Patch for ePN p1.pl

Gavin Carr gavin at openfusion.com.au
Wed Mar 22 00:14:46 CET 2006


There's a bug in the ePN p1.pl shipped with Nagios 2.0 final, where
only the output of the very last print / printf is retained and
reported, leading to plugins that work from the command line 
generating bogus "No output from plugin" messages under ePN. I've
discussed this with Stanley Hopcroft and he's confirmed the bug.

Patch attached that fixes the bug, while retaining the current
limitations on message length and multi-line output.

Cheers,
Gavin

--
Open Fusion - Open Source Business Solutions [ Linux - Perl - Apache ]
http://www.openfusion.com.au
http://www.sharebot.net
- Fashion is a variable, but style is a constant - Programming Perl
-------------- next part --------------
--- p1.pl.dist	2006-03-21 11:42:30.000000000 +1100
+++ p1.pl	2006-03-21 11:56:16.000000000 +1100
@@ -69,27 +69,29 @@
  
 sub TIEHANDLE {
 	my ($class) = @_;
-	my $me ;
+	my $me = '';
 	bless \$me, $class;
 }
 
 sub PRINT {
 	my $self = shift;
-	$$self = substr(join('', at _), 0, 256) ;
-	# $$self .= substr(join('', at _), 0, 256) ;
+	# $$self = substr(join('', at _), 0, 256) ;
+	$$self .= substr(join('', at _), 0, 256) ;
 }
 
 sub PRINTF {
 	my $self = shift;
 	my $fmt = shift;
-	$$self = substr(sprintf($fmt, at _), 0, 256) ;
-	# $$self .= substr(sprintf($fmt, at _), 0, 256) ;
+	# $$self = substr(sprintf($fmt, at _), 0, 256) ;
+	$$self .= substr(sprintf($fmt, at _), 0, 256) ;
 }
 
 sub READLINE {
 	my $self = shift;
+								# Omit all lines after the first, per the nagios plugin guidelines
+        $$self = (split /\n/, $$self)[0];
 								# Perl code other than plugins may print nothing; in this case return "(No output!)\n".
-	return $$self ? $$self : "(No output!)\n" ;
+	return $$self ? substr($$self, 0, 256) : "(No output!)\n" ;
 }
 
 sub CLOSE {


More information about the Developers mailing list