diff options
Diffstat (limited to 'lib/Nagios/Plugin')
-rw-r--r-- | lib/Nagios/Plugin/Functions.pm | 26 | ||||
-rw-r--r-- | lib/Nagios/Plugin/Getopt.pm | 4 |
2 files changed, 19 insertions, 11 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; | |||
8 | use strict; | 8 | use strict; |
9 | use warnings; | 9 | use warnings; |
10 | use File::Basename; | 10 | use File::Basename; |
11 | use Params::Validate qw(validate :types); | 11 | use Params::Validate qw(:types validate); |
12 | use Math::Calc::Units; | 12 | use 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); | 125 | sub _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 ) |
diff --git a/lib/Nagios/Plugin/Getopt.pm b/lib/Nagios/Plugin/Getopt.pm index 743bf7e..b21dc6d 100644 --- a/lib/Nagios/Plugin/Getopt.pm +++ b/lib/Nagios/Plugin/Getopt.pm | |||
@@ -60,9 +60,7 @@ sub _die | |||
60 | my $self = shift; | 60 | my $self = shift; |
61 | my ($msg) = @_; | 61 | my ($msg) = @_; |
62 | $msg .= "\n" unless substr($msg, -1) eq "\n"; | 62 | $msg .= "\n" unless substr($msg, -1) eq "\n"; |
63 | # Set errno to UNKNOWN for die return code | 63 | Nagios::Plugin::Functions::_nagios_exit(3, $msg); |
64 | local $! = 3; | ||
65 | die $msg; | ||
66 | } | 64 | } |
67 | 65 | ||
68 | # Return the given attribute, if set, including a final newline | 66 | # Return the given attribute, if set, including a final newline |