line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Monitoring::Plugin::Threshold; |
2
|
|
|
|
|
|
|
|
3
|
6
|
|
|
6
|
|
68268
|
use 5.006; |
|
6
|
|
|
|
|
24
|
|
4
|
6
|
|
|
6
|
|
32
|
use strict; |
|
6
|
|
|
|
|
10
|
|
|
6
|
|
|
|
|
123
|
|
5
|
6
|
|
|
6
|
|
25
|
use warnings; |
|
6
|
|
|
|
|
21
|
|
|
6
|
|
|
|
|
175
|
|
6
|
|
|
|
|
|
|
|
7
|
6
|
|
|
6
|
|
29
|
use base qw(Class::Accessor::Fast); |
|
6
|
|
|
|
|
8
|
|
|
6
|
|
|
|
|
950
|
|
8
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors(qw(warning critical)); |
9
|
|
|
|
|
|
|
|
10
|
6
|
|
|
6
|
|
4374
|
use Monitoring::Plugin::Range; |
|
6
|
|
|
|
|
12
|
|
|
6
|
|
|
|
|
34
|
|
11
|
6
|
|
|
6
|
|
186
|
use Monitoring::Plugin::Functions qw(:codes plugin_die); |
|
6
|
|
|
|
|
9
|
|
|
6
|
|
|
|
|
2613
|
|
12
|
|
|
|
|
|
|
our ($VERSION) = $Monitoring::Plugin::Functions::VERSION; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub get_status |
15
|
|
|
|
|
|
|
{ |
16
|
68
|
|
|
68
|
0
|
5909
|
my ($self, $value) = @_; |
17
|
|
|
|
|
|
|
|
18
|
68
|
100
|
|
|
|
175
|
$value = [ $value ] if (ref $value eq ""); |
19
|
68
|
|
|
|
|
90
|
foreach my $v (@$value) { |
20
|
76
|
100
|
|
|
|
1227
|
if ($self->critical->is_set) { |
21
|
64
|
100
|
|
|
|
1032
|
return CRITICAL if $self->critical->check_range($v); |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
} |
24
|
49
|
|
|
|
|
110
|
foreach my $v (@$value) { |
25
|
50
|
100
|
|
|
|
605
|
if ($self->warning->is_set) { |
26
|
42
|
100
|
|
|
|
606
|
return WARNING if $self->warning->check_range($v); |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
} |
29
|
26
|
|
|
|
|
167
|
return OK; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub _inflate |
33
|
|
|
|
|
|
|
{ |
34
|
224
|
|
|
224
|
|
343
|
my ($self, $value, $key) = @_; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
# Return an undefined range if $value is undef |
37
|
224
|
100
|
|
|
|
395
|
return Monitoring::Plugin::Range->new if ! defined $value; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
# For refs, check isa N::P::Range |
40
|
193
|
100
|
|
|
|
273
|
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
|
|
|
|
278
|
return Monitoring::Plugin::Range->new if $value eq ""; |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
# Otherwise parse $value |
50
|
184
|
|
|
|
|
374
|
my $range = Monitoring::Plugin::Range->parse_range_string($value); |
51
|
184
|
50
|
|
|
|
296
|
plugin_die("Cannot parse $key range: '$value'") unless(defined($range)); |
52
|
184
|
|
|
|
|
521
|
return $range; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub set_thresholds |
56
|
|
|
|
|
|
|
{ |
57
|
112
|
|
|
112
|
0
|
1736
|
my ($self, %arg) = @_; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
# Equals new() as a class method |
60
|
112
|
100
|
|
|
|
370
|
return $self->new(%arg) unless ref $self; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
# On an object, just acts as special mutator |
63
|
2
|
|
|
|
|
10
|
$self->set($_, $arg{$_}) foreach qw(warning critical); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub set |
67
|
|
|
|
|
|
|
{ |
68
|
4
|
|
|
4
|
1
|
18
|
my $self = shift; |
69
|
4
|
|
|
|
|
7
|
my ($key, $value) = @_; |
70
|
4
|
|
|
|
|
7
|
$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
|
196
|
my ($self, %arg) = @_; |
77
|
|
|
|
|
|
|
$self->SUPER::new({ |
78
|
110
|
|
|
|
|
153
|
map { $_ => $self->_inflate($arg{$_}, $_) } qw(warning critical) |
|
220
|
|
|
|
|
511
|
|
79
|
|
|
|
|
|
|
}); |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
1; |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
__END__ |