Page 1 of 1

Plugin ok from CLI, not ok when executed by nagios

Posted: Mon Apr 14, 2014 11:10 am
by cosmin.neagu
Hi,
I have the following problem. If I run a plugin from cli as nagios, it is working as expected:
nagios@monitor:/usr/local/nagios/libexec$ ./check_generic -e "/bin/sh /usr/local/nagios/libexec/checkipsload.sh" -w ">5" -c ">70" -n "IPS Inspection Load"
IPS Inspection Load WARNING - result:11 match:>5 severities:warning

But if i tell nagios to run the same plugin as a service, will return something like this:
IPS Inspection Load OK - result: match:none

I use check_generic with other personal writen scripts and is working as expected.

Can someone help me troubleshoot this problem, because i do not understand why running this plugin behaves different when invoked from cli and when invoked from nagios.
Thank you

The relevand config below:
define command{
command_name check_generic
command_line $USER1$/check_generic $ARG1$
}
define service {
use TemplateService
host_name ips1
service_description InspectionLOAD
check_command check_generic! -e "/bin/sh /usr/local/nagios/libexec/checkipsload.sh" -w ">5" -c ">70" -n "IPS Inspection Load"
}

Re: Plugin ok from CLI, not ok when executed by nagios

Posted: Mon Apr 14, 2014 4:16 pm
by scottwilkerson
I would run the test again OUTSIDE the libexec directory

e.g.

Code: Select all

cd /tmp
/usr/local/nagios/libexec/check_generic -e "/bin/sh /usr/local/nagios/libexec/checkipsload.sh" -w ">5" -c ">70" -n "IPS Inspection Load"
If this works, we would need to take a look at the check_generic plugin code to test it...

Re: Plugin ok from CLI, not ok when executed by nagios

Posted: Tue Apr 15, 2014 1:48 am
by cosmin.neagu
Strange, you are right, if i run it outside the libexec it shows me the same output as the one showed by nagios.
So what could be the difference between running the plugin fon libexec folder and outside the folder?

nagios@monitor:/tmp$ ls -ld /usr/local/nagios/libexec/
drwxrwxr-x 3 nagios nagios 4096 Apr 14 16:15 /usr/local/nagios/libexec/
nagios@monitor:/tmp$ /usr/local/nagios/libexec/check_generic -e "/bin/sh /usr/local/nagios/libexec/checkipsload.sh" -w ">5" -c ">70" -n "IPS Inspection Load"
Argument "" isn't numeric in numeric gt (>) at (eval 3) line 1.
Argument "" isn't numeric in numeric gt (>) at (eval 4) line 1.
IPS Inspection Load OK - result: match:none


nagios@monitor:/usr/local/nagios/libexec$ /usr/local/nagios/libexec/check_generic -e "/bin/sh /usr/local/nagios/libexec/checkipsload.sh" -w ">5" -c ">70" -n "IPS Inspection Load"
IPS Inspection Load WARNING - result:17 match:>5 severities:warning

Re: Plugin ok from CLI, not ok when executed by nagios

Posted: Tue Apr 15, 2014 3:48 am
by cosmin.neagu
Hi,
I found the problem, it was the fact that in checkipsload.sh, was a relative path defined instead of full path

#!/bin/bash
/usr/bin/expect -f expectips | sed -E 's/\r//g' | grep "Inspection Load" | tr -d '\n' | awk '{print $4}'

After i change the script will full path, everithing was ok
#!/bin/bash
/usr/bin/expect -f /usr/local/nagios/libexec/expectips | sed -E 's/\r//g' | grep "Inspection Load" | tr -d '\n' | awk '{print $4}'

Re: Plugin ok from CLI, not ok when executed by nagios

Posted: Tue Apr 15, 2014 9:55 am
by abrist
cosmin.neagu wrote:I found the problem, it was the fact that in checkipsload.sh, was a relative path defined instead of full path
Good catch! expectips most likely was not in the nagios $PATH.
Cheers.