From 96933fd2e1f53aff9c9ef26639fafe9a84ec754e Mon Sep 17 00:00:00 2001 From: Ton Voon Date: Fri, 4 Aug 2006 20:22:31 +0000 Subject: 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 --- lib/Nagios/Plugin/Base.pm | 45 +++++++++++++++++++++++++++++---------------- 1 file changed, 29 insertions(+), 16 deletions(-) (limited to 'lib/Nagios/Plugin/Base.pm') 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; use strict; use warnings; +use Nagios::Plugin; +our ($VERSION) = $Nagios::Plugin::VERSION; + use Exporter; our @ISA = qw(Exporter); our @EXPORT = qw(%ERRORS); @@ -13,28 +16,38 @@ our %ERRORS=('OK'=>0,'WARNING'=>1,'CRITICAL'=>2,'UNKNOWN'=>3,'DEPENDENT'=>4); our %STATUS_TEXT = reverse %ERRORS; + my $exit_on_die = 1; sub exit_on_die { shift; @_ ? $exit_on_die = shift : $exit_on_die }; my $print_on_die = 1; sub print_on_die { shift; @_ ? $print_on_die = shift : $print_on_die }; sub die { - my ($class, $args, $plugin) = @_; - my $return_code = $args->{return_code} || 3; - my $message = $args->{message} || "Internal error"; - my $output = join(" ", $STATUS_TEXT{$return_code}, $message); - if ($plugin) { - $output = $plugin->shortname." $output" if $plugin->shortname; - $output .= " | ".$plugin->all_perfoutput if $plugin->perfdata; - } - if ($print_on_die) { - print $output, $/; - } - if ($exit_on_die) { - exit $return_code; - } else { - return $output; - } + my ($class, $args, $plugin) = @_; + my $return_code; + + if ( exists $args->{return_code} + && exists $STATUS_TEXT{$args->{return_code}} + ) { + $return_code = $args->{return_code}; + } + else { + $return_code = $ERRORS{UNKNOWN}; + } + my $message = $args->{message} || "Internal error"; + my $output = join(" ", $STATUS_TEXT{$return_code}, $message); + if ($plugin) { + $output = $plugin->shortname." $output" if $plugin->shortname; + $output .= " | ".$plugin->all_perfoutput if $plugin->perfdata; + } + if ($print_on_die) { + print $output, $/; + } + if ($exit_on_die) { + exit $return_code; + } else { + return $output; + } } 1; -- cgit v1.2.3-74-g34f1