Return code of 9 is out of bounds when plugin is runin nagios, but return code is 0 when run from shell

Samuel Kidman Samuel.Kidman at panres.com
Tue Sep 13 07:53:24 CEST 2011


Hi

 

Does anyone know what's causing this error? I am utterly stumped.

 

From: Samuel Kidman [mailto:Samuel.Kidman at panres.com] 
Sent: Thursday, 8 September 2011 3:52 PM
To: nagios-users at lists.sourceforge.net
Subject: [Nagios-users] Return code of 9 is out of bounds when plugin is
runin nagios, but return code is 0 when run from shell

 

Hello


I am having an issue with a plugin I just wrote where the Nagios says
the return code is 9. If I do the following:

 

lnm at PR-LNM-CR-NAG01:/usr/local/nagios/libexec$ sudo -u nagios
./check_snmp_mw_local_rx_power.pl --hostname 192.168.27.140
--rocommunity EMSOLUTIONS --snmp-version 1

CHECK_RX_POWER OK - Local RX Power OK (-47.5dBm),
|'local_RX_Power'=-47.5;-67;-100;;

lnm at PR-LNM-CR-NAG01:/usr/local/nagios/libexec$ echo $?

0

 

It suggests the return code is 0.


I have disabled the embedded perl interpreter.

 

Can anyone tell what is going wrong?

 

Plugin source code below:

 

#!/usr/bin/perl

 

=pod

 

=head1 NAME

 

Name of plugin and a sentence explaining function

 

-head2 SYNOPSIS

 

Detailed explanation of what the check does, any caveats, etc.

 

=cut

 

sub check_snmp_mw_rx_power {

    use strict;

 

    use FindBin;

    use RRDs;

    use lib "$FindBin::Bin/lib";

    use lib "/usr/local/nagios/perl/lib";

 

    use Nagios::Plugin::SNMP;

    use Nenm::Utils;

 

    my $USAGE = <<EOF;

EOF

 

    my $LABEL = 'CHECK_RX_POWER';

 

    my $plugin = Nagios::Plugin::SNMP->new(

        'shortname' => $LABEL,

        'usage'     => $USAGE

    );

 

    $plugin->add_arg(

            spec => 'warning|w=s',

            help => "-w, --warning=INTEGER:INTEGER\n" .

            "Minimum and maximum number of allowable result, outside of
which a warning will be generated.\n",

            default => -67

            );

    

    $plugin->add_arg(

            spec => 'critical|c=s',

            help => "-c, --critical=INTEGER:INTEGER\n" .

            "Minimum and maximum number of allowable result, outside of
which a critical will be generated.\n",

            default => -100

            );

    

    $plugin->add_arg(

            spec => 'host|H=s',

            help => "-H, --host=STRING\n" .

            "IP address of Host to check\n"

            );

 

#example add_arg

#    $plugin->add_arg(

#        'spec' => 'interface|i=s',

#        'help' => "--interface, -i: Name of the interface to use; use
the\n" .

#                "                description as returned by
ifDescr.\n",

#       'required' => 0,

#       'default' = 'eth0/0'

#    );

 

#add arguments here

 

    $plugin->getopts;

 

    my $critical = $plugin->opts->critical;

    my $warning = $plugin->opts->warning;

    my $message;

    my $perfdata;

    my $LocalRXPower_OID = '.1.3.6.1.4.1.10132.9.1.4.12.0';

    my $LocalRXPower;

    my $local_return;

 

    my $result = $plugin->get($LocalRXPower_OID);

 

    $LocalRXPower = $result->{$LocalRXPower_OID} / 10;

 

    if ($LocalRXPower < $critical)

    {

        $message    = "CRITICAL: Local RX Power to low to maintain link.
(${LocalRXPower}dBm), ";

        $local_return = 2;

    }

    elsif   ($LocalRXPower < $warning)

    {

        $message = "WARNING: Local RX Power to low to maintain 32-QAM
Modulation. (${LocalRXPower}dBm), ";

        $local_return = 1;

    }

    else

    {

        $message = "Local RX Power OK (${LocalRXPower}dBm), ";

        $local_return = 0;

    }

    $perfdata = "'local_RX_Power'=$LocalRXPower;$warning;$critical;;";

 

    $plugin->nagios_exit($local_return, $message . "|" . $perfdata);

 

}

 

exit check_snmp_mw_rx_power();

 

 

 

Sam Kidman

IT Support Officer

--------------------------

T:        08 9225 0944

 

 

 

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.monitoring-lists.org/archive/users/attachments/20110913/2e341874/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image001.jpg
Type: image/jpeg
Size: 18659 bytes
Desc: image001.jpg
URL: <https://www.monitoring-lists.org/archive/users/attachments/20110913/2e341874/attachment.jpg>
-------------- next part --------------
------------------------------------------------------------------------------
BlackBerry® DevCon Americas, Oct. 18-20, San Francisco, CA
Learn about the latest advances in developing for the 
BlackBerry® mobile platform with sessions, labs & more.
See new tools and technologies. Register for BlackBerry® DevCon today!
http://p.sf.net/sfu/rim-devcon-copy1 
-------------- next part --------------
_______________________________________________
Nagios-users mailing list
Nagios-users at lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nagios-users
::: Please include Nagios version, plugin version (-v) and OS when reporting any issue. 
::: Messages without supporting info will risk being sent to /dev/null


More information about the Users mailing list