diff options
author | Ton Voon <tonvoon@users.sourceforge.net> | 2007-08-31 13:21:10 +0000 |
---|---|---|
committer | Ton Voon <tonvoon@users.sourceforge.net> | 2007-08-31 13:21:10 +0000 |
commit | 95dba9c4213c2e7e8f4b572efd873c1979406221 (patch) | |
tree | c39a8dc0022ae98b09bfe5fa75f2dc67b3c97a69 /lib/Nagios | |
parent | 4421aa3c2a695335cad006f32ece6c9c5da11165 (diff) | |
download | monitoring-plugin-perl-95dba9c4213c2e7e8f4b572efd873c1979406221.tar.gz |
Fixed bug where warn or crit = 0 will raise an error. Optional flag to
tell nagios_die to use die instead of exit so trappable by eval
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/Nagios-Plugin/trunk@1772 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'lib/Nagios')
-rw-r--r-- | lib/Nagios/Plugin.pm | 3 | ||||
-rw-r--r-- | lib/Nagios/Plugin/Functions.pm | 18 | ||||
-rw-r--r-- | lib/Nagios/Plugin/Threshold.pm | 4 |
3 files changed, 18 insertions, 7 deletions
diff --git a/lib/Nagios/Plugin.pm b/lib/Nagios/Plugin.pm index 459e6bb..fe83575 100644 --- a/lib/Nagios/Plugin.pm +++ b/lib/Nagios/Plugin.pm | |||
@@ -476,7 +476,8 @@ form "SHORTNAME CODE - $message". | |||
476 | =item nagios_die( $message, [<CODE>] ) | 476 | =item nagios_die( $message, [<CODE>] ) |
477 | 477 | ||
478 | Same as nagios_exit(), except that CODE is optional, defaulting | 478 | Same as nagios_exit(), except that CODE is optional, defaulting |
479 | to UNKNOWN. | 479 | to UNKNOWN. NOTE: exceptions are not raised by default to calling code. |
480 | Set C<$_use_die> flag if this functionality is required (see test code). | ||
480 | 481 | ||
481 | =item die( $message, [<CODE>] ) | 482 | =item die( $message, [<CODE>] ) |
482 | 483 | ||
diff --git a/lib/Nagios/Plugin/Functions.pm b/lib/Nagios/Plugin/Functions.pm index f750968..e8b292e 100644 --- a/lib/Nagios/Plugin/Functions.pm +++ b/lib/Nagios/Plugin/Functions.pm | |||
@@ -46,6 +46,10 @@ our %STATUS_TEXT = reverse %ERRORS; | |||
46 | my $_fake_exit = 0; | 46 | my $_fake_exit = 0; |
47 | sub _fake_exit { @_ ? $_fake_exit = shift : $_fake_exit }; | 47 | sub _fake_exit { @_ ? $_fake_exit = shift : $_fake_exit }; |
48 | 48 | ||
49 | # _use_die flag and accessor/mutator, so exceptions can be raised correctly | ||
50 | my $_use_die = 0; | ||
51 | sub _use_die { @_ ? $_use_die = shift : $_use_die }; | ||
52 | |||
49 | sub get_shortname { | 53 | sub get_shortname { |
50 | my %arg = @_; | 54 | my %arg = @_; |
51 | 55 | ||
@@ -115,9 +119,14 @@ sub nagios_exit { | |||
115 | return Nagios::Plugin::ExitResult->new($code, $output); | 119 | return Nagios::Plugin::ExitResult->new($code, $output); |
116 | } | 120 | } |
117 | 121 | ||
118 | # Print output and exit | 122 | # Print output and exit; die if called via nagios_die and flag set |
119 | print $output; | 123 | if($_use_die && (caller(1))[3] =~ m/die/) { |
120 | exit $code; | 124 | $!=$code; |
125 | die($output); | ||
126 | } else { | ||
127 | print $output; | ||
128 | exit $code; | ||
129 | } | ||
121 | } | 130 | } |
122 | 131 | ||
123 | # nagios_die( $message, [ $code ]) OR nagios_die( $code, $message ) | 132 | # nagios_die( $message, [ $code ]) OR nagios_die( $code, $message ) |
@@ -297,7 +306,8 @@ form "PLUGIN CODE - $message". | |||
297 | =item nagios_die( $message, [CODE] ) | 306 | =item nagios_die( $message, [CODE] ) |
298 | 307 | ||
299 | Same as nagios_exit(), except that CODE is optional, defaulting | 308 | Same as nagios_exit(), except that CODE is optional, defaulting |
300 | to UNKNOWN. | 309 | to UNKNOWN. NOTE: exceptions are not raised by default to calling code. |
310 | Set C<$_use_die> flag if this functionality is required (see test code). | ||
301 | 311 | ||
302 | =item check_messages( critical => \@crit, warning => \@warn ) | 312 | =item check_messages( critical => \@crit, warning => \@warn ) |
303 | 313 | ||
diff --git a/lib/Nagios/Plugin/Threshold.pm b/lib/Nagios/Plugin/Threshold.pm index ad58134..145b89f 100644 --- a/lib/Nagios/Plugin/Threshold.pm +++ b/lib/Nagios/Plugin/Threshold.pm | |||
@@ -40,8 +40,8 @@ sub _inflate | |||
40 | } | 40 | } |
41 | 41 | ||
42 | # Otherwise parse $value | 42 | # Otherwise parse $value |
43 | my $range = Nagios::Plugin::Range->parse_range_string($value) | 43 | my $range = Nagios::Plugin::Range->parse_range_string($value); |
44 | or nagios_die("Cannot parse $key range: '$value'"); | 44 | nagios_die("Cannot parse $key range: '$value'") unless(defined($range)); |
45 | return $range; | 45 | return $range; |
46 | } | 46 | } |
47 | 47 | ||