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.
brunocardoso
Posts: 8
Joined: Wed Jul 16, 2014 1:15 pm

Problems with my own plugins

Post by brunocardoso »

I make a plugin who catch the memory used but without parameters and put in the folder /usr/lib64/nagios/plugins
With the permission:
-rwxr-xr-x 1 root root 707 Jul 16 14:43 memorialivre
like:
-rwxr-xr-x 1 root root 41K Out 7 2010 check_load

i execute the both plugins and everything is fine:
[root@proxyjgs plugins]# ./check_load -w 5 -c 10
OK - load average: 0.16, 0.06, 0.01|load1=0.160;5.000;10.000;0; load5=0.060;5.000;10.000;0; load15=0.010;5.000;10.000;0;
[root@proxyjgs plugins]# ./memorialivre
WARNING - Usada: 16096792 KB 98% | Livre: 219856 KB 2% | Total: 16316648 KB

in the nrpe.cfg i have the lines:
command[check_mem]=/usr/lib64/nagios/plugins/memorialivre
command[check_load]=/usr/lib64/nagios/plugins/check_load -w 15,10,5 -c 30,25,20

but when i execute with the check_nrpe my script don't return what i return when execute by hand, look:
[root@proxyjgs plugins]# ./check_nrpe -H localhost -c check_load
OK - load average: 0.14, 0.06, 0.01|load1=0.140;15.000;30.000;0; load5=0.060;10.000;25.000;0; load15=0.010;5.000;20.000;0;
[root@proxyjgs plugins]# ./check_nrpe -H localhost -c check_mem
NRPE: Unable to read output

in the debug occurs the same error. The script need return some other thing or what i'm doing wrong?
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 »

NRPE on your remote host should be running as the user nagios. So when you do your tests on the remote host you should do them as the nagios user:

Code: Select all

su nagios
/usr/lib64/nagios/plugins/memorialivre
Same applied on the Nagios server, the checks are executed by the nagios user, so to test you should do them as the nagios user:

Code: Select all

su nagios
./check_nrpe -H localhost -c check_mem
Did you restart the nrpe service after editing the nrpe.cfg file?

I have a question. Is proxyjgs your Nagios server? If it is then you shouldn't need to be using nrpe to perform checks on the local server. Just create a command that executes the memorialivre and check_load plugins directly.
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 i test with 777 permissions and with nagios user but until have same issue. I can execute with nagios user by hand but not with nrpe:
[root@proxyjgs plugins]# su nagios
bash-4.1$ /usr/lib64/nagios/plugins/memorialivre
WARNING - Usada: 16152320 KB 98% | Livre: 164328 KB 2% | Total: 16316648 KB
bash-4.1$ ./check_nrpe -H localhost -c check_mem
NRPE: Unable to read output
bash-4.1$

And no proxyjgs is not my nagios server all the tests are made locally to separate the things. I restart the service and verified all the nrpe files. Is too strange to me, maybe a bug?
abrist
Red Shirt
Posts: 8334
Joined: Thu Nov 15, 2012 1:20 pm

Re: Problems with my own plugins

Post by abrist »

Could you post the script and the actual check/command definition? I can verify if it runs ok on one of my test systems.
Most of the time though, this error is due to bad paths or $ARGn$/don't_blame_nrpe mismatches.
Former Nagios employee
"It is turtles. All. The. Way. Down. . . .and maybe an elephant or two."
VI VI VI - The editor of the Beast!
Come to the Dark Side.
brunocardoso
Posts: 8
Joined: Wed Jul 16, 2014 1:15 pm

Re: Problems with my own plugins

Post by brunocardoso »

I check with the check_nrpe in the same server that i want test.

Code: Select all

#!/bin/bash

usadakb=`top -n1 | grep Mem | cut -d" " -f5 | cut -d"k" -f1`
totalkb=`cat /proc/meminfo | grep MemTotal | cut -d " " -f8`
a=`echo "$usadakb * 100"|bc`
usada=`echo "$a / $totalkb"|bc`
livre=`echo "100 - $usada"|bc`
livrekb=`echo "$totalkb - $usadakb"|bc`

if [ $usada -lt 90 ]; then
        echo "OK - Usada: $usadakb KB $usada% | Livre: $livrekb KB $livre% | Total: $totalkb KB"
        exit 0
fi
if [ $usada -gt 90 ]; then
        echo "WARNING - Usada: $usadakb KB $usada% | Livre: $livrekb KB $livre% | Total: $totalkb KB"
        exit 1
fi
if [ $usada -gt 95 ]; then
        echo "CRITICAL - Usada: $usadakb KB $usada% | Livre: $livrekb KB $livre% | Total: $totalkb KB"
        exit 2
fi
sreinhardt
-fno-stack-protector
Posts: 4366
Joined: Mon Nov 19, 2012 12:10 pm

Re: Problems with my own plugins

Post by sreinhardt »

It is probably not the full issue, but I would highly suggest changing or removing the pipe separators. These are special characters to nagios and could, again probably not the full issue, cause issues. Also can you run your script like so, and send us the output:

Code: Select all

./memorialivre | xxd
Nagios-Plugins maintainer exclusively, unless you have other C language bugs with open-source nagios projects, then I am happy to help! Please pm or use other communication to alert me to issues as I no longer track the forum.
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 »

I've been having a play and I've narrowed down to why the problem is happening, I just don't know how to resolve it.

Basically any of the commands like top, grep, cut are not producing output when run by nrpe (as the nagios user).

For example:

Code: Select all

su nagios
/bin/grep

Usage: /bin/grep [OPTION]... PATTERN [FILE]...
Try '/bin/grep --help' for more information.
So we've established that the nagios user can run the grep command and it produces a help message.


Now I will add some commands to nrpe.cfg:

Code: Select all

command[test3]=ls -al /bin/grep
command[test4]=/bin/grep
After restarting xinetd service I test these commands:
./check_nrpe -H 10.25.13.1 -c test3
-rwxr-xr-x. 1 root root 111616 Jun 26 2013 /bin/grep
Great, we got some output

Code: Select all

./check_nrpe -H 10.25.13.1 -c test4
NRPE: Unable to read output
:cry: No output is being produced
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 »

I remove the pipe separator but same issues:

Code: Select all

[root@proxyjgs plugins]# ./check_nrpe -H localhost -c check_mem | xxd
0000000: 4e52 5045 3a20 556e 6162 6c65 2074 6f20  NRPE: Unable to
0000010: 7265 6164 206f 7574 7075 740a            read output.
[root@proxyjgs plugins]# ./memorialivre | xxd
0000000: 5741 524e 494e 4720 2055 7361 6461 3a20  WARNING  Usada:
0000010: 3135 3738 3935 3434 204b 4220 3936 2520  15789544 KB 96%
0000020: 204c 6976 7265 3a20 3532 3731 3034 204b   Livre: 527104 K
0000030: 4220 3425 2020 546f 7461 6c3a 2031 3633  B 4%  Total: 163
0000040: 3136 3634 3820 4b42 0a                   16648 KB.
[root@proxyjgs plugins]#
tmcdonald
Posts: 9117
Joined: Mon Sep 23, 2013 8:40 am

Re: Problems with my own plugins

Post by tmcdonald »

Can you add some code to your script that writes out the values of your variables to a file? I think that @Box293 is on to something here, but I also ran into some issues with bc not liking the input and causing issues. If we can see the variables as they are being used we can better troubleshoot what the output might be. Also, please test the command as the nagios user and not as root.
Former Nagios employee
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 »

When I was trying to replicate his issue, if his script was:

Code: Select all

#!/bin/bash
echo "==="
echo `/bin/grep`
echo "---"
exit 0
Then when executed as the local nagios user, the following output is produced:

Code: Select all

===
Usage: /bin/grep [OPTION]... PATTERN [FILE]...
Try '/bin/grep --help' for more information.

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

Code: Select all

===

---
NOTE: If the first and last echo lines were not in the script, when run via NRPE then the output is:

Code: Select all

CHECK_NRPE: No output returned from daemon.
So this is the problem he is having, simple commands in the bash script like grep are not working when run via NRPE.
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
Locked