Page 1 of 2

Bad result code in a PERL plugin

Posted: Mon Jan 09, 2017 11:53 am
by andresrinaldi_uy
Hello, I am having a extrange problem with a perl plugin:

check_iftraffic64.pl https://exchange.nagios.org/directory/P ... 64/details

This plugin checks the traffic using SNMP, and do the job fine but I have a problem when shows the results in the WEB-GUI which I could not resolv.

Image

As it can see in the image, the result is "OK" but the status is "UNKNOWN". I got in touch with the developer but he could not figure out what the problem was. I kept doing some researches and debugging but I do not know what to do, so I ask for your help. I got the same result in three Nagios installations (one of them a clean one).

Debug info:

Code: Select all

[1483644257.422936] [016.1] [pid=21070] Embedded Perl ran /usr/lib/nagios/plugins/check_iftraffic64.pl: return code=3, plugin output=OK - Average IN: 9.71KB (0.01%), Average OUT: 11.76KB (0.01%)Total RX: 1.06GBytes, Total TX: 417.88MBytes
|inUsage=0.01%;85;98 outUsage=0.01%;85;98 inBandwidth=9712.38B 
|outBandwidth=11759.16B inAbsolut=1056798111c outAbsolut=417877276c\n
return code=3

If I run the plugin from terminal and I do "echo $?" it returns code 0

I also created a perl file with:

Code: Select all

#!/usr/bin/perl -w
exit $STATUS_CODE{'OK'};
And it shows OK as result.

My command definition:

Code: Select all

define command{
        command_name    check_iftraffic64
        command_line    $USER1$/check_iftraffic64.pl -H $HOSTADDRESS$ $ARG1$
}

define service {
        use                     generic-service
        host                    hostname
        service_description     Check Traffic
        check_command         check_iftraffic64!-C nagios -i 11 -w 85 -c 98
}
OS: Debian 8.2
Nagios: Core 3.5.1 (from Debian Repository)
Apache: 2.4 (from Debian Repository)

Re: Bad result code in a PERL plugin

Posted: Mon Jan 09, 2017 12:26 pm
by dwhitfield
What's the output of sestatus?

Did this ever work? If so, your apt log might be useful. Also, if it did work before, when did it stop working?

Is there a reason you are still running 3.5.1? Compiling from source only takes about 5 minutes. Instructions at https://support.nagios.com/kb/article.php?id=96. Do not compile from source over the top of the repo install. You'll have to uninstall if you choose to upgrade.

Re: Bad result code in a PERL plugin

Posted: Mon Jan 09, 2017 12:41 pm
by andresrinaldi_uy
Hi, thanks for your help, It never worked.

I am using this version of Nagios because it was in the Debian repositories when I installed it two years ago, I am thinking migrate to Nagios 4 as soon as can.

Could you explainme how I can see the output of setstatus?

Re: Bad result code in a PERL plugin

Posted: Mon Jan 09, 2017 12:51 pm
by dwhitfield
andresrinaldi_uy wrote:Could you explainme how I can see the output of setstatus?
you've got a typo sestatus versus setstatus. If bash says it can't find it, then SELinux is probably not installed or not on.

You can also try cat /etc/sysconfig/selinux

Re: Bad result code in a PERL plugin

Posted: Mon Jan 09, 2017 1:03 pm
by andresrinaldi_uy
It was not installed

Code: Select all

SELinux status:     disabled
/etc/selinux/config

Code: Select all

SELINUX=permissive
SELINUXTPE=default
SETLOCALDEFS=0

Re: Bad result code in a PERL plugin

Posted: Mon Jan 09, 2017 1:38 pm
by avandemore
When you run the plugin from the command line it should be like this:

Code: Select all

# su - nagios
$ /path/to/plugin $ARGs
Immediately after the plugin returns run:

Code: Select all

$ echo $?
Or even more concisely:

Code: Select all

# su - nagios
$ /path/to/plugin $ARGs; echo $?

Re: Bad result code in a PERL plugin

Posted: Mon Jan 09, 2017 1:46 pm
by andresrinaldi_uy
I have done this while I was testing and all seems to work fine, but in the WEB-GUI still orange it does not matter if OK or CRITICAL, the return code is always 3

Image

Re: Bad result code in a PERL plugin

Posted: Mon Jan 09, 2017 4:32 pm
by dwhitfield
Perhaps there is a permission error. What's the output of ls -la /usr/lib/nagios/plugins?

Re: Bad result code in a PERL plugin

Posted: Mon Jan 09, 2017 8:09 pm
by andresrinaldi_uy
I've already checked it, the same permissions that other plugins.

Code: Select all

-rwxr-xr-x 1 root root  39175 ene  9 18:07 check_iftraffic64.pl

Re: Bad result code in a PERL plugin

Posted: Tue Jan 10, 2017 9:50 am
by rkennedy
The original definition you have varies from the check command you posted above. The screenshot mentions -i 65539 where as your service definition is for 11. You'll want to match these up in order to see the same result across the board.