I wrote a Nagios check script which receives a path as argument and checks:
- if the path is mounted
- if it is accessible by touching a file in the path.
- If the mount point directory is empty
[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 ~]$
The command in /etc/nagios/nrpe.cfg
looks like this:
command[check_nfsmounts]=/usr/lib64/nagios/plugins/check_nfsmounts.sh $ARG1$
As you see, when running the command from the monitored machine using Nagios user, the result is as expected, but when I run the command using nrpe
from the Nagios server, it returns "NRPE: Unable to read input".
Other stuff I tried:
- Providing the path within the script itself so no argument needs to be passed through NRPE but got the same result.
- Providing the path within the
nrpe.cfg
, also to avoid passing arguments but to no avail.
I've edited nrpe.cfg
and enabled debugging, then while running tail -f /var/log/messages |grep nrpe
and sending the remote command from the Nagios server, I see these two lines in the log:
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...
But I have no way to know which illegal chars they were…
Don't_blame_nrpe is set to 1.
The script looks like that:
#!/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
What could be the reason for the error "NRPE: Unable to read input"?
Edit #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 ~]#
Edit #2:
SSL is disabled in both the Nagios server and all the clients…
[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.
Thanks in advance
Best Answer
The command you're running through nrpe is
/usr/lib64/nagios/plugins/check_nfsmounts.sh
, but the one you're testing from the command line is/usr/lib64/nagios/plugins/check_nfsmount.sh
. You've confirmed that this discrepancy is the source of the problem - and don't sweat it, this could happen to any of us. A second pair of eyes is always useful in catching these deeply annoying little gremlins!