Nagios command not transmitting all arguments
I'm using the following service to monitor our postgres db from nagios:
define service{
use test-service ; Name of servi$
host_name DEMOCGN002
service_description Postgres State
check_command check_nrpe!check_pgsql!192.168.1.135!test!test!test
notifications_enabled 1
}
On the remote machine I've configured the command:
command[check_pgsql]=/usr/lib/nagios/plugins/check_pgsql -H $ARG1$ -d $ARG2$ -l $ARG3$ -p $ARG4$
In the syslog I can see that command is executed, but there is only one argument transmitted:
Oct 20 13:18:43 DEMOSRV01 nrpe[1033]: Running command: /usr/lib/nagios/plugins/check_pgsql -H 192.168.1.134 -d -l -p
Oct 20 13:18:43 DEMOSRV01 nrpe[1033]: Command completed with return code 3 and output: check_pgsql: Database name is not valid - -l#012Usage:#012check_pgsql [-H <host>] [-P <port>] [-c <critical time>] [-w <warning time>]#012 [-t <timeout>] [-d <database>] [-l <logname>] [-p <password>]
Oct 20 13:18:43 DEMOSRV01 nrpe[1033]: Return Code: 3, Output: check_pgsql: Database name is not valid - -l#012Usage:#012check_pgsql [-H <host>] [-P <port>] [-c <critical time>] [-w <warning time>]#012 [-t <timeout>] [-d <database>] [-l <logname>] [-p <password>]
Why are arguments 2,3 and 4 missing?
Solution 1:
You're mixing up the arguments which are defined on monitoring host with the arguments on the remote host. The $ARGx$
macro cannot be used on the NRPE host.
Be default, the check_nrpe
command is defined as belows:
define command{
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$ -t 120
}
On the remote host you must use the 'real' value, something like this:
command[check_pgsql]=/usr/lib/nagios/plugins/check_pgsql -d test -l test -p test
and this command can be called from the Nagios host with:
define service{
use test-service
host_name DEMOCGN002
service_description Postgres State
check_command check_nrpe!check_pgsql
notifications_enabled 1
}
No need to pass the IP address because it get the value of host_name
.
Solution 2:
I had the same trouble and respectfully disagree a little with the accepted answer, so I thought I would post the solution in case someone else comes across it.
You CAN execute a remote script using nrpe whilst passing it command line arguments from the monitoring host, otherwise you would have to give the remote script hard values on every single remote machine which isn't feasible for large set-ups.
Here is how it works on mine, this works for passing 3 arguments remotely, but you can increase the number in your commands.cfg or equivalent file:
# Check NRPE command
define command {
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$ -a $ARG2$ $ARG3$ $ARG4$
}
Notice that $ARG1$ in the above line is reserved for the command itself, so its actually $ARG2$, $ARG3$ and $ARG4$ that get sent to the remote script, but when they arrive at the remote script they will be listed as $ARG1$ $ARG2$ and $ARG3$ (this is what markus was saying about mixing up arguments) and therefore must be defined as such in the remote machine's nrpe.cfg
The remote machine(s) nrpe.cfg:
command[check_pgsql]=/usr/lib/nagios/plugins/check_pgsql -d $ARG1$ -l $ARG2$ -p $ARG3$
And finally define the service:
define service{
use test-service;
host_name DEMOCGN002;
service_description Postgres State;
check_command check_nrpe!check_pgsql!test!test!test;
notifications_enabled 1;
}