我正在使用以下服务来监视我们从Nagios的postgres数据库:
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 }
在远程机器上,我configuration了这个命令:
command[check_pgsql]=/usr/lib/nagios/plugins/check_pgsql -H $ARG1$ -d $ARG2$ -l $ARG3$ -p $ARG4$
在syslog中,我可以看到该命令被执行,但只有一个参数被传送:
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>]
为什么争论2,3和4失踪?
您将监视主机上定义的参数与远程主机上的参数混合在一起。 $ARGx$macros不能在NRPE主机上使用。
默认情况下, check_nrpe命令定义如下:
define command{ command_name check_nrpe command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$ -t 120 }
在远程主机上,您必须使用“真实”值,如下所示:
command[check_pgsql]=/usr/lib/nagios/plugins/check_pgsql -d test -l test -p test
并且可以使用以下命令从Nagios主机调用此命令:
define service{ use test-service host_name DEMOCGN002 service_description Postgres State check_command check_nrpe!check_pgsql notifications_enabled 1 }
不需要传递IP地址,因为它获得了host_name的值。
我有同样的麻烦,并且对于接受的答案有点不同意,所以我想我会发布解决scheme,以防其他人遇到它。
您可以使用nrpe执行远程脚本,同时从监视主机传递命令行参数,否则必须在每个远程计算机上为远程脚本提供硬值,而这对于大型设置是不可行的。
下面是我的工作原理,它可以远程传递3个参数,但是你可以增加你的commands.cfg或者等价的文件的数量:
# Check NRPE command define command { command_name check_nrpe command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$ -a $ARG2$ $ARG3$ $ARG4$ }
注意上面这行中的$ ARG1 $是为命令本身保留的,所以它的实际$ ARG2 $,$ ARG3 $和$ ARG4 $被发送到远程脚本,但是当它们到达远程脚本时,它们将被列出作为$ ARG1 $ $ ARG2 $和$ ARG3 $(这是markus关于混合参数的说法),因此必须在远程机器的nrpe.cfg中定义
远程机器nrpe.cfg:
command[check_pgsql]=/usr/lib/nagios/plugins/check_pgsql -d $ARG1$ -l $ARG2$ -p $ARG3$
最后定义服务:
define service{ use test-service; host_name DEMOCGN002; service_description Postgres State; check_command check_nrpe!check_pgsql!test!test!test; notifications_enabled 1; }