line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Monitoring::Plugin::Range; |
2
|
|
|
|
|
|
|
|
3
|
7
|
|
|
7
|
|
17480
|
use 5.006; |
|
7
|
|
|
|
|
19
|
|
|
7
|
|
|
|
|
276
|
|
4
|
7
|
|
|
7
|
|
35
|
use strict; |
|
7
|
|
|
|
|
9
|
|
|
7
|
|
|
|
|
208
|
|
5
|
7
|
|
|
7
|
|
34
|
use warnings; |
|
7
|
|
|
|
|
10
|
|
|
7
|
|
|
|
|
189
|
|
6
|
|
|
|
|
|
|
|
7
|
7
|
|
|
7
|
|
32
|
use Carp; |
|
7
|
|
|
|
|
9
|
|
|
7
|
|
|
|
|
489
|
|
8
|
7
|
|
|
7
|
|
30
|
use base qw(Class::Accessor::Fast); |
|
7
|
|
|
|
|
8
|
|
|
7
|
|
|
|
|
1116
|
|
9
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors( |
10
|
|
|
|
|
|
|
qw(start end start_infinity end_infinity alert_on) |
11
|
|
|
|
|
|
|
); |
12
|
|
|
|
|
|
|
|
13
|
7
|
|
|
7
|
|
3513
|
use Monitoring::Plugin::Functions qw(:DEFAULT $value_re); |
|
7
|
|
|
|
|
16
|
|
|
7
|
|
|
|
|
1935
|
|
14
|
|
|
|
|
|
|
our ($VERSION) = $Monitoring::Plugin::Functions::VERSION; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
use overload |
17
|
34
|
|
|
34
|
|
18523
|
'eq' => sub { shift->_stringify }, |
18
|
7
|
|
|
7
|
|
3141
|
'""' => sub { shift->_stringify }; |
|
7
|
|
|
17
|
|
2366
|
|
|
7
|
|
|
|
|
90
|
|
|
17
|
|
|
|
|
124
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
# alert_on constants (undef == range not set) |
21
|
7
|
|
|
7
|
|
737
|
use constant OUTSIDE => 0; |
|
7
|
|
|
|
|
8
|
|
|
7
|
|
|
|
|
455
|
|
22
|
7
|
|
|
7
|
|
32
|
use constant INSIDE => 1; |
|
7
|
|
|
|
|
9
|
|
|
7
|
|
|
|
|
5362
|
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub _stringify { |
25
|
51
|
|
|
51
|
|
65
|
my $self = shift; |
26
|
51
|
100
|
|
|
|
82
|
return "" unless $self->is_set; |
27
|
49
|
100
|
|
|
|
366
|
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
|
4167
|
my $self = shift; |
34
|
221
|
100
|
|
|
|
460
|
(! defined $self->alert_on) ? 0 : 1; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub _set_range_start { |
38
|
40
|
|
|
40
|
|
55
|
my ($self, $value) = @_; |
39
|
40
|
|
|
|
|
143
|
$self->start($value+0); # Force scalar into number |
40
|
40
|
|
|
|
|
310
|
$self->start_infinity(0); |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub _set_range_end { |
44
|
189
|
|
|
189
|
|
207
|
my ($self, $value) = @_; |
45
|
189
|
|
|
|
|
523
|
$self->end($value+0); # Force scalar into number |
46
|
189
|
|
|
|
|
1285
|
$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
|
9026
|
my ($class, $string) = @_; |
52
|
204
|
|
|
|
|
186
|
my $valid = 0; |
53
|
204
|
|
|
|
|
411
|
my $range = $class->new( start => 0, start_infinity => 0, end => 0, end_infinity => 1, alert_on => OUTSIDE); |
54
|
|
|
|
|
|
|
|
55
|
204
|
|
|
|
|
2124
|
$string =~ s/\s//g; # strip out any whitespace |
56
|
|
|
|
|
|
|
# check for valid range definition |
57
|
204
|
100
|
100
|
|
|
2856
|
unless ( $string =~ /[\d~]/ && $string =~ m/^\@?($value_re|~)?(:($value_re)?)?$/ ) { |
58
|
7
|
|
|
|
|
924
|
carp "invalid range definition '$string'"; |
59
|
7
|
|
|
|
|
50
|
return undef; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
197
|
100
|
|
|
|
392
|
if ($string =~ s/^\@//) { |
63
|
2
|
|
|
|
|
8
|
$range->alert_on(INSIDE); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
197
|
100
|
|
|
|
356
|
if ($string =~ s/^~//) { # '~:x' |
67
|
12
|
|
|
|
|
38
|
$range->start_infinity(1); |
68
|
|
|
|
|
|
|
} |
69
|
197
|
100
|
|
|
|
918
|
if ( $string =~ m/^($value_re)?:/ ) { # '10:' |
70
|
53
|
|
|
|
|
118
|
my $start = $1; |
71
|
53
|
100
|
|
|
|
152
|
$range->_set_range_start($start) if defined $start; |
72
|
53
|
|
|
|
|
215
|
$range->end_infinity(1); # overridden below if there's an end specified |
73
|
53
|
|
|
|
|
687
|
$string =~ s/^($value_re)?://; |
74
|
53
|
|
|
|
|
102
|
$valid++; |
75
|
|
|
|
|
|
|
} |
76
|
197
|
100
|
|
|
|
891
|
if ($string =~ /^($value_re)$/) { # 'x:10' or '10' |
77
|
189
|
|
|
|
|
315
|
$range->_set_range_end($string); |
78
|
189
|
|
|
|
|
642
|
$valid++; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
197
|
100
|
100
|
|
|
570
|
if ($valid && ($range->start_infinity == 1 || $range->end_infinity == 1 || $range->start <= $range->end)) { |
|
|
|
33
|
|
|
|
|
82
|
196
|
|
|
|
|
2937
|
return $range; |
83
|
|
|
|
|
|
|
} |
84
|
1
|
|
|
|
|
26
|
return undef; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
# Returns 1 if an alert should be raised, otherwise 0 |
88
|
|
|
|
|
|
|
sub check_range { |
89
|
195
|
|
|
195
|
0
|
29641
|
my ($self, $value) = @_; |
90
|
195
|
|
|
|
|
257
|
my $false = 0; |
91
|
195
|
|
|
|
|
171
|
my $true = 1; |
92
|
195
|
100
|
|
|
|
394
|
if ($self->alert_on == INSIDE) { |
93
|
16
|
|
|
|
|
110
|
$false = 1; |
94
|
16
|
|
|
|
|
23
|
$true = 0; |
95
|
|
|
|
|
|
|
} |
96
|
195
|
100
|
100
|
|
|
993
|
if ($self->end_infinity == 0 && $self->start_infinity == 0) { |
|
|
100
|
66
|
|
|
|
|
|
|
50
|
33
|
|
|
|
|
97
|
101
|
100
|
100
|
|
|
956
|
if ($self->start <= $value && $value <= $self->end) { |
98
|
52
|
|
|
|
|
605
|
return $false; |
99
|
|
|
|
|
|
|
} else { |
100
|
49
|
|
|
|
|
534
|
return $true; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
} elsif ($self->start_infinity == 0 && $self->end_infinity == 1) { |
103
|
29
|
100
|
|
|
|
472
|
if ( $value >= $self->start ) { |
104
|
14
|
|
|
|
|
95
|
return $false; |
105
|
|
|
|
|
|
|
} else { |
106
|
15
|
|
|
|
|
107
|
return $true; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
} elsif ($self->start_infinity == 1 && $self->end_infinity == 0) { |
109
|
65
|
100
|
|
|
|
1560
|
if ($value <= $self->end) { |
110
|
40
|
|
|
|
|
314
|
return $false; |
111
|
|
|
|
|
|
|
} else { |
112
|
25
|
|
|
|
|
223
|
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
|
1143
|
shift->SUPER::new({ @_ }); |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
1; |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
__END__ |