[Nagiosplug-devel] Perl subroutine
Michael Haro
michael.haro at resources.ca.gov
Fri May 30 11:55:03 CEST 2003
It might be more efficient to seek() to the end of the file and read
backwards.
Does the nagios user have access to read /var/log/alert?
I'm not sure if it is better, but it might be better to actually open()
the file.
Something like...
my $fh = new FileHandle;
$fh->open('/var/log/alert') or die("/var/log/alert: $!");
while(<$fh>) {
...
}
$fh->close;
might work. But I'm no PERL expert.
Michael
--
Michael Haro
Systems & Network Administrator
California Resources Agency / CERES
-----Original Message-----
From: Jan van den Berg [mailto:jan at e-commercepark.com]
Sent: Friday, May 30, 2003 11:24 AM
To: Nagiosplug-devel at lists.sourceforge.net
Subject: [Nagiosplug-devel] Perl subroutine
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
More information about the Devel
mailing list