Revision: 1795
http://nagiosplug.svn.sourceforge.net/nagiosplug/?rev=1795&view=rev
Author: tonvoon
Date: 2007-09-24 11:45:59 -0700 (Mon, 24 Sep 2007)
Log Message:
-----------
Help, usage and version output go to stdout now, rather than stderr
Modified Paths:
--------------
Nagios-Plugin/trunk/Changes
Nagios-Plugin/trunk/lib/Nagios/Plugin/Functions.pm
Nagios-Plugin/trunk/lib/Nagios/Plugin/Getopt.pm
Nagios-Plugin/trunk/t/Nagios-Plugin-Getopt-01.t
Nagios-Plugin/trunk/t/Nagios-Plugin-Getopt-02.t
Nagios-Plugin/trunk/t/Nagios-Plugin-Getopt-04.t
Nagios-Plugin/trunk/t/check_stuff.t
Modified: Nagios-Plugin/trunk/Changes
===================================================================
--- Nagios-Plugin/trunk/Changes 2007-09-24 00:30:14 UTC (rev 1794)
+++ Nagios-Plugin/trunk/Changes 2007-09-24 18:45:59 UTC (rev 1795)
@@ -1,5 +1,8 @@
Revision history for Perl module Nagios::Plugin.
+0.21 ??
+ - Help, usage and version output now goes to stdout, not stderr
+
0.20 5th September 2007
- Version bump because of CPAN permission problems
Modified: Nagios-Plugin/trunk/lib/Nagios/Plugin/Functions.pm
===================================================================
--- Nagios-Plugin/trunk/lib/Nagios/Plugin/Functions.pm 2007-09-24 00:30:14 UTC (rev 1794)
+++ Nagios-Plugin/trunk/lib/Nagios/Plugin/Functions.pm 2007-09-24 18:45:59 UTC (rev 1795)
@@ -8,7 +8,7 @@
use strict;
use warnings;
use File::Basename;
-use Params::Validate qw(validate :types);
+use Params::Validate qw(:types validate);
use Math::Calc::Units;
# Remember to update Nagios::Plugins as well
@@ -119,14 +119,24 @@
return Nagios::Plugin::ExitResult->new($code, $output);
}
- # Print output and exit; die if called via nagios_die and flag set
- if($_use_die && (caller(1))[3] =~ m/die/) {
- $!=$code;
- die($output);
- } else {
- print $output;
- exit $code;
+ _nagios_exit($code, $output);
+}
+
+sub _nagios_exit {
+ my ($code, $output) = @_;
+ # Print output and exit; die if flag set and called via a die in stack backtrace
+ if ($_use_die) {
+ for (my $i = 0;; $i++) {
+ @_ = caller($i);
+ last unless @_;
+ if ($_[3] =~ m/die/) {
+ $! = $code;
+ die($output);
+ }
+ }
}
+ print $output;
+ exit $code;
}
# nagios_die( $message, [ $code ]) OR nagios_die( $code, $message )
Modified: Nagios-Plugin/trunk/lib/Nagios/Plugin/Getopt.pm
===================================================================
--- Nagios-Plugin/trunk/lib/Nagios/Plugin/Getopt.pm 2007-09-24 00:30:14 UTC (rev 1794)
+++ Nagios-Plugin/trunk/lib/Nagios/Plugin/Getopt.pm 2007-09-24 18:45:59 UTC (rev 1795)
@@ -60,9 +60,7 @@
my $self = shift;
my ($msg) = @_;
$msg .= "\n" unless substr($msg, -1) eq "\n";
- # Set errno to UNKNOWN for die return code
- local $! = 3;
- die $msg;
+ Nagios::Plugin::Functions::_nagios_exit(3, $msg);
}
# Return the given attribute, if set, including a final newline
Modified: Nagios-Plugin/trunk/t/Nagios-Plugin-Getopt-01.t
===================================================================
--- Nagios-Plugin/trunk/t/Nagios-Plugin-Getopt-01.t 2007-09-24 00:30:14 UTC (rev 1794)
+++ Nagios-Plugin/trunk/t/Nagios-Plugin-Getopt-01.t 2007-09-24 18:45:59 UTC (rev 1795)
@@ -5,6 +5,9 @@
use Test::More tests => 76;
BEGIN { use_ok('Nagios::Plugin::Getopt') };
+# Needed to get evals to work in testing
+Nagios::Plugin::Functions::_use_die(1);
+
my %PARAM = (
version => '0.01',
url => 'http://www.openfusion.com.au/labs/nagios/',
Modified: Nagios-Plugin/trunk/t/Nagios-Plugin-Getopt-02.t
===================================================================
--- Nagios-Plugin/trunk/t/Nagios-Plugin-Getopt-02.t 2007-09-24 00:30:14 UTC (rev 1794)
+++ Nagios-Plugin/trunk/t/Nagios-Plugin-Getopt-02.t 2007-09-24 18:45:59 UTC (rev 1795)
@@ -5,6 +5,9 @@
use Test::More tests => 14;
BEGIN { use_ok('Nagios::Plugin::Getopt') };
+# Needed to get evals to work in testing
+Nagios::Plugin::Functions::_use_die(1);
+
my %PARAM = (
version => '0.01',
url => 'http://www.openfusion.com.au/labs/nagios/',
Modified: Nagios-Plugin/trunk/t/Nagios-Plugin-Getopt-04.t
===================================================================
--- Nagios-Plugin/trunk/t/Nagios-Plugin-Getopt-04.t 2007-09-24 00:30:14 UTC (rev 1794)
+++ Nagios-Plugin/trunk/t/Nagios-Plugin-Getopt-04.t 2007-09-24 18:45:59 UTC (rev 1795)
@@ -5,6 +5,9 @@
use Test::More tests => 11;
BEGIN { use_ok('Nagios::Plugin::Getopt') };
+# Needed to get evals to work in testing
+Nagios::Plugin::Functions::_use_die(1);
+
my %PARAM = (
version => '0.01',
usage => "Don't use this plugin!",
Modified: Nagios-Plugin/trunk/t/check_stuff.t
===================================================================
--- Nagios-Plugin/trunk/t/check_stuff.t 2007-09-24 00:30:14 UTC (rev 1794)
+++ Nagios-Plugin/trunk/t/check_stuff.t 2007-09-24 18:45:59 UTC (rev 1795)
@@ -2,7 +2,7 @@
#
use strict; use warnings;
#use Test::More qw(no_plan);
-use Test::More tests => 16;
+use Test::More tests => 14;
my ($r,$args);
my $s = 't/check_stuff.pl';
@@ -22,24 +22,14 @@
is $?>>8 , $e{UNKNOWN}, "exits($e{UNKNOWN}) with no args";
like $r, qr/^$n UNKNOWN/, "UNKNOWN with no args";
+$r = `$s -V`;
+is $?>>8 , $e{UNKNOWN}, "exits($e{UNKNOWN}) with -V arg";
+like $r, qr/^[\w\.]+ \d+/i, "looks like there's a version";
-#TODO:
-SKIP: {
- local $TODO = q~d'oh! we'll have to redirect STDERR and check it with like() here instead of checking `` which only gets STDIN. Maybe use IPC::Open3?~;
- skip "too noisy, see TODO here", 6;
+$r = `$s -h`;
+is $?>>8 , $e{UNKNOWN}, "exits($e{UNKNOWN}) with -h arg";
+like $r, qr/usage/i, "looks like there's something helpful"; # broken
- $r = `$s -V`;
- is $?>>8 , $e{UNKNOWN}, "exits($e{UNKNOWN}) with -V arg";
- like $r, qr/\d+\.\d/i, "looks like there's a version"; # broken
- is $r, '', "prints nothing to STDOUT";
-
- $r = `$s -h`;
- is $?>>8 , $e{UNKNOWN}, "exits($e{UNKNOWN}) with -h arg";
- like $r, qr/usage/i, "looks like there's something helpful"; # broken
- is $r, '', "prints nothing to STDOUT";
-}
-
-
$args = " -r 99 ";
diag "running `$s $args`" if $ENV{TEST_VERBOSE};
$r = `$s $args`;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.