line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Monitoring::Plugin::Threshold; |
2
|
|
|
|
|
|
|
|
3
|
6
|
|
|
6
|
|
18958
|
use 5.006; |
|
6
|
|
|
|
|
18
|
|
|
6
|
|
|
|
|
231
|
|
4
|
6
|
|
|
6
|
|
27
|
use strict; |
|
6
|
|
|
|
|
8
|
|
|
6
|
|
|
|
|
217
|
|
5
|
6
|
|
|
6
|
|
28
|
use warnings; |
|
6
|
|
|
|
|
7
|
|
|
6
|
|
|
|
|
196
|
|
6
|
|
|
|
|
|
|
|
7
|
6
|
|
|
6
|
|
27
|
use base qw(Class::Accessor::Fast); |
|
6
|
|
|
|
|
12
|
|
|
6
|
|
|
|
|
1150
|
|
8
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors(qw(warning critical)); |
9
|
|
|
|
|
|
|
|
10
|
6
|
|
|
6
|
|
5543
|
use Monitoring::Plugin::Range; |
|
6
|
|
|
|
|
14
|
|
|
6
|
|
|
|
|
65
|
|
11
|
6
|
|
|
6
|
|
219
|
use Monitoring::Plugin::Functions qw(:codes plugin_die); |
|
6
|
|
|
|
|
8
|
|
|
6
|
|
|
|
|
3406
|
|
12
|
|
|
|
|
|
|
our ($VERSION) = $Monitoring::Plugin::Functions::VERSION; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub get_status |
15
|
|
|
|
|
|
|
{ |
16
|
68
|
|
|
68
|
0
|
7705
|
my ($self, $value) = @_; |
17
|
|
|
|
|
|
|
|
18
|
68
|
100
|
|
|
|
244
|
$value = [ $value ] if (ref $value eq ""); |
19
|
68
|
|
|
|
|
124
|
foreach my $v (@$value) { |
20
|
76
|
100
|
|
|
|
180
|
if ($self->critical->is_set) { |
21
|
64
|
100
|
|
|
|
459
|
return CRITICAL if $self->critical->check_range($v); |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
} |
24
|
49
|
|
|
|
|
151
|
foreach my $v (@$value) { |
25
|
50
|
100
|
|
|
|
103
|
if ($self->warning->is_set) { |
26
|
42
|
100
|
|
|
|
255
|
return WARNING if $self->warning->check_range($v); |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
} |
29
|
26
|
|
|
|
|
206
|
return OK; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub _inflate |
33
|
|
|
|
|
|
|
{ |
34
|
224
|
|
|
224
|
|
248
|
my ($self, $value, $key) = @_; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
# Return an undefined range if $value is undef |
37
|
224
|
100
|
|
|
|
418
|
return Monitoring::Plugin::Range->new if ! defined $value; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
# For refs, check isa N::P::Range |
40
|
193
|
100
|
|
|
|
291
|
if (ref $value) { |
41
|
3
|
50
|
|
|
|
22
|
plugin_die("Invalid $key object: type " . ref $value) |
42
|
|
|
|
|
|
|
unless $value->isa("Monitoring::Plugin::Range"); |
43
|
3
|
|
|
|
|
15
|
return $value; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
# Another quick exit if $value is an empty string |
47
|
190
|
100
|
|
|
|
345
|
return Monitoring::Plugin::Range->new if $value eq ""; |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
# Otherwise parse $value |
50
|
184
|
|
|
|
|
436
|
my $range = Monitoring::Plugin::Range->parse_range_string($value); |
51
|
184
|
50
|
|
|
|
349
|
plugin_die("Cannot parse $key range: '$value'") unless(defined($range)); |
52
|
184
|
|
|
|
|
622
|
return $range; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub set_thresholds |
56
|
|
|
|
|
|
|
{ |
57
|
112
|
|
|
112
|
0
|
782
|
my ($self, %arg) = @_; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
# Equals new() as a class method |
60
|
112
|
100
|
|
|
|
425
|
return $self->new(%arg) unless ref $self; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
# On an object, just acts as special mutator |
63
|
2
|
|
|
|
|
14
|
$self->set($_, $arg{$_}) foreach qw(warning critical); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub set |
67
|
|
|
|
|
|
|
{ |
68
|
4
|
|
|
4
|
1
|
30
|
my $self = shift; |
69
|
4
|
|
|
|
|
8
|
my ($key, $value) = @_; |
70
|
4
|
|
|
|
|
12
|
$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
|
194
|
my ($self, %arg) = @_; |
77
|
220
|
|
|
|
|
570
|
$self->SUPER::new({ |
78
|
110
|
|
|
|
|
146
|
map { $_ => $self->_inflate($arg{$_}, $_) } qw(warning critical) |
79
|
|
|
|
|
|
|
}); |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
1; |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
__END__ |