summaryrefslogtreecommitdiffstats
path: root/web/attachments/352097-0001-move-nagios_die-out-of-N-P-Thresholds.patch
blob: 449cdd90f495415217e287d0cefce5f909179fe8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
From c1f379dbeb62b56530a25319690977385ce6766f Mon Sep 17 00:00:00 2001
From: Danijel Tasov <dt@korn.shell.la>
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 <dt@korn.shell.la>
---
 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