Juno/Check/Ping.pm

filter: Statementstmt 93.6% 44 / 47 Branchbran 42.8% 6 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 91.6% 11 / 12 Podpod 0.0% 0 / 1 totaltotal 82.4% 61 / 74 CC 9 SCAR 13.9
CC
9
Cov
82%
_build_pinger
12.0
__ANON__
5.2
check
3.0
CRAP 4.0
« Juno/Check/RawCommand.pm ↑ Summary Juno/Check/SNMP.pm »
1 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 package Juno::Check::Ping;
4 # ABSTRACT: A Ping check for Juno
5 1 $Juno::Check::Ping::VERSION = '0.010';
6 1 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use MooX::Types::MooseLike::Base qw<Int Num Object>;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use AnyEvent::Ping;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use List::Util qw(first );
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 1 with 'Juno::Role::Check';
13  
14 1 has pinger => (
15 is => 'ro',
16 isa => Object,
17 lazy => 1,
18 builder => '_build_pinger'
19 );
20  
21 1 has ping_interval => (
22 is => 'ro',
23 isa => Num,
24 predicate => 'has_ping_interval',
25 );
26  
27 1 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 1 ▶ default => sub {1},
Subroutine __ANON__: called CC=1 SCAR=0.0
37 1 );
38  
39 0 ▶sub _build_pinger {
Subroutine _build_pinger: not called CC=3 SCAR=24.8
40 0 my $self = shift;
41 0 ▶ my $pinger = AnyEvent::Ping->new (
Branch: 2 branches
BranchTrueFalseTotal
$self->has_ping_timeout ? : 0 0 0
$self->has_ping_interval ? : 0 0 0
42 $self->has_ping_timeout ? ( timeout => $self->ping_timeout ) : (),
43 $self->has_ping_interval ? ( interval => $self->ping_interval ) : (),
44 );
45  
46 0 return $pinger;
47 }
48  
49 1 ▶sub check {
Subroutine check: called CC=3 SCAR=11.1
Pod undocumented
50 1 my $self = shift;
51 1 my @hosts = @{ $self->hosts };
52 1 my $pinger = $self->pinger;
53  
54 1 foreach my $host (@hosts) {
55 3 ▶ $self->has_on_before
Branch: 1 branch
BranchTrueFalseTotal
$self->has_on_before and $self->on_before->($self, $host) 0 3 3
56 and $self->on_before->( $self, $host );
57  
58 3 ▶ $pinger->ping( $host, $self->count, sub {
Subroutine __ANON__: called CC=5 SCAR=16.5
59 3 my $results = shift;
60  
61 3 ▶ $self->has_on_result
Branch: 1 branch
BranchTrueFalseTotal
$self->has_on_result and $self->on_result->($self, $host, $results) 3 0 3
62 and $self->on_result->( $self, $host, $results );
63  
64 3 ▶ if ( first { $_->[0] eq 'OK' } @{$results} ) {
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if (&first(sub { $_->[0] eq 'OK'; } , @{$results;})) { } 2 1 3
65 2 ▶ $self->has_on_success
Branch: 1 branch
BranchTrueFalseTotal
$self->has_on_success and $self->on_success->($self, $host, $results) 2 0 2
66 and $self->on_success->( $self, $host, $results );
67 } else {
68 1 ▶ $self->has_on_fail
Branch: 1 branch
BranchTrueFalseTotal
$self->has_on_fail and $self->on_fail->($self, $host, $results) 1 0 1
69 and $self->on_fail->( $self, $host, $results );
70 }
71 3 } );
72 }
73  
74 1 return 0;
75 }
76  
77 1 1;
78  
79 __END__
« Juno/Check/RawCommand.pm ↑ Summary Juno/Check/SNMP.pm »