| 1 | package Nagios::Plugin::CheckHost::Ping; | ||||||||||
| 2 | |||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 1 | ▶ | use base 'Nagios::Plugin::CheckHost'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 1 | ▶ | use Monitoring::Plugin::Threshold; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 1 | ▶ | use Nagios::Plugin::Threshold::Group; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | sub _initialize { | ||||||||||
| 11 | 1 | ▶ | my $self = shift; | ||||||||
|
Subroutine
_initialize: called CC=1 SCAR=0.0
| |||||||||||
| 12 | |||||||||||
| 13 | 1 | $self->{check} = 'ping'; | |||||||||
| 14 | |||||||||||
| 15 | 1 | my $np = $self->_initialize_nagios(shortname => 'CHECKHOST-PING'); | |||||||||
| 16 | |||||||||||
| 17 | 1 | $np->add_arg( | |||||||||
| 18 | spec => 'host|H=s', | ||||||||||
| 19 | help => 'host to check', | ||||||||||
| 20 | required => 1, | ||||||||||
| 21 | ); | ||||||||||
| 22 | |||||||||||
| 23 | 1 | $self->{total_pings} = 4; | |||||||||
| 24 | 1 | $np->add_arg( | |||||||||
| 25 | spec => 'loss_threshold_critical|ltc=s', | ||||||||||
| 26 | help => 'maximum percentage of ping loss ' | ||||||||||
| 27 | . 'outside of which a critical code ' | ||||||||||
| 28 | . 'will be generated for a node (default %s).', | ||||||||||
| 29 | default => 50, | ||||||||||
| 30 | required => 1, | ||||||||||
| 31 | ); | ||||||||||
| 32 | 1 | $np->add_arg( | |||||||||
| 33 | spec => 'loss_threshold_warning|ltw=s', | ||||||||||
| 34 | help => 'maximum percentage of ping loss ' | ||||||||||
| 35 | . 'outside of which a warning code ' | ||||||||||
| 36 | . 'will be generated for a node (default %s).', | ||||||||||
| 37 | default => 25, | ||||||||||
| 38 | required => 1, | ||||||||||
| 39 | ); | ||||||||||
| 40 | |||||||||||
| 41 | 1 | $np->add_arg( | |||||||||
| 42 | spec => 'max_nodes|n=i', | ||||||||||
| 43 | help => 'max amount of nodes used for the check (default %s)', | ||||||||||
| 44 | default => 3, | ||||||||||
| 45 | required => 1, | ||||||||||
| 46 | ); | ||||||||||
| 47 | |||||||||||
| 48 | 1 | $np->add_arg( | |||||||||
| 49 | spec => 'warning|w=i', | ||||||||||
| 50 | help => 'maximum number of nodes that failed ' | ||||||||||
| 51 | . 'threshold check with any code, ' | ||||||||||
| 52 | . 'outside of which a warning will be generated. ' | ||||||||||
| 53 | . 'Default %s.', | ||||||||||
| 54 | default => 0, | ||||||||||
| 55 | ); | ||||||||||
| 56 | |||||||||||
| 57 | 1 | $np->add_arg( | |||||||||
| 58 | spec => 'critical|c=i', | ||||||||||
| 59 | help => 'maximum number of nodes that failed ' | ||||||||||
| 60 | . 'threshold check with a critical code, ' | ||||||||||
| 61 | . 'outside of which a critical will be generated. ' | ||||||||||
| 62 | . 'Default %s.', | ||||||||||
| 63 | default => 1, | ||||||||||
| 64 | ); | ||||||||||
| 65 | |||||||||||
| 66 | 1 | $self; | |||||||||
| 67 | } | ||||||||||
| 68 | |||||||||||
| 69 | sub process_check_result { | ||||||||||
| 70 | 4 | ▶ | my ($self, $result) = @_; | ||||||||
|
Subroutine
process_check_result: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||
| 71 | |||||||||||
| 72 | 4 | my $np = $self->{nagios}; | |||||||||
| 73 | 4 | my $opts = $np->opts; | |||||||||
| 74 | |||||||||||
| 75 | 4 | my @losses = (); | |||||||||
| 76 | |||||||||||
| 77 | 4 | foreach my $node ($result->nodes) { | |||||||||
| 78 | 11 | my $loss = $result->calc_loss($node); | |||||||||
| 79 | 11 | $loss = int($loss * 100); | |||||||||
| 80 | |||||||||||
| 81 | 11 | $np->add_perfdata( | |||||||||
| 82 | label => "loss-" . $node->shortname, | ||||||||||
| 83 | value => $loss, | ||||||||||
| 84 | uom => '%', | ||||||||||
| 85 | ); | ||||||||||
| 86 | |||||||||||
| 87 | 11 | push @losses, $loss; | |||||||||
| 88 | |||||||||||
| 89 | 11 | ▶ | if (my ($avg) = $result->calc_rtt($node)) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 90 | 8 | $np->add_perfdata( | |||||||||
| 91 | label => "avg-" . $node->shortname, | ||||||||||
| 92 | value => int(1000 * $avg), | ||||||||||
| 93 | uom => 'ms', | ||||||||||
| 94 | ); | ||||||||||
| 95 | } | ||||||||||
| 96 | } | ||||||||||
| 97 | |||||||||||
| 98 | 4 | my $loss_threshold = Nagios::Plugin::Threshold::Group->new( | |||||||||
| 99 | group_threshold => Monitoring::Plugin::Threshold->new( | ||||||||||
| 100 | critical => $opts->get('critical'), | ||||||||||
| 101 | warning => $opts->get('warning'), | ||||||||||
| 102 | ), | ||||||||||
| 103 | single_threshold => Monitoring::Plugin::Threshold->new( | ||||||||||
| 104 | critical => $opts->get('loss_threshold_critical'), | ||||||||||
| 105 | warning => $opts->get('loss_threshold_warning'), | ||||||||||
| 106 | ), | ||||||||||
| 107 | ); | ||||||||||
| 108 | |||||||||||
| 109 | 4 | my $code = $loss_threshold->get_status(\@losses); | |||||||||
| 110 | |||||||||||
| 111 | 4 | $np->nagios_exit($code, "report " . $self->report_url); | |||||||||
| 112 | } | ||||||||||
| 113 | |||||||||||
| 114 | 1 | 1; | |||||||||