summaryrefslogtreecommitdiffstats
path: root/lib/Nagios/Plugin
diff options
context:
space:
mode:
authorTon Voon <tonvoon@users.sourceforge.net>2007-08-31 13:21:10 +0000
committerTon Voon <tonvoon@users.sourceforge.net>2007-08-31 13:21:10 +0000
commit95dba9c4213c2e7e8f4b572efd873c1979406221 (patch)
treec39a8dc0022ae98b09bfe5fa75f2dc67b3c97a69 /lib/Nagios/Plugin
parent4421aa3c2a695335cad006f32ece6c9c5da11165 (diff)
downloadmonitoring-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/Plugin')
-rw-r--r--lib/Nagios/Plugin/Functions.pm18
-rw-r--r--lib/Nagios/Plugin/Threshold.pm4
2 files changed, 16 insertions, 6 deletions
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;
46my $_fake_exit = 0; 46my $_fake_exit = 0;
47sub _fake_exit { @_ ? $_fake_exit = shift : $_fake_exit }; 47sub _fake_exit { @_ ? $_fake_exit = shift : $_fake_exit };
48 48
49# _use_die flag and accessor/mutator, so exceptions can be raised correctly
50my $_use_die = 0;
51sub _use_die { @_ ? $_use_die = shift : $_use_die };
52
49sub get_shortname { 53sub 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
299Same as nagios_exit(), except that CODE is optional, defaulting 308Same as nagios_exit(), except that CODE is optional, defaulting
300to UNKNOWN. 309to UNKNOWN. NOTE: exceptions are not raised by default to calling code.
310Set 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