line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Monitoring::Plugin::Threshold; |
2
|
|
|
|
|
|
|
|
3
|
6
|
|
|
6
|
|
13398
|
use 5.006; |
|
6
|
|
|
|
|
12
|
|
|
6
|
|
|
|
|
164
|
|
4
|
6
|
|
|
6
|
|
17
|
use strict; |
|
6
|
|
|
|
|
6
|
|
|
6
|
|
|
|
|
139
|
|
5
|
6
|
|
|
6
|
|
17
|
use warnings; |
|
6
|
|
|
|
|
6
|
|
|
6
|
|
|
|
|
146
|
|
6
|
|
|
|
|
|
|
|
7
|
6
|
|
|
6
|
|
20
|
use base qw(Class::Accessor::Fast); |
|
6
|
|
|
|
|
9
|
|
|
6
|
|
|
|
|
803
|
|
8
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors(qw(warning critical)); |
9
|
|
|
|
|
|
|
|
10
|
6
|
|
|
6
|
|
3978
|
use Monitoring::Plugin::Range; |
|
6
|
|
|
|
|
9
|
|
|
6
|
|
|
|
|
41
|
|
11
|
6
|
|
|
6
|
|
154
|
use Monitoring::Plugin::Functions qw(:codes plugin_die); |
|
6
|
|
|
|
|
5
|
|
|
6
|
|
|
|
|
2260
|
|
12
|
|
|
|
|
|
|
our ($VERSION) = $Monitoring::Plugin::Functions::VERSION; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub get_status |
15
|
|
|
|
|
|
|
{ |
16
|
68
|
|
|
68
|
0
|
4456
|
my ($self, $value) = @_; |
17
|
|
|
|
|
|
|
|
18
|
68
|
100
|
|
|
|
164
|
$value = [ $value ] if (ref $value eq ""); |
19
|
68
|
|
|
|
|
80
|
foreach my $v (@$value) { |
20
|
76
|
100
|
|
|
|
125
|
if ($self->critical->is_set) { |
21
|
64
|
100
|
|
|
|
290
|
return CRITICAL if $self->critical->check_range($v); |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
} |
24
|
49
|
|
|
|
|
102
|
foreach my $v (@$value) { |
25
|
50
|
100
|
|
|
|
78
|
if ($self->warning->is_set) { |
26
|
42
|
100
|
|
|
|
169
|
return WARNING if $self->warning->check_range($v); |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
} |
29
|
26
|
|
|
|
|
123
|
return OK; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub _inflate |
33
|
|
|
|
|
|
|
{ |
34
|
224
|
|
|
224
|
|
201
|
my ($self, $value, $key) = @_; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
# Return an undefined range if $value is undef |
37
|
224
|
100
|
|
|
|
314
|
return Monitoring::Plugin::Range->new if ! defined $value; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
# For refs, check isa N::P::Range |
40
|
193
|
100
|
|
|
|
216
|
if (ref $value) { |
41
|
3
|
50
|
|
|
|
13
|
plugin_die("Invalid $key object: type " . ref $value) |
42
|
|
|
|
|
|
|
unless $value->isa("Monitoring::Plugin::Range"); |
43
|
3
|
|
|
|
|
8
|
return $value; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
# Another quick exit if $value is an empty string |
47
|
190
|
100
|
|
|
|
232
|
return Monitoring::Plugin::Range->new if $value eq ""; |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
# Otherwise parse $value |
50
|
184
|
|
|
|
|
337
|
my $range = Monitoring::Plugin::Range->parse_range_string($value); |
51
|
184
|
50
|
|
|
|
239
|
plugin_die("Cannot parse $key range: '$value'") unless(defined($range)); |
52
|
184
|
|
|
|
|
479
|
return $range; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub set_thresholds |
56
|
|
|
|
|
|
|
{ |
57
|
112
|
|
|
112
|
0
|
604
|
my ($self, %arg) = @_; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
# Equals new() as a class method |
60
|
112
|
100
|
|
|
|
325
|
return $self->new(%arg) unless ref $self; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
# On an object, just acts as special mutator |
63
|
2
|
|
|
|
|
6
|
$self->set($_, $arg{$_}) foreach qw(warning critical); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub set |
67
|
|
|
|
|
|
|
{ |
68
|
4
|
|
|
4
|
1
|
16
|
my $self = shift; |
69
|
4
|
|
|
|
|
4
|
my ($key, $value) = @_; |
70
|
4
|
|
|
|
|
6
|
$self->SUPER::set($key, $self->_inflate($value, $key)); |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
# Constructor - inflate scalars to N::P::Range objects |
74
|
|
|
|
|
|
|
sub new |
75
|
|
|
|
|
|
|
{ |
76
|
110
|
|
|
110
|
1
|
128
|
my ($self, %arg) = @_; |
77
|
220
|
|
|
|
|
416
|
$self->SUPER::new({ |
78
|
110
|
|
|
|
|
116
|
map { $_ => $self->_inflate($arg{$_}, $_) } qw(warning critical) |
79
|
|
|
|
|
|
|
}); |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
1; |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
__END__ |