Bad result code in a PERL plugin

This forum is intended for the discussion of Nagios plugin development. Feature requests, patches, bug fixes, and all types of development-related discussions are welcome!

NOTE: The SourceForge.net nagiosplug-devel mailing list has been deprecated in favor of this forum in order to expedite support and provide additional features not available on the old mailing list.

Bad result code in a PERL plugin

Postby andresrinaldi_uy » Mon Jan 09, 2017 11:53 am

Hello, I am having a extrange problem with a perl plugin:

check_iftraffic64.pl https://exchange.nagios.org/directory/Plugins/Network-Connections%2C-Stats-and-Bandwidth/check_iftraffic64/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)
Attachments
unknown.png
Last edited by dwhitfield on Thu Jan 12, 2017 10:21 am, edited 1 time in total.
Reason: marking with green check mark
andresrinaldi_uy
 
Posts: 13
Joined: Wed Oct 28, 2015 11:19 am

Re: Bad result code in a PERL plugin

Postby dwhitfield » Mon Jan 09, 2017 12:26 pm

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.
https://support.nagios.com/forum/viewtopic.php?f=6&t=1274 says XI at the top, but it more-or-less applies to everything.
User avatar
dwhitfield
Support Tech
 
Posts: 1845
Joined: Wed Sep 21, 2016 10:29 am
Location: Nagios Enterprises, LLC

Re: Bad result code in a PERL plugin

Postby andresrinaldi_uy » Mon Jan 09, 2017 12:41 pm

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?
andresrinaldi_uy
 
Posts: 13
Joined: Wed Oct 28, 2015 11:19 am

Re: Bad result code in a PERL plugin

Postby dwhitfield » Mon Jan 09, 2017 12:51 pm

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
https://support.nagios.com/forum/viewtopic.php?f=6&t=1274 says XI at the top, but it more-or-less applies to everything.
User avatar
dwhitfield
Support Tech
 
Posts: 1845
Joined: Wed Sep 21, 2016 10:29 am
Location: Nagios Enterprises, LLC

Re: Bad result code in a PERL plugin

Postby andresrinaldi_uy » Mon Jan 09, 2017 1:03 pm

It was not installed

Code: Select all
SELinux status:     disabled


/etc/selinux/config
Code: Select all
SELINUX=permissive
SELINUXTPE=default
SETLOCALDEFS=0
andresrinaldi_uy
 
Posts: 13
Joined: Wed Oct 28, 2015 11:19 am

Re: Bad result code in a PERL plugin

Postby avandemore » Mon Jan 09, 2017 1:38 pm

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 $?
User avatar
avandemore
Support Tech
 
Posts: 1044
Joined: Tue Sep 27, 2016 4:57 pm
Location: Nagios Enterprises

Re: Bad result code in a PERL plugin

Postby andresrinaldi_uy » Mon Jan 09, 2017 1:46 pm

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
Attachments
cmd.png
andresrinaldi_uy
 
Posts: 13
Joined: Wed Oct 28, 2015 11:19 am

Re: Bad result code in a PERL plugin

Postby dwhitfield » Mon Jan 09, 2017 4:32 pm

Perhaps there is a permission error. What's the output of ls -la /usr/lib/nagios/plugins?
https://support.nagios.com/forum/viewtopic.php?f=6&t=1274 says XI at the top, but it more-or-less applies to everything.
User avatar
dwhitfield
Support Tech
 
Posts: 1845
Joined: Wed Sep 21, 2016 10:29 am
Location: Nagios Enterprises, LLC

Re: Bad result code in a PERL plugin

Postby andresrinaldi_uy » Mon Jan 09, 2017 8:09 pm

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
andresrinaldi_uy
 
Posts: 13
Joined: Wed Oct 28, 2015 11:19 am

Re: Bad result code in a PERL plugin

Postby rkennedy » Tue Jan 10, 2017 9:50 am

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.
rkennedy
 
Posts: 6503
Joined: Mon Oct 05, 2015 11:45 am

Next

Return to Nagios Plugin Development

Who is online

Users browsing this forum: No registered users and 2 guests