Nagios - NRPE: Command '...' not defined

Hi Hi picture Hi Hi · Oct 14, 2015 · Viewed 8.5k times · Source

In /usr/local/nagios/etc/nrpe.cfg I added a new command check_this_process to the already pre-defined ones:

command[check_users]=/usr/local/nagios/libexec/check_users -w 5 -c 10
command[check_load]=/usr/local/nagios/libexec/check_load -w 15,10,5 -c 30,25,20
command[check_hda1]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/$
command[check_zombie_procs]=/usr/local/nagios/libexec/check_procs -w 5 -c 10 -s$
command[check_total_procs]=/usr/local/nagios/libexec/check_procs -w 150 -c 200
command[check_this_process]=/usr/local/nagios/libexec/check_procs -w 15 -c 20 -C name

This works:

define service{
        use                     generic-service
        host_name               my_host
        service_description     CPU Load
        check_command           check_nrpe!check_load
}

This doesn't:

define service{
        use                             local-service
        host_name                       my_host
        service_description             cron
        check_command                   check_nrpe!check_this_process
}

and returns: NRPE: Command 'check_this_process' not defined

Answer

Joe Young picture Joe Young · Oct 14, 2015

The terminology used in the supplied docs is a little confusing, but I'll put it like this:

As written in Page 10 of https://assets.nagios.com/downloads/nagioscore/docs/nrpe/NRPE.pdf, you need to modify /usr/local/nagios/etc/commands.cfg on your Nagios server and add the following to define the check_nrpe command:

define command{
    command_name check_nrpe
    command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}

On your Nagios server, define your service definition as you've already done:

define service{
        use                             local-service
        host_name                       my_host
        service_description             cron
        check_command                   check_nrpe!check_this_process
}

On your remote host to be monitored, the following is going to be different depending on whether you installed NRPE:

If you used the tarball / xinetd method, your NRPE configuration file will likely be located at /usr/local/nagios/etc/nrpe.cfg on your remote-host-to-be-monitored. (To avoid typing that all the time, I'll just call it "my_host"). So, on my_host, modify /usr/local/nagios/etc/nrpe.cfg.

Add

command[check_this_process]=/usr/local/nagios/libexec/check_procs -w 15 -c 20 -C name

So that it looks like:

command[check_users]=/usr/local/nagios/libexec/check_users -w 5 -c 10
command[check_load]=/usr/local/nagios/libexec/check_load -w 15,10,5 -c 30,25,20
command[check_hda1]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/$
command[check_zombie_procs]=/usr/local/nagios/libexec/check_procs -w 5 -c 10 -s$
command[check_total_procs]=/usr/local/nagios/libexec/check_procs -w 150 -c 200
command[check_this_process]=/usr/local/nagios/libexec/check_procs -w 15 -c 20 -C name

(Note: the above is assuming you have a process called name. If not, replace name with your real process name: i.e. crond)

Restart xinetd:

service xinetd restart

(NOTE: restarting xinted might not be necessary, but I don't use it so I'm a little fuzzy on this one.)

However, if you installed NRPE on my_host using a package manager like yum, your NRPE configuration file will likely be located at /etc/nagios/nrpe.cfg. So, on my_host, modify /etc/nagios/nrpe.cfg.

Add

command[check_this_process]=/usr/local/nagios/libexec/check_procs -w 15 -c 20 -C name

So that it looks like:

command[check_users]=/usr/local/nagios/libexec/check_users -w 5 -c 10
command[check_load]=/usr/local/nagios/libexec/check_load -w 15,10,5 -c 30,25,20
command[check_hda1]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/$
command[check_zombie_procs]=/usr/local/nagios/libexec/check_procs -w 5 -c 10 -s$
command[check_total_procs]=/usr/local/nagios/libexec/check_procs -w 150 -c 200
command[check_this_process]=/usr/local/nagios/libexec/check_procs -w 15 -c 20 -C name

Restart the nrpe service:

service nrpe restart

Back on your Nagios server, run a verification of your Nagios configuration settings:

nagios -v /usr/local/nagios/etc/nagios.cfg

Check the output for errors. If there are no errors, restart Nagios:

service nagios restart

On your Nagios server you should have a check_nrpe utility installed somehwere as a result of installing the "check_nrpe plugin" on your Nagios server. See pages 9 and 10 of: https://assets.nagios.com/downloads/nagioscore/docs/nrpe/NRPE.pdf

This check_nrpe utility will most likely be located at: /usr/local/nagios/libexec/check_nrpe Using the host information for my_host manually test your NRPE connection from the Nagios server. Execute the following:

/usr/local/nagios/libexec/check_nrpe -H <IP Address of my_host> -c check_this_process

If everything is setup correctly, you should get some output on the command line.