line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# |
2
|
|
|
|
|
|
|
# $Id$ |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# network::ping Brik |
5
|
|
|
|
|
|
|
# |
6
|
|
|
|
|
|
|
package Metabrik::Network::Ping; |
7
|
1
|
|
|
1
|
|
704
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
29
|
|
8
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
26
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
6
|
use base qw(Metabrik::Shell::Command Metabrik::System::Package); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
397
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub brik_properties { |
13
|
|
|
|
|
|
|
return { |
14
|
0
|
|
|
0
|
1
|
|
revision => '$Revision$', |
15
|
|
|
|
|
|
|
tags => [ qw(unstable) ], |
16
|
|
|
|
|
|
|
author => 'GomoR ', |
17
|
|
|
|
|
|
|
license => 'http://opensource.org/licenses/BSD-3-Clause', |
18
|
|
|
|
|
|
|
attributes => { |
19
|
|
|
|
|
|
|
try => [ qw(count) ], |
20
|
|
|
|
|
|
|
timeout => [ qw(seconds) ], |
21
|
|
|
|
|
|
|
}, |
22
|
|
|
|
|
|
|
attributes_default => { |
23
|
|
|
|
|
|
|
try => 2, |
24
|
|
|
|
|
|
|
timeout => 5, |
25
|
|
|
|
|
|
|
ignore_error => 0, # We need return code from ping command |
26
|
|
|
|
|
|
|
}, |
27
|
|
|
|
|
|
|
commands => { |
28
|
|
|
|
|
|
|
install => [ ], # Inherited |
29
|
|
|
|
|
|
|
is_alive => [ qw(host try|OPTIONAL timeout|OPTIONAL) ], |
30
|
|
|
|
|
|
|
}, |
31
|
|
|
|
|
|
|
require_modules => { |
32
|
|
|
|
|
|
|
'Metabrik::System::Os' => [ ], |
33
|
|
|
|
|
|
|
'Metabrik::Network::Linux::Ping' => [ ], |
34
|
|
|
|
|
|
|
'Metabrik::Network::Freebsd::Ping' => [ ], |
35
|
|
|
|
|
|
|
}, |
36
|
|
|
|
|
|
|
require_binaries => { |
37
|
|
|
|
|
|
|
ping => [ ], |
38
|
|
|
|
|
|
|
}, |
39
|
|
|
|
|
|
|
need_packages => { |
40
|
|
|
|
|
|
|
ubuntu => [ qw(iputils-ping) ], |
41
|
|
|
|
|
|
|
debian => [ qw(iputils-ping) ], |
42
|
|
|
|
|
|
|
kali => [ qw(iputils-ping) ], |
43
|
|
|
|
|
|
|
}, |
44
|
|
|
|
|
|
|
}; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
# |
48
|
|
|
|
|
|
|
# Sends ICMP echo-requests $try number of times or until $timeout seconds occurs. |
49
|
|
|
|
|
|
|
# |
50
|
|
|
|
|
|
|
sub is_alive { |
51
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
52
|
0
|
|
|
|
|
|
my ($host, $try, $timeout) = @_; |
53
|
|
|
|
|
|
|
|
54
|
0
|
|
0
|
|
|
|
$try ||= $self->try; |
55
|
0
|
|
0
|
|
|
|
$timeout ||= $self->timeout; |
56
|
0
|
0
|
|
|
|
|
$self->brik_help_run_undef_arg('is_alive', $host) or return; |
57
|
|
|
|
|
|
|
|
58
|
0
|
|
|
|
|
|
my $np; |
59
|
0
|
0
|
|
|
|
|
my $os = Metabrik::System::Os->new_from_brik_init($self) or return; |
60
|
0
|
0
|
|
|
|
|
if ($os->is_linux) { |
|
|
0
|
|
|
|
|
|
61
|
0
|
0
|
|
|
|
|
$np = Metabrik::Network::Linux::Ping->new_from_brik_init($self) or return; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
elsif ($os->is_freebsd) { |
64
|
0
|
0
|
|
|
|
|
$np = Metabrik::Network::Freebsd::Ping->new_from_brik_init($self) or return; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
else { |
67
|
0
|
|
|
|
|
|
return $self->log->error("is_alive: OS unsupported"); |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
0
|
|
|
|
|
|
return $np->is_alive($host, $try, $timeout); |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
1; |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
__END__ |