| 1 | package Nagios::Monitoring::Plugin::Range; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 10 | ▶ | use 5.006; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 10 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 10 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 10 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 10 | ▶ | use base qw(Class::Accessor::Fast); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 10 | __PACKAGE__->mk_accessors( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | qw(start end start_infinity end_infinity alert_on) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 10 | ▶ | use Nagios::Monitoring::Plugin::Functions qw(:DEFAULT $value_re); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 10 | our ($VERSION) = $Nagios::Monitoring::Plugin::Functions::VERSION; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | use overload | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 34 | ▶ | 'eq' => sub { shift->_stringify }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 10 | ▶ | '""' => sub { shift->_stringify }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | # alert_on constants (undef == range not set) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 10 | ▶ | use constant OUTSIDE => 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 10 | ▶ | use constant INSIDE => 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 51 | ▶ | sub _stringify { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_stringify: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 51 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 51 | ▶ | return "" unless $self->is_set; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 49 | ▶ | return (($self->alert_on) ? "@" : "") . | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | (($self->start_infinity == 1) ? "~:" : (($self->start == 0)?"":$self->start.":")) . | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | (($self->end_infinity == 1) ? "" : $self->end); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 226 | ▶ | sub is_set { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_set: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 226 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 226 | ▶ | (! defined $self->alert_on) ? 0 : 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 43 | ▶ | sub _set_range_start { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_set_range_start: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 43 | my ($self, $value) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 43 | $self->start($value+0); # Force scalar into number | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 43 | $self->start_infinity(0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 195 | ▶ | sub _set_range_end { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_set_range_end: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 195 | my ($self, $value) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 195 | $self->end($value+0); # Force scalar into number | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 195 | $self->end_infinity(0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | # Returns a N::P::Range object if the string is a conforms to a Nagios Plugin range string, otherwise null | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 210 | ▶ | sub parse_range_string { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_range_string: called CC=12 SCAR=24.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 210 | my ($class, $string) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 210 | my $valid = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 210 | my $range = $class->new( start => 0, start_infinity => 0, end => 0, end_infinity => 1, alert_on => OUTSIDE); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 210 | $string =~ s/\s//g; # strip out any whitespace | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | # check for valid range definition | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 210 | ▶ | unless ( $string =~ /[\d~]/ && $string =~ m/^\@?($value_re|~)?(:($value_re)?)?$/ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$string =~ /[\d~]/ and $string =~ /^\@?($Nagios::Monitoring::Plugin::Range::value_re|~)?(:($Nagios::Monitoring::Plugin::Range::value_re)?)?$/
MC/DC100%2/2
$string =~ /[\d~]/ and $string =~ /^\@?($Nagios::Monitoring::Plugin::Range::value_re|~)?(:($Nagios::Monitoring::Plugin::Range::value_re)?)?$/
$string =~ /[\d~]/
$string =~ /^\@?($Nagios::Monitoring::Plugin::Range::value_re|~)?(:($Nagios::Monitoring::Plugin::Range::value_re)?)?$/
Truth table100%3/3
A and B
A= $string =~ /[\d~]/B= $string =~ /^\@?($Nagios::Monitoring::Plugin::Range::value_re|~)?(:($Nagios::Monitoring::Plugin::Range::value_re)?)?$/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 7 | carp "invalid range definition '$string'"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 7 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 203 | ▶ | if ($string =~ s/^\@//) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 2 | $range->alert_on(INSIDE); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 203 | ▶ | if ($string =~ s/^~//) { # '~:x' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 15 | $range->start_infinity(1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 203 | ▶ | if ( $string =~ m/^($value_re)?:/ ) { # '10:' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 59 | my $start = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 59 | ▶ | $range->_set_range_start($start) if defined $start; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 59 | $range->end_infinity(1); # overridden below if there's an end specified | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 59 | $string =~ s/^($value_re)?://; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 59 | $valid++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 203 | ▶ | if ($string =~ /^($value_re)$/) { # 'x:10' or '10' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 195 | $range->_set_range_end($string); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 195 | $valid++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 203 | ▶ | if ($valid && ($range->start_infinity == 1 || $range->end_infinity == 1 || $range->start <= $range->end)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition88%8/9
$valid and $range->start_infinity == 1 || $range->end_infinity == 1 || $range->start <= $range->end
$range->start_infinity == 1 or $range->end_infinity == 1 or $range->start <= $range->end
$range->start_infinity == 1 or $range->end_infinity == 1
MC/DC75%3/4
$valid and $range->start_infinity == 1 || $range->end_infinity == 1 || $range->start <= $range->end
$valid
$range->start_infinity == 1
$range->end_infinity == 1
$range->start <= $range->end
Truth table80%4/5
A and B or C or D
A= $validB= $range->start_infinity == 1C= $range->end_infinity == 1D= $range->start <= $range->end
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 202 | return $range; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 1 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | # Returns 1 if an alert should be raised, otherwise 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 200 | ▶ | sub check_range { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
check_range: called CC=12 SCAR=25.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 200 | my ($self, $value) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 200 | my $false = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 200 | my $true = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 200 | ▶ | if ($self->alert_on == INSIDE) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 16 | $false = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 16 | $true = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 200 | ▶ | if ($self->end_infinity == 0 && $self->start_infinity == 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition100%3/3
$self->end_infinity == 0 and $self->start_infinity == 0
MC/DC100%2/2
$self->end_infinity == 0 and $self->start_infinity == 0
$self->end_infinity == 0
$self->start_infinity == 0
Truth table100%3/3
A and B
A= $self->end_infinity == 0B= $self->start_infinity == 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 103 | ▶ | if ($self->start <= $value && $value <= $self->end) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->start <= $value and $value <= $self->end
MC/DC100%2/2
$self->start <= $value and $value <= $self->end
$self->start <= $value
$value <= $self->end
Truth table100%3/3
A and B
A= $self->start <= $valueB= $value <= $self->end
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 53 | return $false; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 50 | return $true; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | ▶ | } elsif ($self->start_infinity == 0 && $self->end_infinity == 1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$self->start_infinity == 0 and $self->end_infinity == 1
MC/DC50%1/2
$self->start_infinity == 0 and $self->end_infinity == 1
$self->start_infinity == 0
$self->end_infinity == 1
Truth table66%2/3
A and B
A= $self->start_infinity == 0B= $self->end_infinity == 1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 29 | ▶ | if ( $value >= $self->start ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 14 | return $false; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 15 | return $true; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | ▶ | } elsif ($self->start_infinity == 1 && $self->end_infinity == 0) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$self->start_infinity == 1 and $self->end_infinity == 0
MC/DC0%0/2
$self->start_infinity == 1 and $self->end_infinity == 0
$self->start_infinity == 1
$self->end_infinity == 0
Truth table33%1/3
A and B
A= $self->start_infinity == 1B= $self->end_infinity == 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 68 | ▶ | if ($value <= $self->end) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 42 | return $false; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 26 | return $true; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | return $false; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | # Constructor - map args to hashref for SUPER | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | sub new | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 247 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 247 | shift->SUPER::new({ @_ }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 10 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||