summaryrefslogtreecommitdiffstats
path: root/lib/Nagios/Plugin/Base.pm
diff options
context:
space:
mode:
authorTon Voon <tonvoon@users.sourceforge.net>2006-08-04 20:22:31 +0000
committerTon Voon <tonvoon@users.sourceforge.net>2006-08-04 20:22:31 +0000
commit96933fd2e1f53aff9c9ef26639fafe9a84ec754e (patch)
tree307d23df452b83c4d6799303379e208c7adb6317 /lib/Nagios/Plugin/Base.pm
parentc0f29b373c0339eec73e325fb15ebef6dd24d230 (diff)
downloadmonitoring-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.pm45
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;
5use strict; 5use strict;
6use warnings; 6use warnings;
7 7
8use Nagios::Plugin;
9our ($VERSION) = $Nagios::Plugin::VERSION;
10
8use Exporter; 11use Exporter;
9our @ISA = qw(Exporter); 12our @ISA = qw(Exporter);
10our @EXPORT = qw(%ERRORS); 13our @EXPORT = qw(%ERRORS);
@@ -13,28 +16,38 @@ our %ERRORS=('OK'=>0,'WARNING'=>1,'CRITICAL'=>2,'UNKNOWN'=>3,'DEPENDENT'=>4);
13 16
14our %STATUS_TEXT = reverse %ERRORS; 17our %STATUS_TEXT = reverse %ERRORS;
15 18
19
16my $exit_on_die = 1; 20my $exit_on_die = 1;
17sub exit_on_die { shift; @_ ? $exit_on_die = shift : $exit_on_die }; 21sub exit_on_die { shift; @_ ? $exit_on_die = shift : $exit_on_die };
18my $print_on_die = 1; 22my $print_on_die = 1;
19sub print_on_die { shift; @_ ? $print_on_die = shift : $print_on_die }; 23sub print_on_die { shift; @_ ? $print_on_die = shift : $print_on_die };
20 24
21sub die { 25sub 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
401; 531;