Page 1 of 1

Plugin runs on core and locally but fails over NRPE

Posted: Wed Oct 25, 2017 6:35 pm
by AnudeepReddy
Hello,

I wrote the following plugin which alerts on Available Memory on FreeBSD. It runs locally on remote machine and its nagios status is ok on the core. But it fails over NRPE. I don't see any errors in the NRPE log file.

Code: Select all

#!/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' | sed 's/.*\[ \(.*\)\]/\1/' | awk '{print $1}' | 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 <warnlevel> -c <critlevel>"
  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
Output when I run locally:
OK - Available Memory = 88% | Available memory=88%;20;10;0;100

On web gui:
CRITICAL - Available Memory = %

From the GUI output, it looks like the variable value hasn't been grabbed but I am not sure what the issue is. All the other plugins are running fine.

Re: Plugin runs on core and locally but fails over NRPE

Posted: Thu Oct 26, 2017 9:53 am
by kyang
Hey @AnudeepReddy,

What OS and version is your Core on?

What version of NRPE? Source install?

Code: Select all

./check_nrpe -V
Is it working locally?

Code: Select all

/usr/local/nagios/libexec/check_nrpe -H 127.0.0.1
Can you show us the command you are using with NRPE to check your FreeBSD server. Is it hardcoded inside your nrpe.cfg? Or you could post your nrpe.cfg.

Re: Plugin runs on core and locally but fails over NRPE

Posted: Thu Oct 26, 2017 3:05 pm
by AnudeepReddy
Hello @kyang,

Yes. Check_nrpe is working fine.

I kinda figured out the issue. Using the absolute path for the command `free -m` resolved the problem. i.e `/usr/local/bin/free -m`
Not sure why I need the full path though. It runs fine on the core without absolute path.

Re: Plugin runs on core and locally but fails over NRPE

Posted: Thu Oct 26, 2017 4:23 pm
by kyang
Good to hear, did you have more questions or are we okay to close this thread?

Re: Plugin runs on core and locally but fails over NRPE

Posted: Thu Oct 26, 2017 4:53 pm
by AnudeepReddy
Yes, you can close the thread. Thanks!

Re: Plugin runs on core and locally but fails over NRPE

Posted: Thu Oct 26, 2017 4:55 pm
by kyang
Sounds great! I'll be closing this topic!

If you have any more questions, feel free to create another thread!

Thank you for using the Nagios Support Forum!