line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Monitoring::Plugin::Range; |
2
|
|
|
|
|
|
|
|
3
|
7
|
|
|
7
|
|
50973
|
use 5.006; |
|
7
|
|
|
|
|
25
|
|
4
|
7
|
|
|
7
|
|
29
|
use strict; |
|
7
|
|
|
|
|
9
|
|
|
7
|
|
|
|
|
134
|
|
5
|
7
|
|
|
7
|
|
26
|
use warnings; |
|
7
|
|
|
|
|
10
|
|
|
7
|
|
|
|
|
160
|
|
6
|
|
|
|
|
|
|
|
7
|
7
|
|
|
7
|
|
32
|
use Carp; |
|
7
|
|
|
|
|
10
|
|
|
7
|
|
|
|
|
341
|
|
8
|
7
|
|
|
7
|
|
48
|
use base qw(Class::Accessor::Fast); |
|
7
|
|
|
|
|
10
|
|
|
7
|
|
|
|
|
931
|
|
9
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors( |
10
|
|
|
|
|
|
|
qw(start end start_infinity end_infinity alert_on) |
11
|
|
|
|
|
|
|
); |
12
|
|
|
|
|
|
|
|
13
|
7
|
|
|
7
|
|
2916
|
use Monitoring::Plugin::Functions qw(:DEFAULT $value_re); |
|
7
|
|
|
|
|
18
|
|
|
7
|
|
|
|
|
1415
|
|
14
|
|
|
|
|
|
|
our ($VERSION) = $Monitoring::Plugin::Functions::VERSION; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
use overload |
17
|
34
|
|
|
34
|
|
19085
|
'eq' => sub { shift->_stringify }, |
18
|
7
|
|
|
7
|
|
1898
|
'""' => sub { shift->_stringify }; |
|
7
|
|
|
17
|
|
1512
|
|
|
7
|
|
|
|
|
83
|
|
|
17
|
|
|
|
|
151
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
# alert_on constants (undef == range not set) |
21
|
7
|
|
|
7
|
|
429
|
use constant OUTSIDE => 0; |
|
7
|
|
|
|
|
17
|
|
|
7
|
|
|
|
|
406
|
|
22
|
7
|
|
|
7
|
|
35
|
use constant INSIDE => 1; |
|
7
|
|
|
|
|
10
|
|
|
7
|
|
|
|
|
4053
|
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub _stringify { |
25
|
51
|
|
|
51
|
|
64
|
my $self = shift; |
26
|
51
|
100
|
|
|
|
79
|
return "" unless $self->is_set; |
27
|
49
|
100
|
|
|
|
799
|
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
|
3559
|
my $self = shift; |
34
|
221
|
100
|
|
|
|
2729
|
(! defined $self->alert_on) ? 0 : 1; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub _set_range_start { |
38
|
40
|
|
|
40
|
|
63
|
my ($self, $value) = @_; |
39
|
40
|
|
|
|
|
612
|
$self->start($value+0); # Force scalar into number |
40
|
40
|
|
|
|
|
678
|
$self->start_infinity(0); |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub _set_range_end { |
44
|
189
|
|
|
189
|
|
280
|
my ($self, $value) = @_; |
45
|
189
|
|
|
|
|
2834
|
$self->end($value+0); # Force scalar into number |
46
|
189
|
|
|
|
|
2985
|
$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
|
8189
|
my ($class, $string) = @_; |
52
|
204
|
|
|
|
|
238
|
my $valid = 0; |
53
|
204
|
|
|
|
|
313
|
my $range = $class->new( start => 0, start_infinity => 0, end => 0, end_infinity => 1, alert_on => OUTSIDE); |
54
|
|
|
|
|
|
|
|
55
|
204
|
|
|
|
|
1448
|
$string =~ s/\s//g; # strip out any whitespace |
56
|
|
|
|
|
|
|
# check for valid range definition |
57
|
204
|
100
|
100
|
|
|
1824
|
unless ( $string =~ /[\d~]/ && $string =~ m/^\@?($value_re|~)?(:($value_re)?)?$/ ) { |
58
|
7
|
|
|
|
|
811
|
carp "invalid range definition '$string'"; |
59
|
7
|
|
|
|
|
52
|
return undef; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
197
|
100
|
|
|
|
379
|
if ($string =~ s/^\@//) { |
63
|
2
|
|
|
|
|
38
|
$range->alert_on(INSIDE); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
197
|
100
|
|
|
|
325
|
if ($string =~ s/^~//) { # '~:x' |
67
|
12
|
|
|
|
|
176
|
$range->start_infinity(1); |
68
|
|
|
|
|
|
|
} |
69
|
197
|
100
|
|
|
|
729
|
if ( $string =~ m/^($value_re)?:/ ) { # '10:' |
70
|
53
|
|
|
|
|
98
|
my $start = $1; |
71
|
53
|
100
|
|
|
|
123
|
$range->_set_range_start($start) if defined $start; |
72
|
53
|
|
|
|
|
803
|
$range->end_infinity(1); # overridden below if there's an end specified |
73
|
53
|
|
|
|
|
566
|
$string =~ s/^($value_re)?://; |
74
|
53
|
|
|
|
|
128
|
$valid++; |
75
|
|
|
|
|
|
|
} |
76
|
197
|
100
|
|
|
|
706
|
if ($string =~ /^($value_re)$/) { # 'x:10' or '10' |
77
|
189
|
|
|
|
|
356
|
$range->_set_range_end($string); |
78
|
189
|
|
|
|
|
766
|
$valid++; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
197
|
100
|
100
|
|
|
2493
|
if ($valid && ($range->start_infinity == 1 || $range->end_infinity == 1 || $range->start <= $range->end)) { |
|
|
|
66
|
|
|
|
|
82
|
196
|
|
|
|
|
8287
|
return $range; |
83
|
|
|
|
|
|
|
} |
84
|
1
|
|
|
|
|
45
|
return undef; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
# Returns 1 if an alert should be raised, otherwise 0 |
88
|
|
|
|
|
|
|
sub check_range { |
89
|
195
|
|
|
195
|
0
|
29579
|
my ($self, $value) = @_; |
90
|
195
|
|
|
|
|
217
|
my $false = 0; |
91
|
195
|
|
|
|
|
196
|
my $true = 1; |
92
|
195
|
100
|
|
|
|
2767
|
if ($self->alert_on == INSIDE) { |
93
|
16
|
|
|
|
|
67
|
$false = 1; |
94
|
16
|
|
|
|
|
16
|
$true = 0; |
95
|
|
|
|
|
|
|
} |
96
|
195
|
100
|
100
|
|
|
2798
|
if ($self->end_infinity == 0 && $self->start_infinity == 0) { |
|
|
100
|
66
|
|
|
|
|
|
|
50
|
33
|
|
|
|
|
97
|
101
|
100
|
100
|
|
|
2860
|
if ($self->start <= $value && $value <= $self->end) { |
98
|
52
|
|
|
|
|
1007
|
return $false; |
99
|
|
|
|
|
|
|
} else { |
100
|
49
|
|
|
|
|
707
|
return $true; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
} elsif ($self->start_infinity == 0 && $self->end_infinity == 1) { |
103
|
29
|
100
|
|
|
|
1204
|
if ( $value >= $self->start ) { |
104
|
14
|
|
|
|
|
79
|
return $false; |
105
|
|
|
|
|
|
|
} else { |
106
|
15
|
|
|
|
|
97
|
return $true; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
} elsif ($self->start_infinity == 1 && $self->end_infinity == 0) { |
109
|
65
|
100
|
|
|
|
4289
|
if ($value <= $self->end) { |
110
|
40
|
|
|
|
|
222
|
return $false; |
111
|
|
|
|
|
|
|
} else { |
112
|
25
|
|
|
|
|
171
|
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
|
793
|
shift->SUPER::new({ @_ }); |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
1; |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
__END__ |