line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Nagios::Plugin::CheckHost::HTTP; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
680
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
31
|
|
4
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
33
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
5
|
use base 'Nagios::Plugin::CheckHost'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
478
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub _initialize { |
9
|
1
|
|
|
1
|
|
2
|
my $self = shift; |
10
|
|
|
|
|
|
|
|
11
|
1
|
|
|
|
|
4
|
$self->{check} = 'http'; |
12
|
|
|
|
|
|
|
|
13
|
1
|
|
|
|
|
6
|
my $np = $self->_initialize_nagios(shortname => 'CHECKHOST-HTTP'); |
14
|
|
|
|
|
|
|
|
15
|
1
|
|
|
|
|
13355
|
$np->add_arg( |
16
|
|
|
|
|
|
|
spec => 'host|H=s', |
17
|
|
|
|
|
|
|
help => 'host to check', |
18
|
|
|
|
|
|
|
required => 1, |
19
|
|
|
|
|
|
|
); |
20
|
|
|
|
|
|
|
|
21
|
1
|
|
|
|
|
42
|
$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
|
|
|
|
|
31
|
$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
|
|
|
|
|
35
|
$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
|
|
|
|
|
38
|
$self; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub process_check_result { |
50
|
4
|
|
|
4
|
0
|
6
|
my ($self, $result) = @_; |
51
|
|
|
|
|
|
|
|
52
|
4
|
|
|
|
|
4
|
my $np = $self->{nagios}; |
53
|
4
|
|
|
|
|
13
|
my $opts = $np->opts; |
54
|
|
|
|
|
|
|
|
55
|
4
|
|
|
|
|
15
|
my @failed_nodes = (); |
56
|
|
|
|
|
|
|
|
57
|
4
|
|
|
|
|
11
|
foreach my $node ($result->nodes) { |
58
|
11
|
100
|
|
|
|
4539
|
push @failed_nodes, $node unless $result->request_ok($node); |
59
|
|
|
|
|
|
|
|
60
|
11
|
|
|
|
|
26
|
my $response_time = $result->request_time($node); |
61
|
11
|
|
|
|
|
25
|
$np->add_perfdata( |
62
|
|
|
|
|
|
|
label => "time-" . $node->shortname, |
63
|
|
|
|
|
|
|
value => $response_time, |
64
|
|
|
|
|
|
|
uom => 's', |
65
|
|
|
|
|
|
|
); |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
4
|
|
|
|
|
88
|
my $code = $np->check_threshold( |
69
|
|
|
|
|
|
|
check => scalar(@failed_nodes), |
70
|
|
|
|
|
|
|
warning => $opts->get('warning'), |
71
|
|
|
|
|
|
|
critical => $opts->get('critical'), |
72
|
|
|
|
|
|
|
); |
73
|
|
|
|
|
|
|
|
74
|
4
|
|
|
|
|
1055
|
$np->nagios_exit($code, 'report ' . $self->report_url); |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
1; |