line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Nagios::Monitoring::Plugin::Threshold; |
2
|
|
|
|
|
|
|
|
3
|
5
|
|
|
5
|
|
20652
|
use 5.006; |
|
5
|
|
|
|
|
16
|
|
4
|
|
|
|
|
|
|
|
5
|
5
|
|
|
5
|
|
26
|
use strict; |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
112
|
|
6
|
5
|
|
|
5
|
|
26
|
use warnings; |
|
5
|
|
|
|
|
17
|
|
|
5
|
|
|
|
|
202
|
|
7
|
|
|
|
|
|
|
|
8
|
5
|
|
|
5
|
|
22
|
use base qw(Class::Accessor::Fast); |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
1342
|
|
9
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors(qw(warning critical)); |
10
|
|
|
|
|
|
|
|
11
|
5
|
|
|
5
|
|
7542
|
use Nagios::Monitoring::Plugin::Range; |
|
5
|
|
|
|
|
15
|
|
|
5
|
|
|
|
|
55
|
|
12
|
5
|
|
|
5
|
|
173
|
use Nagios::Monitoring::Plugin::Functions qw(:codes nagios_die); |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
3013
|
|
13
|
|
|
|
|
|
|
our ($VERSION) = $Nagios::Monitoring::Plugin::Functions::VERSION; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub get_status |
16
|
|
|
|
|
|
|
{ |
17
|
68
|
|
|
68
|
0
|
7093
|
my ($self, $value) = @_; |
18
|
|
|
|
|
|
|
|
19
|
68
|
100
|
|
|
|
222
|
$value = [ $value ] if (ref $value eq ""); |
20
|
68
|
|
|
|
|
127
|
foreach my $v (@$value) { |
21
|
76
|
100
|
|
|
|
202
|
if ($self->critical->is_set) { |
22
|
64
|
100
|
|
|
|
480
|
return CRITICAL if $self->critical->check_range($v); |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
} |
25
|
49
|
|
|
|
|
142
|
foreach my $v (@$value) { |
26
|
50
|
100
|
|
|
|
121
|
if ($self->warning->is_set) { |
27
|
42
|
100
|
|
|
|
294
|
return WARNING if $self->warning->check_range($v); |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
} |
30
|
26
|
|
|
|
|
182
|
return OK; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub _inflate |
34
|
|
|
|
|
|
|
{ |
35
|
224
|
|
|
224
|
|
397
|
my ($self, $value, $key) = @_; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
# Return an undefined range if $value is undef |
38
|
224
|
100
|
|
|
|
507
|
return Nagios::Monitoring::Plugin::Range->new if ! defined $value; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
# For refs, check isa N::P::Range |
41
|
193
|
100
|
|
|
|
345
|
if (ref $value) { |
42
|
3
|
50
|
|
|
|
15
|
nagios_die("Invalid $key object: type " . ref $value) |
43
|
|
|
|
|
|
|
unless $value->isa("Nagios::Monitoring::Plugin::Range"); |
44
|
3
|
|
|
|
|
11
|
return $value; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
# Another quick exit if $value is an empty string |
48
|
190
|
100
|
|
|
|
378
|
return Nagios::Monitoring::Plugin::Range->new if $value eq ""; |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
# Otherwise parse $value |
51
|
184
|
|
|
|
|
529
|
my $range = Nagios::Monitoring::Plugin::Range->parse_range_string($value); |
52
|
184
|
50
|
|
|
|
443
|
nagios_die("Cannot parse $key range: '$value'") unless(defined($range)); |
53
|
184
|
|
|
|
|
776
|
return $range; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub set_thresholds |
57
|
|
|
|
|
|
|
{ |
58
|
112
|
|
|
112
|
0
|
955
|
my ($self, %arg) = @_; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
# Equals new() as a class method |
61
|
112
|
100
|
|
|
|
478
|
return $self->new(%arg) unless ref $self; |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
# On an object, just acts as special mutator |
64
|
2
|
|
|
|
|
7
|
$self->set($_, $arg{$_}) foreach qw(warning critical); |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub set |
68
|
|
|
|
|
|
|
{ |
69
|
4
|
|
|
4
|
1
|
23
|
my $self = shift; |
70
|
4
|
|
|
|
|
5
|
my ($key, $value) = @_; |
71
|
4
|
|
|
|
|
9
|
$self->SUPER::set($key, $self->_inflate($value, $key)); |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
# Constructor - inflate scalars to N::P::Range objects |
75
|
|
|
|
|
|
|
sub new |
76
|
|
|
|
|
|
|
{ |
77
|
110
|
|
|
110
|
1
|
258
|
my ($self, %arg) = @_; |
78
|
|
|
|
|
|
|
$self->SUPER::new({ |
79
|
110
|
|
|
|
|
187
|
map { $_ => $self->_inflate($arg{$_}, $_) } qw(warning critical) |
|
220
|
|
|
|
|
689
|
|
80
|
|
|
|
|
|
|
}); |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
1; |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
__END__ |