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

Jed Obray Jed.Obray at intermountainmail.org
Wed Dec 7 11:00:04 CET 2005


Disregard this message (if you haven't already ;) - I've found the
problem.  I'm EMBARASSED to say it was a file permissions issue.... it
was the "or die" statements that were causing the return code 13.  Now,
I can write the _correct_ error handling into the Perl script.

However, after looking at the script below, if any of you have any
suggestions to improve it (I'm sure there are many) I would love to hear

Thanks again!

-----Original Message-----
From: nagiosplug-devel-admin at lists.sourceforge.net
[mailto:nagiosplug-devel-admin at lists.sourceforge.net] On Behalf Of Jed
Sent: Wednesday, December 07, 2005 11:29 AM
To: nagiosplug-devel at lists.sourceforge.net
Subject: [Nagiosplug-devel] Custom plugin errors: Return code of 13 is
out of bounds

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
#! /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
open (API_FILE, $logfile) or die "ERROR: Unable to open $logfile in
@raw_log =<API_FILE>;

foreach $line (@raw_log)
        ($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'};
        $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$
|------- 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
|------- 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

Thanks for any assistance you can provide.

This SF.net email is sponsored by: Splunk Inc. Do you grep through log
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
Nagios Plugin Development Mailing List
Nagiosplug-devel at lists.sourceforge.net
Unsubscribe at
::: Please include plugins version (-v) and OS when reporting any issue.

::: Messages without supporting info will risk being sent to /dev/null

More information about the Devel mailing list