NRPE:自定义脚本返回无法读取input,但脚本正常工作,它可能是什么?

我写了一个Nagios检查脚本,它接收一个path作为参数并检查:

  • 如果path被安装
  • 如果可以通过触摸path中的文件进行访问。
  • 如果挂载点目录是空的
[root@hadoop-nn1 mass1]# su - nagios [nagios@hadoop-nn1 ~]$ /usr/lib64/nagios/plugins/check_nfsmount.sh /mass2/hpfiles/ Warning: /mass2/hpfiles/ is mounted but directory is empty! [nagios@hadoop-nn1 ~]$ /usr/lib64/nagios/plugins/check_nfsmount.sh /mass1/hpfiles/ Warning: /mass1/hpfiles/ is MOUNTED properly but not writeable for user nagios [nagios@hadoop-nn1 ~]$ /usr/lib64/nagios/plugins/check_nfsmount.sh /mass1/hp_offline/ Ok: /mass1/hp_offline/ is MOUNTED properly and writeable for user nagios [nagios@hadoop-nn1 ~]$ 

/etc/nagios/nrpe.cfg的命令如下所示:

 command[check_nfsmounts]=/usr/lib64/nagios/plugins/check_nfsmounts.sh $ARG1$ 

如您所见,当使用Nagios用户从受监视的计算机运行命令时,结果如预期的那样,但是当我使用来自Nagios服务器的nrpe运行命令时,它将返回“NRPE:无法读取input”。

其他我尝试的东西:

  • 在脚本中提供path,所以不需要通过NRPE传递参数,但得到相同的结果。
  • nrpe.cfg提供path,也是为了避免传递参数,但无济于事。

我编辑了nrpe.cfg并启用了debugging,然后在运行tail -f /var/log/messages |grep nrpe并从Nagios服务器发送远程命令时,我在日志中看到这两行:

 Dec 15 04:09:44 hadoop-nn1 nrpe[9354]: Error: Request contained illegal metachars! Dec 15 04:09:44 hadoop-nn1 nrpe[9354]: Client request was invalid, bailing out... 

但我无法知道他们是哪个非法字符

Don't_blame_nrpe设置为1.脚本如下所示:

 #!/bin/bash # This script checks if the provided mount point is mounted and writeable. # Script by Itai Ganot if [ -z "$1" ]; then echo "Usage: $(basename $0) PATH_TO_CHECK" echo "Available PATH's: /mass1/hp_offline -- /mass1/hpfiles -- /mass2/hpfiles" exit 3 fi DF="/bin/df -t nfs" GREP="/bin/grep -q" AWK="/bin/awk" TOUCH="/bin/touch" LS="/bin/ls" WC="/usr/bin/wc" TESTFILE="test.dat" USER=$(whoami) NFS_MOUNT="$1" $DF | $GREP "$NFS_MOUNT" | $AWK '{print $5}' if [ $? = 0 ]; then MOUNTED="yes" else MOUNTED="no" fi if [[ "$MOUNTED" = "yes" ]] && [[ $($LS -A "$NFS_MOUNT" | "$WC" -l) -gt "1" ]]; then "$TOUCH" "$NFS_MOUNT""$TESTFILE" 2>/dev/null if [ $? = 0 ]; then TOUCHED="yes" else TOUCHED="no" fi elif [[ "$MOUNTED" = "yes" ]] && [[ $($LS -A "$NFS_MOUNT" | "$WC" -l) -eq "0" ]]; then TXT="$NFS_MOUNT is mounted but directory is empty!" RETVAL="1" STATUS="Warning" elif [ "$MOUNTED" = "no" ]; then TXT="$NFS_MOUNT not MOUNTED" RETVAL="2" STATUS="Critical" fi if [[ "$TOUCHED" = "yes" ]]; then TXT="$NFS_MOUNT is MOUNTED properly and writeable for user $USER" RETVAL="0" STATUS="Ok" elif [[ "$TOUCHED" = "no" ]] || [[ "$MOUNTED" = "no" ]]; then TXT="$NFS_MOUNT is MOUNTED properly but not writeable for user $USER" RETVAL="1" STATUS="Warning" fi echo "$STATUS: $TXT" exit $RETVAL 

什么可能是错误的原因“NRPE:无法读取input”?

编辑#1:

 [root@mon1 ~]# /usr/lib64/nagios/plugins/check_nrpe -H 10.39.21.211 -c check_nfsmounts -a /mass1/hp_offline NRPE: Unable to read output [root@mon1 ~]# /usr/lib64/nagios/plugins/check_nrpe -H 10.39.21.211 -c check_nfsmounts -a '/mass1/hp_offline' NRPE: Unable to read output [root@mon1 ~]# /usr/lib64/nagios/plugins/check_nrpe -H 10.39.21.211 -c check_nfsmounts /mass1/hp_offline NRPE: Unable to read output [root@mon1 ~]# 

编辑#2:在Nagios服务器和所有客户端都禁用了SSL …

 [root@mon1 ~]# /usr/lib64/nagios/plugins/check_nrpe -H 10.39.21.211 -n -c check_nfsmounts '/mass1/hp_offline' CHECK_NRPE: Error receiving data from daemon. [root@mon1 ~]# /usr/lib64/nagios/plugins/check_nrpe -H 10.39.21.211 -n -c check_nfsmounts -a '/mass1/hp_offline' CHECK_NRPE: Error receiving data from daemon. 

提前致谢

您通过nrpe运行的命令是/usr/lib64/nagios/plugins/check_nfsmounts.sh ,但是您从命令行testing的命令是/usr/lib64/nagios/plugins/check_nfsmount.sh 。 您已经确认这种差异是问题的根源 – 不要冒汗,这可能发生在我们任何一个人身上。 第二双眼睛总是有用的捕捉这些深深讨厌的小gremlins!