diff options
author | Ton Voon <tonvoon@users.sourceforge.net> | 2006-08-04 20:22:31 +0000 |
---|---|---|
committer | Ton Voon <tonvoon@users.sourceforge.net> | 2006-08-04 20:22:31 +0000 |
commit | 96933fd2e1f53aff9c9ef26639fafe9a84ec754e (patch) | |
tree | 307d23df452b83c4d6799303379e208c7adb6317 /lib/Nagios/Plugin/Base.pm | |
parent | c0f29b373c0339eec73e325fb15ebef6dd24d230 (diff) | |
download | monitoring-plugin-perl-96933fd2e1f53aff9c9ef26639fafe9a84ec754e.tar.gz |
Lots of extra tests and subsequent fixes (Nathan Vonnahme)
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/Nagios-Plugin/trunk@1466 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'lib/Nagios/Plugin/Base.pm')
-rw-r--r-- | lib/Nagios/Plugin/Base.pm | 45 |
1 files changed, 29 insertions, 16 deletions
diff --git a/lib/Nagios/Plugin/Base.pm b/lib/Nagios/Plugin/Base.pm index f3a7f7c..d1678a5 100644 --- a/lib/Nagios/Plugin/Base.pm +++ b/lib/Nagios/Plugin/Base.pm | |||
@@ -5,6 +5,9 @@ package Nagios::Plugin::Base; | |||
5 | use strict; | 5 | use strict; |
6 | use warnings; | 6 | use warnings; |
7 | 7 | ||
8 | use Nagios::Plugin; | ||
9 | our ($VERSION) = $Nagios::Plugin::VERSION; | ||
10 | |||
8 | use Exporter; | 11 | use Exporter; |
9 | our @ISA = qw(Exporter); | 12 | our @ISA = qw(Exporter); |
10 | our @EXPORT = qw(%ERRORS); | 13 | our @EXPORT = qw(%ERRORS); |
@@ -13,28 +16,38 @@ our %ERRORS=('OK'=>0,'WARNING'=>1,'CRITICAL'=>2,'UNKNOWN'=>3,'DEPENDENT'=>4); | |||
13 | 16 | ||
14 | our %STATUS_TEXT = reverse %ERRORS; | 17 | our %STATUS_TEXT = reverse %ERRORS; |
15 | 18 | ||
19 | |||
16 | my $exit_on_die = 1; | 20 | my $exit_on_die = 1; |
17 | sub exit_on_die { shift; @_ ? $exit_on_die = shift : $exit_on_die }; | 21 | sub exit_on_die { shift; @_ ? $exit_on_die = shift : $exit_on_die }; |
18 | my $print_on_die = 1; | 22 | my $print_on_die = 1; |
19 | sub print_on_die { shift; @_ ? $print_on_die = shift : $print_on_die }; | 23 | sub print_on_die { shift; @_ ? $print_on_die = shift : $print_on_die }; |
20 | 24 | ||
21 | sub die { | 25 | sub die { |
22 | my ($class, $args, $plugin) = @_; | 26 | my ($class, $args, $plugin) = @_; |
23 | my $return_code = $args->{return_code} || 3; | 27 | my $return_code; |
24 | my $message = $args->{message} || "Internal error"; | 28 | |
25 | my $output = join(" ", $STATUS_TEXT{$return_code}, $message); | 29 | if ( exists $args->{return_code} |
26 | if ($plugin) { | 30 | && exists $STATUS_TEXT{$args->{return_code}} |
27 | $output = $plugin->shortname." $output" if $plugin->shortname; | 31 | ) { |
28 | $output .= " | ".$plugin->all_perfoutput if $plugin->perfdata; | 32 | $return_code = $args->{return_code}; |
29 | } | 33 | } |
30 | if ($print_on_die) { | 34 | else { |
31 | print $output, $/; | 35 | $return_code = $ERRORS{UNKNOWN}; |
32 | } | 36 | } |
33 | if ($exit_on_die) { | 37 | my $message = $args->{message} || "Internal error"; |
34 | exit $return_code; | 38 | my $output = join(" ", $STATUS_TEXT{$return_code}, $message); |
35 | } else { | 39 | if ($plugin) { |
36 | return $output; | 40 | $output = $plugin->shortname." $output" if $plugin->shortname; |
37 | } | 41 | $output .= " | ".$plugin->all_perfoutput if $plugin->perfdata; |
42 | } | ||
43 | if ($print_on_die) { | ||
44 | print $output, $/; | ||
45 | } | ||
46 | if ($exit_on_die) { | ||
47 | exit $return_code; | ||
48 | } else { | ||
49 | return $output; | ||
50 | } | ||
38 | } | 51 | } |
39 | 52 | ||
40 | 1; | 53 | 1; |