| 1 | package Nagios::Plugin::CheckHost::HTTP; | ||||||||||
| 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 | |||||||||||
| 8 | 1 | ▶ | sub _initialize { | ||||||||
|
Subroutine
_initialize: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 1 | my $self = shift; | |||||||||
| 10 | |||||||||||
| 11 | 1 | $self->{check} = 'http'; | |||||||||
| 12 | |||||||||||
| 13 | 1 | my $np = $self->_initialize_nagios(shortname => 'CHECKHOST-HTTP'); | |||||||||
| 14 | |||||||||||
| 15 | 1 | $np->add_arg( | |||||||||
| 16 | spec => 'host|H=s', | ||||||||||
| 17 | help => 'host to check', | ||||||||||
| 18 | required => 1, | ||||||||||
| 19 | ); | ||||||||||
| 20 | |||||||||||
| 21 | 1 | $np->add_arg( | |||||||||
| 22 | spec => 'max_nodes|n=i', | ||||||||||
| 23 | help => 'max amount of nodes used for the check (default %s)', | ||||||||||
| 24 | default => 3, | ||||||||||
| 25 | required => 1, | ||||||||||
| 26 | ); | ||||||||||
| 27 | |||||||||||
| 28 | 1 | $np->add_arg( | |||||||||
| 29 | spec => 'warning|w=i', | ||||||||||
| 30 | help => 'maximum number of nodes that failed ' | ||||||||||
| 31 | . 'threshold check with any code, ' | ||||||||||
| 32 | . 'outside of which a warning will be generated. ' | ||||||||||
| 33 | . 'Default %s.', | ||||||||||
| 34 | default => 0, | ||||||||||
| 35 | ); | ||||||||||
| 36 | |||||||||||
| 37 | 1 | $np->add_arg( | |||||||||
| 38 | spec => 'critical|c=i', | ||||||||||
| 39 | help => 'maximum number of nodes that failed ' | ||||||||||
| 40 | . 'threshold check with a critical code, ' | ||||||||||
| 41 | . 'outside of which a critical will be generated. ' | ||||||||||
| 42 | . 'Default %s.', | ||||||||||
| 43 | default => 1, | ||||||||||
| 44 | ); | ||||||||||
| 45 | |||||||||||
| 46 | 1 | $self; | |||||||||
| 47 | } | ||||||||||
| 48 | |||||||||||
| 49 | 4 | ▶ | sub process_check_result { | ||||||||
|
Subroutine
process_check_result: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||
| 50 | 4 | my ($self, $result) = @_; | |||||||||
| 51 | |||||||||||
| 52 | 4 | my $np = $self->{nagios}; | |||||||||
| 53 | 4 | my $opts = $np->opts; | |||||||||
| 54 | |||||||||||
| 55 | 4 | my @failed_nodes = (); | |||||||||
| 56 | |||||||||||
| 57 | 4 | foreach my $node ($result->nodes) { | |||||||||
| 58 | 11 | ▶ | push @failed_nodes, $node unless $result->request_ok($node); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 59 | |||||||||||
| 60 | 11 | my $response_time = $result->request_time($node); | |||||||||
| 61 | 11 | $np->add_perfdata( | |||||||||
| 62 | label => "time-" . $node->shortname, | ||||||||||
| 63 | value => $response_time, | ||||||||||
| 64 | uom => 's', | ||||||||||
| 65 | ); | ||||||||||
| 66 | } | ||||||||||
| 67 | |||||||||||
| 68 | 4 | my $code = $np->check_threshold( | |||||||||
| 69 | check => scalar(@failed_nodes), | ||||||||||
| 70 | warning => $opts->get('warning'), | ||||||||||
| 71 | critical => $opts->get('critical'), | ||||||||||
| 72 | ); | ||||||||||
| 73 | |||||||||||
| 74 | 4 | $np->nagios_exit($code, 'report ' . $self->report_url); | |||||||||
| 75 | } | ||||||||||
| 76 | |||||||||||
| 77 | 1 | 1; | |||||||||