我有一个Nagios服务器和一个受监控的服务器。 在受监视的服务器上:
[root@Monitored ~]# netstat -an |grep :5666 tcp 0 0 0.0.0.0:5666 0.0.0.0:* LISTEN [root@Monitored ~]# locate check_kvm /usr/lib64/nagios/plugins/check_kvm [root@Monitored ~]# /usr/lib64/nagios/plugins/check_kvm -H localhost hosts:3 OK:3 WARN:0 CRIT:0 - ab2c7:running alpweb5:running istaweb5:running [root@Monitored ~]# /usr/lib64/nagios/plugins/check_nrpe -H localhost -c check_kvm NRPE: Unable to read output [root@Monitored ~]# /usr/lib64/nagios/plugins/check_nrpe -H localhost NRPE v2.14 [root@Monitored ~]# ps -ef |grep nrpe nagios 21178 1 0 16:11 ? 00:00:00 /usr/sbin/nrpe -c /etc/nagios/nrpe.cfg -d [root@Monitored ~]#
在Nagios服务器上:
[root@Nagios ~]# /usr/lib64/nagios/plugins/check_nrpe -H 1.1.1.159 -c check_kvm NRPE: Unable to read output [root@Nagios ~]# /usr/lib64/nagios/plugins/check_nrpe -H 1.1.1.159 NRPE v2.14 [root@Nagios ~]#
当我使用相同的命令检查networking中的另一台服务器时:
[root@Nagios ~]# /usr/lib64/nagios/plugins/check_nrpe -H 1.1.1.80 -c check_kvm hosts:4 OK:4 WARN:0 CRIT:0 - karmisoft:running ab2c4:running kidumim1:running travel2gether1:running [root@Nagios ~]#
使用Nagios帐户在本地运行支票:
[root@Monitored ~]# su - nagios -bash-4.1$ /usr/lib64/nagios/plugins/check_kvm hosts:3 OK:3 WARN:0 CRIT:0 - ab2c7:running alpweb5:running istaweb5:running -bash-4.1$
使用Nagios帐户从Nagios服务器远程运行检查:
-bash-4.1$ /usr/lib64/nagios/plugins/check_nrpe -H 1.1.1.159 -c check_kvm NRPE: Unable to read output -bash-4.1$ /usr/lib64/nagios/plugins/check_nrpe -H 1.1.1.159 NRPE v2.14 -bash-4.1$
使用Nagios帐户对networking中的不同服务器运行相同的check_kvm:
-bash-4.1$ /usr/lib64/nagios/plugins/check_nrpe -H 1.1.1.80 -c check_kvm hosts:4 OK:4 WARN:0 CRIT:0 - karmisoft:running ab2c4:running kidumim1:running travel2gether1:running -bash-4.1$
权限:
-rwxr-xr-x. 1 root root 4684 2013-10-14 17:14 nrpe.cfg (aka /etc/nagios/nrpe.cfg) drwxrwxr-x. 3 nagios nagios 4096 2013-10-15 03:38 plugins (aka /usr/lib64/nagios/plugins)
/etc/sudoers:
[root@Monitored ~]# grep -i requiretty /etc/sudoers #Defaults requiretty
iptables的/ SELinux的:
[root@Monitored xinetd.d]# service iptables status iptables: Firewall is not running. [root@Monitored xinetd.d]# service ip6tables status ip6tables: Firewall is not running. [root@Monitored xinetd.d]# grep disable /etc/selinux/config # disabled - No SELinux policy is loaded. SELINUX=disabled [root@Monitored xinetd.d]#
/etc/nagios/nrpe.cfg的命令是:
[root@Monitored ~]# grep kvm /etc/nagios/nrpe.cfg command[check_kvm]=sudo /usr/lib64/nagios/plugins/check_kvm
并在/etc/sudoers上添加了nagios用户:
nagios ALL=(ALL) NOPASSWD:/usr/lib64/nagios/plugins/check_kvm nagios ALL=(ALL) NOPASSWD:/usr/lib64/nagios/plugins/check_nrpe
check_kvm是一个shell脚本,看起来像这样:
#!/bin/sh LIST=$(virsh list --all | sed '1,2d' | sed '/^$/d'| awk '{print $2":"$3}') if [ ! "$LIST" ]; then EXITVAL=3 #Status 3 = UNKNOWN (orange) echo "Unknown guests" exit $EXITVAL fi OK=0 WARN=0 CRIT=0 NUM=0 for host in $(echo $LIST) do name=$(echo $host | awk -F: '{print $1}') state=$(echo $host | awk -F: '{print $2}') NUM=$(expr $NUM + 1) case "$state" in running|blocked) OK=$(expr $OK + 1) ;; paused) WARN=$(expr $WARN + 1) ;; shutdown|shut*|crashed) CRIT=$(expr $CRIT + 1) ;; *) CRIT=$(expr $CRIT + 1) ;; esac done if [ "$NUM" -eq "$OK" ]; then EXITVAL=0 #Status 0 = OK (green) fi if [ "$WARN" -gt 0 ]; then EXITVAL=1 #Status 1 = WARNING (yellow) fi if [ "$CRIT" -gt 0 ]; then EXITVAL=2 #Status 2 = CRITICAL (red) fi echo hosts:$NUM OK:$OK WARN:$WARN CRIT:$CRIT - $LIST exit $EXITVAL
编辑(10/22/13):以下所有,我现在能够从脚本得到一些回应:
[root@Monitored ~]# /usr/lib64/nagios/plugins/check_nrpe -H localhost -c check_kvm Unknown guests [root@Monitored ~]# /usr/lib64/nagios/plugins/check_nrpe -H localhost NRPE v2.14 [root@Monitored ~]# /usr/lib64/nagios/plugins/check_kvm hosts:3 OK:3 WARN:0 CRIT:0 - ab2c7:running alpweb5:running istaweb5:running [root@Monitored ~]# su - nagios -bash-4.1$ /usr/lib64/nagios/plugins/check_kvm hosts:3 OK:3 WARN:0 CRIT:0 - ab2c7:running alpweb5:running istaweb5:running -bash-4.1$ /usr/lib64/nagios/plugins/check_nrpe -H localhost -c check_kvm Unknown guests -bash-4.1$ /usr/lib64/nagios/plugins/check_nrpe -H localhost NRPE v2.14
似乎问题是一些如何与check_nrpe命令有关或与服务器上的nrpe安装有关。
编辑12/2/13:有问题的服务器工作的其他检查: 
尼斯详细的报道伊泰! 你有没有尝试减lessconfiguration的复杂性,看看它是否工作?
对于初学者,我会开始改变nrpe.cfg的行
command[check_kvm]=/usr/lib64/nagios/plugins/check_kvm
并暂时将/ usr / lib64 / nagios / plugins / check_kvm脚本更改为如下所示的简单内容:
#!/bin/sh echo Hi exit 0
如果这样做,那么你可以开始棘手的复杂性。 也许不是让nagios用户sudo访问脚本,而是真的需要访问virsh命令,并且可以在nrpe.cfg命令行中nrpe.cfg sudo部分。
我在http://forums.gentoo.org/viewtopic-t-806014-start-0.html上看到了一个类似于你的Gentoo服务器的问题
有一个很好的方法来debugging这个问题。
该post上的用户与check_disk有问题,并得到完全相同的错误信息为您的。
他被告知执行以下命令:
ssh remote_ip /usr/lib/nagios/plugins/check_disk -w 10 -c 5 -p "/" 2>&1
2>&1将输出stderr并可能显示确切的错误。
所以在你的情况下,用服务器的IP地址replaceremote_ip不能执行check_nrpe。 并用check_kvm应该执行的完整命令replacecheck_disk命令。 如果你运行它没有任何参数,所以你可以去执行
ssh <remote_ip> /usr/lib64/nagios/plugins/check_kvm 2>&1
希望能透露有关问题的信息。
祝你好运!
我有同样的问题,我设法通过杀死nagios进程(在受监控的机器上)来解决它:
ps -ef | grep nagios kill -9 [NagiosProcessNumber] /etc/init.d/nagios-nrpe-server start
之后一切顺利。
尝试查看是否在远程服务器上运行了selinux(nrpe代理正在运行)。 [root@dl1-ap-ldap1 plugins]# getenforce Enforcing如果是,则将其closures,或者configuration[root@dl1-ap-ldap1 plugins]# setenforce 0
尝试在/ etc / sudoers文件中评论以下行:
Defaults requiretty
修改后,应该是这样的:
#Defaults requiretty