diff options
author | Sven Nierlein <sven@nierlein.de> | 2014-01-20 00:54:34 +0100 |
---|---|---|
committer | Sven Nierlein <sven@nierlein.de> | 2014-01-20 00:54:34 +0100 |
commit | b418181dfe80dd75169b6e8a619ac1932155dea2 (patch) | |
tree | cad9c0ae0eae8e800cfff60555ead06ad33c6856 /lib/Nagios/Plugin/Threshold.pm | |
parent | 1cd8d1c52cbd47121f344c4074aec84653f412ce (diff) | |
download | monitoring-plugin-perl-b418181dfe80dd75169b6e8a619ac1932155dea2.tar.gz |
renamed module into Monitoring::Plugin
since the complete monitoring team has been renamed, we
also rename this module.
Signed-off-by: Sven Nierlein <sven@nierlein.de>
Diffstat (limited to 'lib/Nagios/Plugin/Threshold.pm')
-rw-r--r-- | lib/Nagios/Plugin/Threshold.pm | 134 |
1 files changed, 0 insertions, 134 deletions
diff --git a/lib/Nagios/Plugin/Threshold.pm b/lib/Nagios/Plugin/Threshold.pm deleted file mode 100644 index 95a089b..0000000 --- a/lib/Nagios/Plugin/Threshold.pm +++ /dev/null | |||
@@ -1,134 +0,0 @@ | |||
1 | package Nagios::Plugin::Threshold; | ||
2 | |||
3 | use 5.006; | ||
4 | |||
5 | use strict; | ||
6 | use warnings; | ||
7 | |||
8 | use base qw(Class::Accessor::Fast); | ||
9 | __PACKAGE__->mk_accessors(qw(warning critical)); | ||
10 | |||
11 | use Nagios::Plugin::Range; | ||
12 | use Nagios::Plugin::Functions qw(:codes nagios_die); | ||
13 | our ($VERSION) = $Nagios::Plugin::Functions::VERSION; | ||
14 | |||
15 | sub get_status | ||
16 | { | ||
17 | my ($self, $value) = @_; | ||
18 | |||
19 | $value = [ $value ] if (ref $value eq ""); | ||
20 | foreach my $v (@$value) { | ||
21 | if ($self->critical->is_set) { | ||
22 | return CRITICAL if $self->critical->check_range($v); | ||
23 | } | ||
24 | } | ||
25 | foreach my $v (@$value) { | ||
26 | if ($self->warning->is_set) { | ||
27 | return WARNING if $self->warning->check_range($v); | ||
28 | } | ||
29 | } | ||
30 | return OK; | ||
31 | } | ||
32 | |||
33 | sub _inflate | ||
34 | { | ||
35 | my ($self, $value, $key) = @_; | ||
36 | |||
37 | # Return an undefined range if $value is undef | ||
38 | return Nagios::Plugin::Range->new if ! defined $value; | ||
39 | |||
40 | # For refs, check isa N::P::Range | ||
41 | if (ref $value) { | ||
42 | nagios_die("Invalid $key object: type " . ref $value) | ||
43 | unless $value->isa("Nagios::Plugin::Range"); | ||
44 | return $value; | ||
45 | } | ||
46 | |||
47 | # Another quick exit if $value is an empty string | ||
48 | return Nagios::Plugin::Range->new if $value eq ""; | ||
49 | |||
50 | # Otherwise parse $value | ||
51 | my $range = Nagios::Plugin::Range->parse_range_string($value); | ||
52 | nagios_die("Cannot parse $key range: '$value'") unless(defined($range)); | ||
53 | return $range; | ||
54 | } | ||
55 | |||
56 | sub set_thresholds | ||
57 | { | ||
58 | my ($self, %arg) = @_; | ||
59 | |||
60 | # Equals new() as a class method | ||
61 | return $self->new(%arg) unless ref $self; | ||
62 | |||
63 | # On an object, just acts as special mutator | ||
64 | $self->set($_, $arg{$_}) foreach qw(warning critical); | ||
65 | } | ||
66 | |||
67 | sub set | ||
68 | { | ||
69 | my $self = shift; | ||
70 | my ($key, $value) = @_; | ||
71 | $self->SUPER::set($key, $self->_inflate($value, $key)); | ||
72 | } | ||
73 | |||
74 | # Constructor - inflate scalars to N::P::Range objects | ||
75 | sub new | ||
76 | { | ||
77 | my ($self, %arg) = @_; | ||
78 | $self->SUPER::new({ | ||
79 | map { $_ => $self->_inflate($arg{$_}, $_) } qw(warning critical) | ||
80 | }); | ||
81 | } | ||
82 | |||
83 | 1; | ||
84 | |||
85 | __END__ | ||
86 | |||
87 | =head1 NAME | ||
88 | |||
89 | Nagios::Plugin::Threshold - class for handling Nagios::Plugin thresholds. | ||
90 | |||
91 | =head1 SYNOPSIS | ||
92 | |||
93 | # NB: This is an internal Nagios::Plugin class. | ||
94 | # See Nagios::Plugin itself for public interfaces. | ||
95 | |||
96 | # Constructor | ||
97 | $t = Nagios::Plugin::Threshold->set_thresholds( | ||
98 | warning => $warning_range_string, | ||
99 | critical => $critical_range_string, | ||
100 | ); | ||
101 | |||
102 | # Value checking - returns CRITICAL if in the critical range, | ||
103 | # WARNING if in the warning range, and OK otherwise | ||
104 | $status = $t->get_status($value); | ||
105 | |||
106 | # Accessors - return the associated N::P::Range object | ||
107 | $warning_range = $t->warning; | ||
108 | $critical_range = $t->critical; | ||
109 | |||
110 | |||
111 | =head1 DESCRIPTION | ||
112 | |||
113 | Internal Nagios::Plugin class for handling threshold data. See | ||
114 | Nagios::Plugin for public interfaces. | ||
115 | |||
116 | A threshold object contains (typically) a pair of ranges, associated | ||
117 | with a particular severity e.g. | ||
118 | |||
119 | warning => range1 | ||
120 | critical => range2 | ||
121 | |||
122 | =head1 AUTHOR | ||
123 | |||
124 | This code is maintained by the Nagios Plugin Development Team: see | ||
125 | http://nagiosplug.sourceforge.net. | ||
126 | |||
127 | =head1 COPYRIGHT AND LICENSE | ||
128 | |||
129 | Copyright (C) 2006-2007 Nagios Plugin Development Team | ||
130 | |||
131 | This library is free software; you can redistribute it and/or modify | ||
132 | it under the same terms as Perl itself. | ||
133 | |||
134 | =cut | ||