[Nagiosplug-devel] Custom Plugin issue

Andreas Ericsson ae at op5.se
Sun May 8 01:58:29 CEST 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".
> 

Because it exits with return code 0. Read the plugin developer 
guidelines or the code of another plugin. The output doesn't matter at 
all. Only the return-code as given from the program to the shell by the 
exit(3) library call.

Having nagios actually care about the output of plugins would be 
seriously stupid performance-wise.

>  
> 
> 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
> 
>  
> 
> 

-- 
Andreas Ericsson                   andreas.ericsson at op5.se
OP5 AB                             www.op5.se
Lead Developer




More information about the Devel mailing list