Nagios:使用nrpe执行插件会产生与本地运行不同的结果

我试图添加一个NRPE检查来监视Puppet代理,但是我遇到困难让插件在本地执行时返回正确的结果。

我正在使用这个插件:

当在nagios客户端本地执行脚本时,结果是正确的,但是用nrpe执行会导致严重的结果。 我想我已经错过了我的configuration中的东西。 其他nrpe插件正在成功执行。

我重新启动了nrpe.d(并检查了没有nrpe pid运行时)check_puppet文件的权限,拥有者和组与我的其他检查

[root@puppet-master]# /usr/lib64/nagios/plugins/check_nrpe -H server.addr -c check_puppet CRITICAL: Puppet daemon not running or something wrong with process [root@git nrpe.d]# /usr/lib64/nagios/plugins/check_puppet OK: Puppet agent "3.4.3" running catalogversion 1398787991, and executed at Tue 29 Apr 2014 04:13:25 PM UTC for last time 

nagios_commands.cfg:

 define command { command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -t 15 -c check_puppet command_name check_nrpe_puppet } 

nagios_service.cfg:

 define service { ## --PUPPET_NAME-- (called '_naginator_name' in the manifest) check_puppet check_command check_nrpe_puppet host_name server.addr service_description check_puppet use generic-service } 

/etc/nrpe.d/nrpe-check_puppet

 # Configuration for check_puppet (from the generic template) command[check_puppet]=/usr/lib64/nagios/plugins/check_puppet 

这里的参考是我的工作configuration

 define command { command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -t 15 -c check_ram command_name check_nrpe_ram 

}

 define service { ## --PUPPET_NAME-- (called '_naginator_name' in the manifest) check_ram_server.addr check_command check_nrpe_ram host_name server.addr service_description ram use generic-service } 

/etc/nrpe.d/nrpe-check_ram

 # Configuration for check_ram (from the generic template) command[check_ram]=/usr/lib64/nagios/plugins/check_ram -w 10% -c 5% 

更新:

我已经按照自述文件中的说明将Nagios用户添加到了sudoers中,但是并没有将testing作为Nagios用户来运行。 由于sudoers列表中允许的path不正确(我的插件位于Lib64中),因此失败,NRPE作为我的系统上的nrpe用户运行。

我更正sudoers授予nopasswed sudo正确的文件夹nrpe用户,并添加了一个nrpe壳,所以我可以testing为该用户(它被设置为nologin)

 bash-4.1$ whoami nrpe bash-4.1$ /usr/lib64/nagios/plugins/check_puppet UNKNOWN: last_run_summary.yaml not found, not readable or incomplete bash-4.1$ exit exit [root@ip-10-185-165-196 plugins]# ps auxww | grep nrpe nrpe 16353 0.0 0.0 41320 1364 ? Ss 23:33 0:00 /usr/sbin/nrpe -c /etc/nagios/nrpe.cfg -d root 16814 0.0 0.0 103236 856 pts/0 S+ 23:53 0:00 grep nrpe [root@ip-10-185-165-196 plugins]# 

在nagios服务器上:

 [root@puppet-master plugins]# ./check_nrpe -H <myserver> -t 15 -c check_puppet CRITICAL: Puppet daemon not running or something wrong with process 

我正在运行一个最小安装的CentOS 6.5

我禁用了requiretty:

 Defaults:nrpe !requiretty 

更新3:

看起来像SELinux是责怪。 setenforce 0解决了这个问题。 $ setenforce 0

正如yoonix指出的那样,插件本身非常清晰,在第36-38行:它只是一个核心插件的包装,而核心插件需要以root身份运行。 这就是为什么当你以root身份运行时,它工作得很好。 包装将通过sudo升级特权; 它设置为执行sudo本身,但是您将需要提供适当的sudo权限。

假设你的nrpe作为用户nagios运行,插件说你需要sudoers文件中的以下行:

 nagios ALL=NOPASSWD:/usr/bin/puppet,/usr/lib/nagios/plugins/check_puppet_agent,/bin/kill 

(我不确定它为什么需要/bin/kill ,但是它说明了这一点,所以你可能会更好地授予它,或者冒险插入失败的有趣和不完整的方法。

你不要告诉我们你的操作系统(如果是Linux,发行版); 如果是CentOS,而且使用的是RPMforge nrpe ,则会以用户名nagios身份运行。 您将需要找出您的nrpe运行的用户,并将该用户replace为上面的sudoers行中的主要nagios