| 1 | package Nagios::Monitoring::Plugin::Threshold; | ||||||||||
| 2 | |||||||||||
| 3 | 9 | ▶ | use 5.006; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | |||||||||||
| 5 | 9 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 9 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 9 | ▶ | use base qw(Class::Accessor::Fast); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 9 | __PACKAGE__->mk_accessors(qw(warning critical)); | |||||||||
| 10 | |||||||||||
| 11 | 9 | ▶ | use Nagios::Monitoring::Plugin::Range; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | 9 | ▶ | use Nagios::Monitoring::Plugin::Functions qw(:codes nagios_die); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | 9 | our ($VERSION) = $Nagios::Monitoring::Plugin::Functions::VERSION; | |||||||||
| 14 | |||||||||||
| 15 | sub get_status | ||||||||||
| 16 | 71 | ▶ | { | ||||||||
|
Subroutine
get_status: called CC=8 SCAR=20.8
Pod
undocumented
| |||||||||||
| 17 | 71 | my ($self, $value) = @_; | |||||||||
| 18 | |||||||||||
| 19 | 71 | ▶ | $value = [ $value ] if (ref $value eq ""); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 20 | 71 | foreach my $v (@$value) { | |||||||||
| 21 | 79 | ▶ | if ($self->critical->is_set) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 22 | 67 | ▶ | return CRITICAL if $self->critical->check_range($v); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 23 | } | ||||||||||
| 24 | } | ||||||||||
| 25 | 51 | foreach my $v (@$value) { | |||||||||
| 26 | 52 | ▶ | if ($self->warning->is_set) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 27 | 44 | ▶ | return WARNING if $self->warning->check_range($v); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 28 | } | ||||||||||
| 29 | } | ||||||||||
| 30 | 27 | return OK; | |||||||||
| 31 | } | ||||||||||
| 32 | |||||||||||
| 33 | sub _inflate | ||||||||||
| 34 | 230 | ▶ | { | ||||||||
|
Subroutine
_inflate: called CC=6 SCAR=18.0
| |||||||||||
| 35 | 230 | my ($self, $value, $key) = @_; | |||||||||
| 36 | |||||||||||
| 37 | # Return an undefined range if $value is undef | ||||||||||
| 38 | 230 | ▶ | return Nagios::Monitoring::Plugin::Range->new if ! defined $value; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 39 | |||||||||||
| 40 | # For refs, check isa N::P::Range | ||||||||||
| 41 | 199 | ▶ | if (ref $value) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 42 | 3 | ▶ | nagios_die("Invalid $key object: type " . ref $value) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 43 | unless $value->isa("Nagios::Monitoring::Plugin::Range"); | ||||||||||
| 44 | 3 | return $value; | |||||||||
| 45 | } | ||||||||||
| 46 | |||||||||||
| 47 | # Another quick exit if $value is an empty string | ||||||||||
| 48 | 196 | ▶ | return Nagios::Monitoring::Plugin::Range->new if $value eq ""; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 49 | |||||||||||
| 50 | # Otherwise parse $value | ||||||||||
| 51 | 190 | my $range = Nagios::Monitoring::Plugin::Range->parse_range_string($value); | |||||||||
| 52 | 190 | ▶ | nagios_die("Cannot parse $key range: '$value'") unless(defined($range)); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 53 | 190 | return $range; | |||||||||
| 54 | } | ||||||||||
| 55 | |||||||||||
| 56 | sub set_thresholds | ||||||||||
| 57 | 115 | ▶ | { | ||||||||
|
Subroutine
set_thresholds: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||
| 58 | 115 | my ($self, %arg) = @_; | |||||||||
| 59 | |||||||||||
| 60 | # Equals new() as a class method | ||||||||||
| 61 | 115 | ▶ | return $self->new(%arg) unless ref $self; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 62 | |||||||||||
| 63 | # On an object, just acts as special mutator | ||||||||||
| 64 | 2 | $self->set($_, $arg{$_}) foreach qw(warning critical); | |||||||||
| 65 | } | ||||||||||
| 66 | |||||||||||
| 67 | sub set | ||||||||||
| 68 | 4 | ▶ | { | ||||||||
|
Subroutine
set: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 69 | 4 | my $self = shift; | |||||||||
| 70 | 4 | my ($key, $value) = @_; | |||||||||
| 71 | 4 | $self->SUPER::set($key, $self->_inflate($value, $key)); | |||||||||
| 72 | } | ||||||||||
| 73 | |||||||||||
| 74 | # Constructor - inflate scalars to N::P::Range objects | ||||||||||
| 75 | sub new | ||||||||||
| 76 | 113 | ▶ | { | ||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 77 | 113 | my ($self, %arg) = @_; | |||||||||
| 78 | $self->SUPER::new({ | ||||||||||
| 79 | 113 | map { $_ => $self->_inflate($arg{$_}, $_) } qw(warning critical) | |||||||||
| 80 | }); | ||||||||||
| 81 | } | ||||||||||
| 82 | |||||||||||
| 83 | 9 | 1; | |||||||||
| 84 | |||||||||||
| 85 | __END__ | ||||||||||