line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Nagios::Plugin::CheckHost::Ping; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
421
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
21
|
|
4
|
1
|
|
|
1
|
|
3
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
19
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
3
|
use base 'Nagios::Plugin::CheckHost'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
315
|
|
7
|
1
|
|
|
1
|
|
435
|
use Monitoring::Plugin::Threshold; |
|
1
|
|
|
|
|
2070
|
|
|
1
|
|
|
|
|
4
|
|
8
|
1
|
|
|
1
|
|
387
|
use Nagios::Plugin::Threshold::Group; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
263
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub _initialize { |
11
|
1
|
|
|
1
|
|
2
|
my $self = shift; |
12
|
|
|
|
|
|
|
|
13
|
1
|
|
|
|
|
3
|
$self->{check} = 'ping'; |
14
|
|
|
|
|
|
|
|
15
|
1
|
|
|
|
|
6
|
my $np = $self->_initialize_nagios(shortname => 'CHECKHOST-PING'); |
16
|
|
|
|
|
|
|
|
17
|
1
|
|
|
|
|
12791
|
$np->add_arg( |
18
|
|
|
|
|
|
|
spec => 'host|H=s', |
19
|
|
|
|
|
|
|
help => 'host to check', |
20
|
|
|
|
|
|
|
required => 1, |
21
|
|
|
|
|
|
|
); |
22
|
|
|
|
|
|
|
|
23
|
1
|
|
|
|
|
36
|
$self->{total_pings} = 4; |
24
|
1
|
|
|
|
|
3
|
$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
|
|
|
|
|
30
|
$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
|
|
|
|
|
26
|
$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
|
|
|
|
|
27
|
$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
|
|
|
|
|
25
|
$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
|
|
|
|
|
24
|
$self; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub process_check_result { |
70
|
4
|
|
|
4
|
0
|
5
|
my ($self, $result) = @_; |
71
|
|
|
|
|
|
|
|
72
|
4
|
|
|
|
|
6
|
my $np = $self->{nagios}; |
73
|
4
|
|
|
|
|
11
|
my $opts = $np->opts; |
74
|
|
|
|
|
|
|
|
75
|
4
|
|
|
|
|
13
|
my @losses = (); |
76
|
|
|
|
|
|
|
|
77
|
4
|
|
|
|
|
11
|
foreach my $node ($result->nodes) { |
78
|
11
|
|
|
|
|
85
|
my $loss = $result->calc_loss($node); |
79
|
11
|
|
|
|
|
14
|
$loss = int($loss * 100); |
80
|
|
|
|
|
|
|
|
81
|
11
|
|
|
|
|
20
|
$np->add_perfdata( |
82
|
|
|
|
|
|
|
label => "loss-" . $node->shortname, |
83
|
|
|
|
|
|
|
value => $loss, |
84
|
|
|
|
|
|
|
uom => '%', |
85
|
|
|
|
|
|
|
); |
86
|
|
|
|
|
|
|
|
87
|
11
|
|
|
|
|
1883
|
push @losses, $loss; |
88
|
|
|
|
|
|
|
|
89
|
11
|
100
|
|
|
|
19
|
if (my ($avg) = $result->calc_rtt($node)) { |
90
|
8
|
|
|
|
|
13
|
$np->add_perfdata( |
91
|
|
|
|
|
|
|
label => "avg-" . $node->shortname, |
92
|
|
|
|
|
|
|
value => int(1000 * $avg), |
93
|
|
|
|
|
|
|
uom => 'ms', |
94
|
|
|
|
|
|
|
); |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
4
|
|
|
|
|
72
|
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
|
|
|
|
|
14
|
my $code = $loss_threshold->get_status(\@losses); |
110
|
|
|
|
|
|
|
|
111
|
4
|
|
|
|
|
13
|
$np->nagios_exit($code, "report " . $self->report_url); |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
1; |