line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
1
|
|
|
1
|
|
25597
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
56
|
|
2
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
80
|
|
3
|
|
|
|
|
|
|
package Juno::Check::Ping; |
4
|
|
|
|
|
|
|
# ABSTRACT: A Ping check for Juno |
5
|
|
|
|
|
|
|
$Juno::Check::Ping::VERSION = '0.010'; |
6
|
1
|
|
|
1
|
|
750
|
use Moo; |
|
1
|
|
|
|
|
15302
|
|
|
1
|
|
|
|
|
6
|
|
7
|
1
|
|
|
1
|
|
2090
|
use MooX::Types::MooseLike::Base qw; |
|
1
|
|
|
|
|
6471
|
|
|
1
|
|
|
|
|
134
|
|
8
|
1
|
|
|
1
|
|
702
|
use AnyEvent::Ping; |
|
1
|
|
|
|
|
29549
|
|
|
1
|
|
|
|
|
33
|
|
9
|
1
|
|
|
1
|
|
499
|
use namespace::autoclean; |
|
1
|
|
|
|
|
10600
|
|
|
1
|
|
|
|
|
5
|
|
10
|
1
|
|
|
1
|
|
57
|
use List::Util qw(first ); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
331
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
with 'Juno::Role::Check'; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
has pinger => ( |
15
|
|
|
|
|
|
|
is => 'ro', |
16
|
|
|
|
|
|
|
isa => Object, |
17
|
|
|
|
|
|
|
lazy => 1, |
18
|
|
|
|
|
|
|
builder => '_build_pinger' |
19
|
|
|
|
|
|
|
); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
has ping_interval => ( |
22
|
|
|
|
|
|
|
is => 'ro', |
23
|
|
|
|
|
|
|
isa => Num, |
24
|
|
|
|
|
|
|
predicate => 'has_ping_interval', |
25
|
|
|
|
|
|
|
); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
has ping_timeout => ( |
28
|
|
|
|
|
|
|
is => 'ro', |
29
|
|
|
|
|
|
|
isa => Num, |
30
|
|
|
|
|
|
|
predicate => 'has_ping_timeout', |
31
|
|
|
|
|
|
|
); |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
has count => ( |
34
|
|
|
|
|
|
|
is => 'ro', |
35
|
|
|
|
|
|
|
isa => Int, #change this for a check of the data (positive int - no zero) |
36
|
|
|
|
|
|
|
default => sub {1}, |
37
|
|
|
|
|
|
|
); |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub _build_pinger { |
40
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
41
|
0
|
0
|
|
|
|
0
|
my $pinger = AnyEvent::Ping->new ( |
|
|
0
|
|
|
|
|
|
42
|
|
|
|
|
|
|
$self->has_ping_timeout ? ( timeout => $self->ping_timeout ) : (), |
43
|
|
|
|
|
|
|
$self->has_ping_interval ? ( interval => $self->ping_interval ) : (), |
44
|
|
|
|
|
|
|
); |
45
|
|
|
|
|
|
|
|
46
|
0
|
|
|
|
|
0
|
return $pinger; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub check { |
50
|
1
|
|
|
1
|
0
|
3
|
my $self = shift; |
51
|
1
|
|
|
|
|
2
|
my @hosts = @{ $self->hosts }; |
|
1
|
|
|
|
|
7
|
|
52
|
1
|
|
|
|
|
6
|
my $pinger = $self->pinger; |
53
|
|
|
|
|
|
|
|
54
|
1
|
|
|
|
|
578
|
foreach my $host (@hosts) { |
55
|
3
|
50
|
|
|
|
2343
|
$self->has_on_before |
56
|
|
|
|
|
|
|
and $self->on_before->( $self, $host ); |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
$pinger->ping( $host, $self->count, sub { |
59
|
3
|
|
|
3
|
|
4196
|
my $results = shift; |
60
|
|
|
|
|
|
|
|
61
|
3
|
50
|
|
|
|
24
|
$self->has_on_result |
62
|
|
|
|
|
|
|
and $self->on_result->( $self, $host, $results ); |
63
|
|
|
|
|
|
|
|
64
|
3
|
100
|
|
|
|
3624
|
if ( first { $_->[0] eq 'OK' } @{$results} ) { |
|
7
|
|
|
|
|
15
|
|
|
3
|
|
|
|
|
14
|
|
65
|
2
|
50
|
|
|
|
15
|
$self->has_on_success |
66
|
|
|
|
|
|
|
and $self->on_success->( $self, $host, $results ); |
67
|
|
|
|
|
|
|
} else { |
68
|
1
|
50
|
|
|
|
9
|
$self->has_on_fail |
69
|
|
|
|
|
|
|
and $self->on_fail->( $self, $host, $results ); |
70
|
|
|
|
|
|
|
} |
71
|
3
|
|
|
|
|
26
|
} ); |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
1
|
|
|
|
|
1163
|
return 0; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
1; |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
__END__ |