From c1f379dbeb62b56530a25319690977385ce6766f Mon Sep 17 00:00:00 2001 From: Danijel Tasov Date: Sun, 22 Nov 2009 14:25:33 +0100 Subject: [PATCH] move nagios_die out of N::P::Thresholds. N::P::Thresholds uses nagios_die. This is suboptimal for using that Class in other Projects. Though one can set N::P::F::_use_die, but then $@ contains get_shortname and a STATUS_TEXT, which feels odd. Signed-off-by: Danijel Tasov --- lib/Nagios/Plugin.pm | 7 ++++++- lib/Nagios/Plugin/Threshold.pm | 7 ++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/Nagios/Plugin.pm b/lib/Nagios/Plugin.pm index 697005a..958d617 100644 --- a/lib/Nagios/Plugin.pm +++ b/lib/Nagios/Plugin.pm @@ -83,7 +83,12 @@ sub all_perfoutput { sub set_thresholds { my $self = shift; require Nagios::Plugin::Threshold; - return $self->threshold( Nagios::Plugin::Threshold->set_thresholds(@_)); + eval { + $self->threshold( Nagios::Plugin::Threshold->set_thresholds(@_)); + }; if($@) { + $self->nagios_die($@); + } + return $self->threshold; } # NP::Functions wrappers diff --git a/lib/Nagios/Plugin/Threshold.pm b/lib/Nagios/Plugin/Threshold.pm index 73fce53..e481cd4 100644 --- a/lib/Nagios/Plugin/Threshold.pm +++ b/lib/Nagios/Plugin/Threshold.pm @@ -9,7 +9,8 @@ use base qw(Class::Accessor::Fast); __PACKAGE__->mk_accessors(qw(warning critical)); use Nagios::Plugin::Range; -use Nagios::Plugin::Functions qw(:codes nagios_die); +use Nagios::Plugin::Functions qw(:codes); +use Carp; our ($VERSION) = $Nagios::Plugin::Functions::VERSION; sub get_status @@ -34,7 +35,7 @@ sub _inflate # For refs, check isa N::P::Range if (ref $value) { - nagios_die("Invalid $key object: type " . ref $value) + croak("Invalid $key object: type " . ref $value) unless $value->isa("Nagios::Plugin::Range"); return $value; } @@ -44,7 +45,7 @@ sub _inflate # Otherwise parse $value my $range = Nagios::Plugin::Range->parse_range_string($value); - nagios_die("Cannot parse $key range: '$value'") unless(defined($range)); + croak("Cannot parse $key range: '$value'") unless(defined($range)); return $range; } -- 1.6.5.2.10.g754571