summaryrefslogtreecommitdiffstats
path: root/lib/Nagios/Plugin/Functions.pm
diff options
context:
space:
mode:
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