[Nagiosplug-devel] Custom Plugin issue

Subhendu Ghosh sghosh at sghosh.org
Sun May 8 01:52:14 CEST 2005


This is the correct forum - but you may want to subscribe before posting 
as well.

Documentation on writing plugins:
http://nagiosplug.sourceforge.net/developer-guidelines.html

Nagios looks at the exit codes.
An "echo $?" after running the plugin on the command line will tell you if 
you are exiting with the proper code or not.
You are missing a "exit ($status)" line at the end.

-sg


On Thu, 5 May 2005, Frank Reta wrote:

> Hello:
>
>            Not sure if these are the correct forums through which to
> ask questions, but I couldn't find where else to post to.
>
>
>
> Nagios 1.2 on Fedora 3
>
>
>
> I'm in the throes of trying to create an in-house script that parses a
> file for a given number.  It then uses this number to determine if the
> return should be OK, WARNING or CRITICAL.  When command line run, the
> issued PRINT line displays the correct result given the parameters
> given.  When brought into Nagios, the "Status Information" portion of
> the service item is correct, but the actual "Status" entry never changes
> from OK, despite the plugin reporting "Critical".
>
>
>
> The perl script is:
>
>
>
> #!/usr/bin/perl -w
>
>
>
> use strict;
>
> use warnings;
>
> use Getopt::Long;
>
>
>
> use constant STATS_FILE_PATH =>
> '/home/kapow/crawler/etc/crawl-server.stat';
>
>
>
> my @return_codes = qw( OK WARNING CRITICAL UNKNOWN );
>
>
>
>
>
> my ($warning, $critical) = get_cmd_params();
>
> my $threads = 0;
>
> my $status = 0;
>
> my $msg = '';
>
>
>
> if( open( STAT, STATS_FILE_PATH ) ) {
>
>
>
>    foreach ( <STAT> ) {
>
>        next unless /^threads=(\d+)/;
>
>        $threads = $1;
>
>    }
>
>    close( STAT );
>
>    $status = ( $threads > $warning ) ? 0 :
>
>        ( $threads > $critical ) ? 1 : 2;
>
>    $msg = "crawl-server currently has $threads threads";
>
> } else {
>
>    $status = 3;
>
>    $msg = 'unable to open crawl-server stats file';
>
> }
>
>
>
>
>
> print( "threads $return_codes[$status] - $msg ",
>
>       "|threads=$threads;$warning;$critical;$status\n" );
>
>
>
>
>
>
>
> ######################################################################
>
> sub get_cmd_params {
>
>
>
>    my ($warning, $critical) = (0,0);
>
>
>
>    my $result = GetOptions( 'w=i' => \$warning,
>
>                             'c=i' => \$critical );
>
>
>
>    die "Usage: get_crawler_stats -w <threads> -c <threads>\n"
>
>        if($warning <= 0 || $critical <= 0);
>
>
>
>    return ($warning, $critical);
>
> }
>
>
>
>
>
>
>
> When run on command line, the result is:
>
> [root at warlords etc]# /usr/local/nagios/libexec/check_nrpe -H crawl1 -c
> check_threads -a 70 60
>
> threads WARNING - crawl-server currently has 64 threads
> |threads=64;70;60;0
>
>
>
> (to compare, the check_users, which does work correctly all the way
> through is:)
>
> [root at warlords libexec]# ./check_users -w 1 -c 6
>
> USERS WARNING - 5 users currently logged in |users=5;1;6;0
>
>
>
>
>
> Any help on this would be immensely appreciated.  If this is not the
> correct forum to direct my questions to, could you please point me in
> the right direction?
>
>
>
> Thanks much!
>
>
>
> Frank Reta
>
> Information Technology Janitor - Simply Hired
> <http://www.simplyhired.com/> , Inc.
>
> http://www.SimplyHired.com
>
> (650) 254-9000x130
>
> frank at simplyhired.com
>
>
>
>

-- 





More information about the Devel mailing list