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