line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Monitoring::Plugin::Range; |
2
|
|
|
|
|
|
|
|
3
|
7
|
|
|
7
|
|
13261
|
use 5.006; |
|
7
|
|
|
|
|
15
|
|
|
7
|
|
|
|
|
200
|
|
4
|
7
|
|
|
7
|
|
26
|
use strict; |
|
7
|
|
|
|
|
7
|
|
|
7
|
|
|
|
|
153
|
|
5
|
7
|
|
|
7
|
|
24
|
use warnings; |
|
7
|
|
|
|
|
8
|
|
|
7
|
|
|
|
|
124
|
|
6
|
|
|
|
|
|
|
|
7
|
7
|
|
|
7
|
|
21
|
use Carp; |
|
7
|
|
|
|
|
6
|
|
|
7
|
|
|
|
|
350
|
|
8
|
7
|
|
|
7
|
|
22
|
use base qw(Class::Accessor::Fast); |
|
7
|
|
|
|
|
7
|
|
|
7
|
|
|
|
|
773
|
|
9
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors( |
10
|
|
|
|
|
|
|
qw(start end start_infinity end_infinity alert_on) |
11
|
|
|
|
|
|
|
); |
12
|
|
|
|
|
|
|
|
13
|
7
|
|
|
7
|
|
2508
|
use Monitoring::Plugin::Functions qw(:DEFAULT $value_re); |
|
7
|
|
|
|
|
9
|
|
|
7
|
|
|
|
|
1301
|
|
14
|
|
|
|
|
|
|
our ($VERSION) = $Monitoring::Plugin::Functions::VERSION; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
use overload |
17
|
34
|
|
|
34
|
|
12452
|
'eq' => sub { shift->_stringify }, |
18
|
7
|
|
|
7
|
|
1769
|
'""' => sub { shift->_stringify }; |
|
7
|
|
|
17
|
|
1406
|
|
|
7
|
|
|
|
|
64
|
|
|
17
|
|
|
|
|
101
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
# alert_on constants (undef == range not set) |
21
|
7
|
|
|
7
|
|
341
|
use constant OUTSIDE => 0; |
|
7
|
|
|
|
|
8
|
|
|
7
|
|
|
|
|
291
|
|
22
|
7
|
|
|
7
|
|
21
|
use constant INSIDE => 1; |
|
7
|
|
|
|
|
7
|
|
|
7
|
|
|
|
|
3440
|
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub _stringify { |
25
|
51
|
|
|
51
|
|
42
|
my $self = shift; |
26
|
51
|
100
|
|
|
|
63
|
return "" unless $self->is_set; |
27
|
49
|
100
|
|
|
|
275
|
return (($self->alert_on) ? "@" : "") . |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
28
|
|
|
|
|
|
|
(($self->start_infinity == 1) ? "~:" : (($self->start == 0)?"":$self->start.":")) . |
29
|
|
|
|
|
|
|
(($self->end_infinity == 1) ? "" : $self->end); |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub is_set { |
33
|
221
|
|
|
221
|
0
|
2280
|
my $self = shift; |
34
|
221
|
100
|
|
|
|
338
|
(! defined $self->alert_on) ? 0 : 1; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub _set_range_start { |
38
|
40
|
|
|
40
|
|
40
|
my ($self, $value) = @_; |
39
|
40
|
|
|
|
|
100
|
$self->start($value+0); # Force scalar into number |
40
|
40
|
|
|
|
|
231
|
$self->start_infinity(0); |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub _set_range_end { |
44
|
189
|
|
|
189
|
|
185
|
my ($self, $value) = @_; |
45
|
189
|
|
|
|
|
386
|
$self->end($value+0); # Force scalar into number |
46
|
189
|
|
|
|
|
921
|
$self->end_infinity(0); |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
# Returns a N::P::Range object if the string is a conforms to a Monitoring Plugin range string, otherwise null |
50
|
|
|
|
|
|
|
sub parse_range_string { |
51
|
204
|
|
|
204
|
0
|
5320
|
my ($class, $string) = @_; |
52
|
204
|
|
|
|
|
135
|
my $valid = 0; |
53
|
204
|
|
|
|
|
293
|
my $range = $class->new( start => 0, start_infinity => 0, end => 0, end_infinity => 1, alert_on => OUTSIDE); |
54
|
|
|
|
|
|
|
|
55
|
204
|
|
|
|
|
1484
|
$string =~ s/\s//g; # strip out any whitespace |
56
|
|
|
|
|
|
|
# check for valid range definition |
57
|
204
|
100
|
100
|
|
|
1967
|
unless ( $string =~ /[\d~]/ && $string =~ m/^\@?($value_re|~)?(:($value_re)?)?$/ ) { |
58
|
7
|
|
|
|
|
831
|
carp "invalid range definition '$string'"; |
59
|
7
|
|
|
|
|
48
|
return undef; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
197
|
100
|
|
|
|
297
|
if ($string =~ s/^\@//) { |
63
|
2
|
|
|
|
|
5
|
$range->alert_on(INSIDE); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
197
|
100
|
|
|
|
245
|
if ($string =~ s/^~//) { # '~:x' |
67
|
12
|
|
|
|
|
22
|
$range->start_infinity(1); |
68
|
|
|
|
|
|
|
} |
69
|
197
|
100
|
|
|
|
662
|
if ( $string =~ m/^($value_re)?:/ ) { # '10:' |
70
|
53
|
|
|
|
|
78
|
my $start = $1; |
71
|
53
|
100
|
|
|
|
105
|
$range->_set_range_start($start) if defined $start; |
72
|
53
|
|
|
|
|
152
|
$range->end_infinity(1); # overridden below if there's an end specified |
73
|
53
|
|
|
|
|
481
|
$string =~ s/^($value_re)?://; |
74
|
53
|
|
|
|
|
65
|
$valid++; |
75
|
|
|
|
|
|
|
} |
76
|
197
|
100
|
|
|
|
631
|
if ($string =~ /^($value_re)$/) { # 'x:10' or '10' |
77
|
189
|
|
|
|
|
225
|
$range->_set_range_end($string); |
78
|
189
|
|
|
|
|
484
|
$valid++; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
197
|
100
|
100
|
|
|
429
|
if ($valid && ($range->start_infinity == 1 || $range->end_infinity == 1 || $range->start <= $range->end)) { |
|
|
|
33
|
|
|
|
|
82
|
196
|
|
|
|
|
2115
|
return $range; |
83
|
|
|
|
|
|
|
} |
84
|
1
|
|
|
|
|
14
|
return undef; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
# Returns 1 if an alert should be raised, otherwise 0 |
88
|
|
|
|
|
|
|
sub check_range { |
89
|
195
|
|
|
195
|
0
|
19516
|
my ($self, $value) = @_; |
90
|
195
|
|
|
|
|
148
|
my $false = 0; |
91
|
195
|
|
|
|
|
142
|
my $true = 1; |
92
|
195
|
100
|
|
|
|
276
|
if ($self->alert_on == INSIDE) { |
93
|
16
|
|
|
|
|
55
|
$false = 1; |
94
|
16
|
|
|
|
|
15
|
$true = 0; |
95
|
|
|
|
|
|
|
} |
96
|
195
|
100
|
100
|
|
|
716
|
if ($self->end_infinity == 0 && $self->start_infinity == 0) { |
|
|
100
|
66
|
|
|
|
|
|
|
50
|
33
|
|
|
|
|
97
|
101
|
100
|
100
|
|
|
690
|
if ($self->start <= $value && $value <= $self->end) { |
98
|
52
|
|
|
|
|
394
|
return $false; |
99
|
|
|
|
|
|
|
} else { |
100
|
49
|
|
|
|
|
387
|
return $true; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
} elsif ($self->start_infinity == 0 && $self->end_infinity == 1) { |
103
|
29
|
100
|
|
|
|
294
|
if ( $value >= $self->start ) { |
104
|
14
|
|
|
|
|
64
|
return $false; |
105
|
|
|
|
|
|
|
} else { |
106
|
15
|
|
|
|
|
89
|
return $true; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
} elsif ($self->start_infinity == 1 && $self->end_infinity == 0) { |
109
|
65
|
100
|
|
|
|
992
|
if ($value <= $self->end) { |
110
|
40
|
|
|
|
|
190
|
return $false; |
111
|
|
|
|
|
|
|
} else { |
112
|
25
|
|
|
|
|
141
|
return $true; |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
} else { |
115
|
0
|
|
|
|
|
0
|
return $false; |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
# Constructor - map args to hashref for SUPER |
120
|
|
|
|
|
|
|
sub new |
121
|
|
|
|
|
|
|
{ |
122
|
241
|
|
|
241
|
1
|
801
|
shift->SUPER::new({ @_ }); |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
1; |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
__END__ |