Hello,
I try to use a script check_mem, when I execute it on my server I don’t have any problem:
./check_mem -w 98 -c 99
CRITICAL - Total: 4096 Mb – Used: 4086 Mb – Free: 9 Mb – 99 %
but when I execute it on the nagios server I’ve got an error
/usr/local/nagios/libexec/check_nrpe -n -H .***.***. -c check_mem -a 70 90
NRPE: Unable to read output
this is the script
#!/bin/sh
Script that will check wether the memory trespassed a warning or critical
value
PROGNAME=/bin/basename $0
PROGPATH=echo $0 | /bin/sed -e 's,\\/]^\\/]^\\/]*$,,'
REVISION=echo '$Revision: 0.0 $' | /bin/sed -e 's/^0-9.]//g'
. $PROGPATH/utils.sh
print_usage() {
echo "Usage: ${PROGNAME} -w warning value in percentage used"
echo "Usage: ${PROGNAME} -c critial value in percentage used"
echo "Usage: ${PROGNAME} --help"
echo “Usage: ${PROGNAME} --version”
}
print_help() {
echo ""
print_usage
echo ""
echo “Memory monitoring plugin for Nagios”
}
Make sure the correct number of command line
arguments have been supplied
if $# -lt 4 ]; then
print_usage
exit $STATE_UNKNOWN
fi
take command line arguments.
exitstatus=$STATE_OK #default
while test -n “${1}”; do
case “${1}” in
–help)
print_help
exit ${STATE_OK}
;;
-h)
print_help
exit ${STATE_OK}
;;
–version)
echo "${PROGNAME} ${REVISION}"
exit ${STATE_OK}
;;
-c)
critval=${2}
shift
;;
-w)
warnval=${2}
shift
;;
*)
echo "Unknown argument: ${1}"
print_usage
exit ${STATE_UNKNOWN}
;;
esac
shift
done
if $warnval -gt $critval ]; then
echo "Warning threshold should be smaller than the critical threshold"
exit -1
fi
Create a tempdir for use with this function only (avoid security issues like
symlink vulnerability)
tmp=${TMPDIR-/tmp}
tmp=$tmp/svmon.$RANDOM.$RANDOM.$RANDOM.$$
(umask 077 && mkdir $tmp) || {
echo “Could not create temporary directory! Exiting.” 1>&2
exit ${STATE_CRITICAL}
}
Put the output off svmon in a tmpfile
svmon > ${tmp}/svmon_raw
set the different variables
total=$(cat ${tmp}/svmon_raw | awk ’ $1 ~ /^[memory]./ {print $2}’)
used=$(cat ${tmp}/svmon_raw | awk ’ $1 ~ /^[memory]./ {print $3}’)
free=$(cat ${tmp}/svmon_raw | awk ’ $1 ~ /^[memory].*/ {print $4}’)
#set in MB
total=$((total4/1024))
used=$((used4/1024))
free=$((free*4/1024))
check=$(((used * 100)/total))
if $check -ge $critval ]
then exitstatus=$STATE_CRITICAL
else if $check -ge $warnval ]
then exitstatus=$STATE_WARNING
fi
fi
Creating message for Nagios
msg=“Total: $total Mb – Used: $used Mb – Free: $free Mb – $check %”
case “$exitstatus” in
"$STATE_WARNING")
msg=“WARNING - $msg”
;;
"$STATE_CRITICAL")
msg=“CRITICAL - $msg”
;;
"$STATE_OK")
msg=“OK - $msg”
;;
*)
msg="$msg"
;;
esac
remove the tempdir
rm -fr ${tmp}
echo $msg
exit $exitstatus
Thank you to your help