Perl subroutine plug-in

Dean Bishop dbishop at ehvert.com
Fri May 30 21:49:40 CEST 2003


Try adding this to the top of the script.
 
#! /usr/bin/perl
use Getopt::Long;
use vars qw($opt_V $opt_h $opt_H $opt_w $opt_c $PROGNAME);
use lib "/usr/local/nagios/libexec"  ;
use utils qw(%ERRORS &print_revision &support &usage);
 
$PROGNAME = "check_queue";
 
sub print_help ();
sub print_usage ();
 
$ENV{'PATH'}='';
$ENV{'BASH_ENV'}='';
$ENV{'ENV'}='';
 
 
and use something like this for your exit code
 
if ($ok){
  print "Ok. $line\n";
  exit $ERRORS{'OK'};
}
 
if ($not_ok) {
  print "WARNING.  Cannot read the bloody line\n";
  exit $ERRORS{"WARNING"};
}
 
 
I'm no perl expert but I hacked around until mine worked and this is what I
did.
 
Later,
Dean
 
 
-----Original Message-----
From: Jan van den Berg [mailto:jan at e-commercepark.com] 
Sent: May 30, 2003 2:06 PM
To: 'Nagios-Users (E-mail)'
Subject: [Nagios-users] Perl subroutine plug-in
 
 
Hi there,
 
I don't if this is the right place here, but I have a question about a
plug-in I'm developing.
 
See the following Perl sub-routine
 
sub get_alert
        {
        local @ARGV = '/var/log/alert';
        my @last8;
  
        while (<>) {
                push @last8, $_;
                shift @last8 while @last8 > 8;
                        }
                        my $line = $last8[-6];
                        my $line =~ y/[,'"()<>]:;0123456789*//d;

                        print $line;   
                        #print "test";
        }
 
So what this does is, get the 8 before last line from a log file, strips
this line from meta-characters and print out a clean line of text. When I
run this command-line: no problem. However Nagios says there is no output!
But when I uncomment the print "test"; it prints this out nicely in
Nagios..... so the subroutine is okay, and the print statement is okay.
 (I also tried using quotes around "$line" but that didn't work).
 
So what am I doing wrong here?
 
Please help.
 
Jan van den Berg
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.monitoring-lists.org/archive/users/attachments/20030530/63b1bc8a/attachment.html>


More information about the Users mailing list