Problems with my own plugins

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
turboscrew
Posts: 23
Joined: Wed Jul 30, 2014 6:15 am

Re: Problems with my own plugins

Post by turboscrew »

That's probably because the "usage" is printed to stderr instead of stdout.
turboscrew
Posts: 23
Joined: Wed Jul 30, 2014 6:15 am

Re: Problems with my own plugins

Post by turboscrew »

I wonder if this relates to the OP's problem?

# su -c "/etc/nagios/check_omat 20% 10% 1>/dev/null" nrpe
# su -c "/etc/nagios/check_omat 20% 10% 2>/dev/null" nrpe
SERVICE STATUS: OK
# su -c "/usr/lib64/nagios/plugins/check_nrpe -H localhost -c check_omat 20% 10% " nrpe
NRPE: Unable to read output
# su -c "/usr/lib64/nagios/plugins/check_nrpe -H localhost -c check_omat\!20%\!10% " nagios
NRPE: Unable to read output
brunocardoso
Posts: 8
Joined: Wed Jul 16, 2014 1:15 pm

Re: Problems with my own plugins

Post by brunocardoso »

tmcdonald i dont understaing what you write about linking with bc. Because with nagios user and root works well the variables.
User avatar
Box293
Too Basu
Posts: 5126
Joined: Sun Feb 07, 2010 10:55 pm
Location: Deniliquin, Australia
Contact:

Re: Problems with my own plugins

Post by Box293 »

turboscrew wrote:That's probably because the "usage" is printed to stderr instead of stdout.
Ahh I see, thanks for explaining that, I tried it with a full grep command and it worked via NRPE.

But this is where I get stumped.

Here is the first command in his script (I needed to change f5 to f8):

Code: Select all

#!/bin/bash
usadakb=`top -n1 | grep Mem | cut -d" " -f8 | cut -d"k" -f1`
echo "==="
echo $usadakb
echo "---"
Then when executed as the local nagios user, the following output is produced:

Code: Select all

===
528280
---
When executed via NRPE, the following output is produced:

Code: Select all

===

---
This is where I get confused
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
brunocardoso
Posts: 8
Joined: Wed Jul 16, 2014 1:15 pm

Re: Problems with my own plugins

Post by brunocardoso »

yeah my tests is the same like yours.
User avatar
Box293
Too Basu
Posts: 5126
Joined: Sun Feb 07, 2010 10:55 pm
Location: Deniliquin, Australia
Contact:

Re: Problems with my own plugins

Post by Box293 »

OK I've worked it out. Basically top was outputting an error and we needed to switch to batch mode using -b in our top command.

Big thanks to turboscrew who put me onto the path of the output being directed to stderr !!!

Here's how I worked it out:

Code: Select all

#!/bin/bash
echo "==="
echo `top -n1 2>&1`
echo "---"
When run via NRPE this outputs:

Code: Select all

===
top: failed tty get
---
A quick google revealed we needed to use the -b option with top. So now:

Code: Select all

#!/bin/bash
echo "==="
echo `top -b -n1 2>&1`
echo "---"
When run via NRPE this outputs:

Code: Select all

===
top - 11:59:15 up 42 min, 4 users, blah blah blah blah
---
SO here's a full running version of your command with the following changes:
  • On the usadakb line I added -b to the top command
    On the usadakb line I needed to change -f5 to -f8 (most likely your OS language outputs slightly differently)
    On the totalkb line I needed to change -f8 to -f9 (most likely your OS language outputs slightly differently)
    I also changed your output message but removing the pipe symbols and putting each one in curtly brackets, also seeing as it was the same message for each state type I turned it into a variable
Enjoy

Code: Select all

#!/bin/bash
usadakb=`top -b -n1 | grep Mem | cut -d" " -f8 | cut -d"k" -f1`
totalkb=`cat /proc/meminfo | grep MemTotal | cut -d " " -f9`
a=`echo "$usadakb * 100"|bc`
usada=`echo "$a / $totalkb"|bc`
livre=`echo "100 - $usada"|bc`
livrekb=`echo "$totalkb - $usadakb"|bc`
message="{Usada: $usadakb KB $usada%} {Livre: $livrekb KB $livre%} {Total: $totalkb KB}"

if [ $usada -lt 90 ]; then
        echo "OK - $message"
        exit 0
fi
if [ $usada -gt 90 ]; then
       	echo "WARNING - $message"
        exit 1
fi
if [ $usada -gt 95 ]; then
        echo "CRITICAL - $message"
        exit 2
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
brunocardoso
Posts: 8
Joined: Wed Jul 16, 2014 1:15 pm

Re: Problems with my own plugins

Post by brunocardoso »

Yeah works really well with me. I work around grep command. But now i read the batch mode in manual page and understanding this.
brunocardoso
Posts: 8
Joined: Wed Jul 16, 2014 1:15 pm

Re: Problems with my own plugins

Post by brunocardoso »

wow. i forget to thank you :)
Attachments
nagios.png
tmcdonald
Posts: 9117
Joined: Mon Sep 23, 2013 8:40 am

Re: Problems with my own plugins

Post by tmcdonald »

So is it safe to close this thread now?
Former Nagios employee
Locked