summaryrefslogtreecommitdiffstats
path: root/lib/Nagios/Plugin/Functions.pm
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/Functions.pm
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/Functions.pm')
-rw-r--r--lib/Nagios/Plugin/Functions.pm18
1 files changed, 14 insertions, 4 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