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