[Nagiosplug-help] trouble installing a plugin i wrote

jim nagios at nachlin.com
Thu Sep 16 11:47:13 CEST 2004


Hi,

I've written this plugin in perl [attached at bottom of this message]
which works locally, but will not work when called remotely via
check_nrpe.  The error message is that the command is not defined, but
it is indeed in etc/nrpe.cfg.

[root at nagios02 nagios]# ./libexec/check_nrpe -H web04 -c
check_syndication_output
NRPE: Command 'check_syndication_output' not defined

On the machine running nrpe:

(14:35:25 foo nagios)# ./libexec/check_syndication_output -f /etc/motd
CRITICAL: /etc/motd is < 1000 bytes


The line in nrpe.cfg:
command[check_syndication_output]=/usr/local/nagios/libexec/check_syndication_output 

-f /mnt/web04/file.xml


The code of the plugin:
=========================
#! /usr/bin/perl -w

# check_syndication_output
#  a nagios plugin to monitor file size, age, and presence
#  requires -f <file> argument
#
############################################################################

use POSIX;
use strict;
use Getopt::Long;
use vars qw($opt_V $opt_h $opt_v $verbose $PROGNAME $opt_w $opt_c $file
$status $state $msg $msg_q );
use lib  "/usr/local/nagios/libexec" ;
use utils qw(%ERRORS &print_revision &support &usage );

############################################################################
### a little gross config
my $file;
my $verbose = 0;
my $minfilesize=1000;
my $maxage=0.042; # total in days

sub print_help ();
sub print_usage ();
sub process_arguments ();

$ENV{'PATH'}='';
$ENV{'BASH_ENV'}='';
$ENV{'ENV'}='';
$PROGNAME = "check_syndication_output";

Getopt::Long::Configure('bundling');
$status = process_arguments();
if ($status){
         print "ERROR: processing arguments\n";
         exit $ERRORS{"CRITICAL"};
}


my $stat = 1; # means everything is cool
my $statusstring = "";

# the meat^H^H^H^Htofu
if( -e $file ){
     if ( -s $file < $minfilesize ){
         $stat = 0;
         $statusstring = "$file is < $minfilesize bytes";
     } elsif ( -M $file > $maxage ){
         $stat = 0;
         $statusstring = "$file is more than $maxage days old";
     }
} else {
     $stat = 0;
     $statusstring = "$file does not exist"
}

# end tofu
if(! $stat) {
     $msg = "CRITICAL: $statusstring";
     $state = $ERRORS{'CRITICAL'};
}else{
     $msg = "OK: $file exists, is recent, and is big enough.";
     $state = $ERRORS{'OK'};
}

# declare an error if we also get a non-zero return code from
# unless already set to critical
if ( $? ) {
         $state = $state == $ERRORS{"CRITICAL"} ? $ERRORS{"CRITICAL"} :
$ERRORS{"UNKNOWN"}  ;
         print "error: $!\n" if $verbose;
}
## close mailq

# Perfdata support
print "$msg\n";
exit $state;


#####################################
#### subs


sub process_arguments(){
         GetOptions
                 ("V"   => \$opt_V, "version"    => \$opt_V,
                  "v"   => \$opt_v, "verbose"    => \$opt_v,
                  "h"   => \$opt_h, "help"       => \$opt_h,
                  "f=s" => \$file,  "file=s"     => \$file
                  );

         if ($opt_V) {
                 print_revision($PROGNAME,'$Revision: 1.1 $ ');
                 exit $ERRORS{'OK'};
         }

         if ($opt_h) {
                 print_help();
                 exit $ERRORS{'OK'};
         }

         if (defined $opt_v ){
                 $verbose = $opt_v;
         }

         unless (defined $file) {
                 print_help();
                 exit $ERRORS{'UNKNOWN'};
         }

         return $ERRORS{'OK'};
}
sub print_usage () {
         print "Usage: $PROGNAME [-v verbose]\n";
}

sub print_help () {
         print_revision($PROGNAME,'$Revision: 1.1 $');
         print "Copyright (c) 2004 Kinja Media\n";
         print "\n";
         print_usage();
         print "\n";
         print "   Checks selected log files for error messages\n\n";
         print "-h (--help)\n";
         print "-f (--file)      = file to monitor\n";
         print "-V (--version)\n";
         print "-v (--verbose)   = debugging output\n";
         print "\n\n";
         support();
}

=========================

Thanks in advance,
Jim





More information about the Help mailing list