Problems with my own plugins
-
- Posts: 23
- Joined: Wed Jul 30, 2014 6:15 am
Re: Problems with my own plugins
That's probably because the "usage" is printed to stderr instead of stdout.
-
- Posts: 23
- Joined: Wed Jul 30, 2014 6:15 am
Re: Problems with my own plugins
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
# 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
-
- Posts: 8
- Joined: Wed Jul 16, 2014 1:15 pm
Re: Problems with my own plugins
tmcdonald i dont understaing what you write about linking with bc. Because with nagios user and root works well the variables.
- Box293
- Too Basu
- Posts: 5126
- Joined: Sun Feb 07, 2010 10:55 pm
- Location: Deniliquin, Australia
- Contact:
Re: Problems with my own plugins
Ahh I see, thanks for explaining that, I tried it with a full grep command and it worked via NRPE.turboscrew wrote:That's probably because the "usage" is printed to stderr instead of stdout.
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 "---"
Code: Select all
===
528280
---
Code: Select all
===
---
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
-
- Posts: 8
- Joined: Wed Jul 16, 2014 1:15 pm
Re: Problems with my own plugins
yeah my tests is the same like yours.
- Box293
- Too Basu
- Posts: 5126
- Joined: Sun Feb 07, 2010 10:55 pm
- Location: Deniliquin, Australia
- Contact:
Re: Problems with my own plugins
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:
When run via NRPE this outputs:
A quick google revealed we needed to use the -b option with top. So now:
When run via NRPE this outputs:
SO here's a full running version of your command with the following changes:
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 "---"
Code: Select all
===
top: failed tty get
---
Code: Select all
#!/bin/bash
echo "==="
echo `top -b -n1 2>&1`
echo "---"
Code: Select all
===
top - 11:59:15 up 42 min, 4 users, blah blah blah blah
---
- 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
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.
-
- Posts: 8
- Joined: Wed Jul 16, 2014 1:15 pm
Re: Problems with my own plugins
Yeah works really well with me. I work around grep command. But now i read the batch mode in manual page and understanding this.
-
- Posts: 8
- Joined: Wed Jul 16, 2014 1:15 pm