mar*_*kus 6 postgresql debian nagios
我正在使用以下服务从 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
}
Run Code Online (Sandbox Code Playgroud)
在远程机器上,我配置了命令:
command[check_pgsql]=/usr/lib/nagios/plugins/check_pgsql -H $ARG1$ -d $ARG2$ -l $ARG3$ -p $ARG4$
Run Code Online (Sandbox Code Playgroud)
在 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>]
Run Code Online (Sandbox Code Playgroud)
为什么缺少参数 2,3 和 4?
您将监视主机上定义的参数与远程主机上的参数混在一起。该$ARGx$宏不能在 NRPE 主机上使用。
默认情况下,check_nrpe命令定义如下:
define command{
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$ -t 120
}
Run Code Online (Sandbox Code Playgroud)
在远程主机上,您必须使用“真实”值,如下所示:
command[check_pgsql]=/usr/lib/nagios/plugins/check_pgsql -d test -l test -p test
Run Code Online (Sandbox Code Playgroud)
并且可以从 Nagios 主机调用此命令:
define service{
use test-service
host_name DEMOCGN002
service_description Postgres State
check_command check_nrpe!check_pgsql
notifications_enabled 1
}
Run Code Online (Sandbox Code Playgroud)
无需传递 IP 地址,因为它获得了host_name.
我遇到了同样的麻烦,并且恭敬地不同意接受的答案,所以我想我会发布解决方案,以防其他人遇到它。
您可以使用 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$
}
Run Code Online (Sandbox Code Playgroud)
请注意,上面一行中的 $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$
Run Code Online (Sandbox Code Playgroud)
最后定义服务:
define service{
use test-service;
host_name DEMOCGN002;
service_description Postgres State;
check_command check_nrpe!check_pgsql!test!test!test;
notifications_enabled 1;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10615 次 |
| 最近记录: |