Page 1 of 2

Problems with my own plugins

Posted: Wed Jul 16, 2014 1:28 pm
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?

Re: Problems with my own plugins

Posted: Wed Jul 16, 2014 8:31 pm
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.

Re: Problems with my own plugins

Posted: Fri Jul 18, 2014 12:06 pm
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?

Re: Problems with my own plugins

Posted: Fri Jul 18, 2014 12:20 pm
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.

Re: Problems with my own plugins

Posted: Thu Jul 24, 2014 12:07 pm
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

Re: Problems with my own plugins

Posted: Thu Jul 24, 2014 4:36 pm
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

Re: Problems with my own plugins

Posted: Thu Jul 24, 2014 10:06 pm
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

Re: Problems with my own plugins

Posted: Mon Jul 28, 2014 11:28 am
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]#

Re: Problems with my own plugins

Posted: Mon Jul 28, 2014 4:50 pm
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.

Re: Problems with my own plugins

Posted: Wed Jul 30, 2014 11:48 pm
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.