I have the following plugin whose status is OK on core.
#!/usr/local/bin/bash
if [ "$1" = "-w" ] && [ "$2" -lt "101" ] && [ "$3" = "-c" ] && [ "$4" -lt "101" ] ; then
warn=$2
crit=$4
AVAILMEMPERC=$(free -m | grep mem_avail | awk '{print $7}'| tr -d %])
if [ ${AVAILMEMPERC} -gt $warn ] && [ ${AVAILMEMPERC} -gt $crit ];then
echo "OK - Available Memory = $AVAILMEMPERC% | Available memory=$AVAILMEMPERC%;$warn;$crit;0;100"
exit 0
elif [ ${AVAILMEMPERC} -lt $warn ] && [ ${AVAILMEMPERC} -gt $crit ]; then
echo "WARNING - Available Memory = $AVAILMEMPERC% | Available memory=$AVAILMEMPERC%;$warn;$crit;0;100"
exit 1
else
echo "CRITICAL - Available Memory = $AVAILMEMPERC% | Available memory=$AVAILMEMPERC%;$warn;$crit;0;100"
exit 2
fi
else
echo "$0 - Nagios Plugin for checking the available memory in a Linux system"
echo ""
echo "Usage: $0 -w -c "
echo " = warnlevel and critlevel is warning and critical value for alerts."
echo ""
echo "EXAMPLE: $0 -w 10 -c 5 "
echo " = This will send warning alert when available memory is less than 10%, and send critical when it is less than 5%"
echo ""
exit 3
fi
When I run it locally on the remote machine, it runs fine. I get the right output. But on the web GUI, I see that Nagios cannot extract the variable
AVAILMEMPERC
value
For example, if I simplify the plugin to below
#!/usr/local/bin/bash
warn=$2
crit=$4
AVAIL_MEM_PERCENTAGE="$(free -m)"
echo "OK - ${AVAIL_MEM_PERCENTAGE}"
The only output I see on GUI is
OK -
When I run it on command line, I do get the entire free -m
output
Tried the following and it doesn't write anything. I gave 777 permissions to /tmp and the files.
free -m > /tmp/check_avail_memory.out
Seems like a permissions issue? It runs on Nagios Core though. If I replace free with top
nagios is able to write to the file.
I have downloaded free from here http://people.freebsd.org/~rse/dist/freebsd-memory . As I said it runs fine on the remote machine. I have made sure the paths are correct on FreeBSD and it is executable.
Couldn't find any relevant logs to this except for the plugin output.
Asked by pdns
(275 rep)
Oct 26, 2017, 01:14 AM
Last activity: Oct 26, 2017, 12:04 PM
Last activity: Oct 26, 2017, 12:04 PM