[Nagiosplug-devel] Custom plugin errors: Return code of 13 is out of bounds

Jed Obray Jed.Obray at intermountainmail.org
Wed Dec 7 10:31:05 CET 2005


I am developing the following Perl plugin that is used to read data from
a text file and provide the data to Nagios.  This is my first attempt at
a Nagios plugin so go easy on me.  I'm also fairly new to Perl.  If this
isn't the correct list, I apologize.

Basically, the Perl script compiles and executes from the console just
fine.  I am using strict, as suggested in the Plugin documentation.
However, when I define the script as a check_command in Nagios and
define a service, It errors "Return code of 13 is out of bounds".  Can
anyone help me understand what I'm doing incorrectly?

The Perl script is VERY basic.  I'm just trying to show that it can be
done.  I'm thinking that the problem may be in the "or die" statements.
>From the Nagios documentation, I'm getting the impression that this is
not the correct way to error out; I should be using the
$ERRORS{'UNKOWN'} or something to that effect?

|------- Perl script check_gwapi.pl --------|
File info: -rwxr-xr-x  1 nagios nagios  1346 2005-12-09 13:37
check_gwapi.pl*
=========================
#! /usr/bin/perl -w

#Reads a file for data regarding GW API queue size.
#File data is collected on the NW API server and deposited
#on the API server.
#A cron job on the Nagios server picks up these files to be
#processed by this check script.

use POSIX;
use strict;
use Getopt::Long;
use vars qw($logpath $logfile $warning $critical $line $pathread
$filecount $msg $state);
use lib "/usr/local/nagios/libexec";
use utils qw(%ERRORS);
my(@raw_log) = {};

$ENV{'PATH'} = '';
$ENV{'BASH_ENV'} = '';
$ENV{'ENV'} = '';

#usage = check_gwapi logpath logfile warning critical
$logpath = shift;
$logfile = shift;
$warning = shift;
$critical = shift;


#open the file for reading
chdir $logpath or die "ERROR: Unable to chdir to $logpath\n" if
$logpath;
open (API_FILE, $logfile) or die "ERROR: Unable to open $logfile in
$logpath\n";
@raw_log =<API_FILE>;
close(API_FILE);

foreach $line (@raw_log)
{
        chop($line);
        ($pathread,$filecount) = split(/\|/,$line);
}

if ($filecount < $warning)
{
        $msg = "OK: $filecount files in $pathread";
        $state = $ERRORS{'OK'};
}
elsif ($filecount >= $warning && $filecount < $critical)
{
        $msg = "WARNING: $filecount files in $pathread";
        $state = $ERRORS{'WARNING'};
}
else
{
        $msg = "CRITICAL: $filecount files in $pathread";
        $state = $ERRORS{'CRITICAL'};
}

print $msg;
exit $state;

|------- End Perl script --------|

|------- check_command ----------|
define command{
        command_name    check_gwapi
        command_line    $USER1$/check_gwapi.pl $ARG1$ $ARG2$ $ARG3$
$ARG4$
}
|------- End check_command ------|

|------- Service definition -----|
define service{
        use                             generic-service
        host_name                       SERVER-NAME
        service_description             FILE QUEUE NAME
        is_volatile                     0
        check_period                    24x7
        max_check_attempts              3
        normal_check_interval           10
        retry_check_interval            10
        contact_groups                  servers-lp
        notification_interval           120
        notification_period             24x7
        notification_options            w,c,r
        check_command
check_gwapi!/path/to/file/nagios!FILE_NAME!200!300
        }
|------- End Service definition ---|

I've changed some of the argument info with generic stuff.  Again, this
seems to work great from the console, just not when it's running through
Nagios.

Thanks for any assistance you can provide.





More information about the Devel mailing list