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.pm26
1 files changed, 18 insertions, 8 deletions
diff --git a/lib/Nagios/Plugin/Functions.pm b/lib/Nagios/Plugin/Functions.pm
index e6baca9..87f0ccd 100644
--- a/lib/Nagios/Plugin/Functions.pm
+++ b/lib/Nagios/Plugin/Functions.pm
@@ -8,7 +8,7 @@ use 5.006;
8use strict; 8use strict;
9use warnings; 9use warnings;
10use File::Basename; 10use File::Basename;
11use Params::Validate qw(validate :types); 11use Params::Validate qw(:types validate);
12use Math::Calc::Units; 12use Math::Calc::Units;
13 13
14# Remember to update Nagios::Plugins as well 14# Remember to update Nagios::Plugins as well
@@ -119,14 +119,24 @@ sub nagios_exit {
119 return Nagios::Plugin::ExitResult->new($code, $output); 119 return Nagios::Plugin::ExitResult->new($code, $output);
120 } 120 }
121 121
122 # Print output and exit; die if called via nagios_die and flag set 122 _nagios_exit($code, $output);
123 if($_use_die && (caller(1))[3] =~ m/die/) { 123}
124 $!=$code; 124
125 die($output); 125sub _nagios_exit {
126 } else { 126 my ($code, $output) = @_;
127 print $output; 127 # Print output and exit; die if flag set and called via a die in stack backtrace
128 exit $code; 128 if ($_use_die) {
129 for (my $i = 0;; $i++) {
130 @_ = caller($i);
131 last unless @_;
132 if ($_[3] =~ m/die/) {
133 $! = $code;
134 die($output);
135 }
136 }
129 } 137 }
138 print $output;
139 exit $code;
130} 140}
131 141
132# nagios_die( $message, [ $code ]) OR nagios_die( $code, $message ) 142# nagios_die( $message, [ $code ]) OR nagios_die( $code, $message )