NRPE:自定义脚本返回无法读取输入,但脚本运行正常,可能是什么问题?

NRPE:自定义脚本返回无法读取输入,但脚本运行正常,可能是什么问题?

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

  • 如果路径被挂载
  • 是否可以通过触摸路径中的文件来访问它。
  • 如果挂载点目录为空
[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:无法读取输入”。

我尝试过的其他东西:

  • 在脚本本身内提供路径,因此无需通过 NRPE 传递任何参数但得到相同的结果。
  • 提供内的路径nrpe.cfg,也是为了避免传递参数,但无济于事。

我已经编辑nrpe.cfg并启用了调试,然后在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: 无法读取输入”错误的原因可能是什么?

编辑#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.

提前致谢

答案1

您通过 nrpe 运行的命令是/usr/lib64/nagios/plugins/check_nfsmounts.sh,但您从命令行测试的命令是/usr/lib64/nagios/plugins/check_nfsmount.sh。您已确认此差异是问题的根源 - 并且不要担心,这可能发生在我们任何人身上。第二双眼睛总是有用的,可以捕捉到这些令人讨厌的小精灵!

相关内容