line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# |
2
|
|
|
|
|
|
|
# $Id$ |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# network::linux::ping Brik |
5
|
|
|
|
|
|
|
# |
6
|
|
|
|
|
|
|
package Metabrik::Network::Linux::Ping; |
7
|
1
|
|
|
1
|
|
667
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
28
|
|
8
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
27
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
4
|
use base qw(Metabrik::Shell::Command Metabrik::System::Package); |
|
1
|
|
|
|
|
12
|
|
|
1
|
|
|
|
|
349
|
|
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_binaries => { |
32
|
|
|
|
|
|
|
ping => [ ], |
33
|
|
|
|
|
|
|
}, |
34
|
|
|
|
|
|
|
need_packages => { |
35
|
|
|
|
|
|
|
ubuntu => [ qw(iputils-ping) ], |
36
|
|
|
|
|
|
|
debian => [ qw(iputils-ping) ], |
37
|
|
|
|
|
|
|
kali => [ qw(iputils-ping) ], |
38
|
|
|
|
|
|
|
}, |
39
|
|
|
|
|
|
|
}; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
# |
43
|
|
|
|
|
|
|
# Sends ICMP echo-requests $try number of times or until $timeout seconds occurs. |
44
|
|
|
|
|
|
|
# |
45
|
|
|
|
|
|
|
sub is_alive { |
46
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
47
|
0
|
|
|
|
|
|
my ($host, $try, $timeout) = @_; |
48
|
|
|
|
|
|
|
|
49
|
0
|
|
0
|
|
|
|
$try ||= $self->try; |
50
|
0
|
|
0
|
|
|
|
$timeout ||= $self->timeout; |
51
|
0
|
0
|
|
|
|
|
$self->brik_help_run_undef_arg('is_alive', $host) or return; |
52
|
|
|
|
|
|
|
|
53
|
0
|
|
|
|
|
|
my $cmd = "ping -c $try -W $timeout $host > /dev/null 2>&1"; |
54
|
|
|
|
|
|
|
|
55
|
0
|
0
|
|
|
|
|
my $r = $self->system($cmd) or return; |
56
|
0
|
0
|
|
|
|
|
if ($r == 1) { |
57
|
0
|
|
|
|
|
|
return 1; # Host is alive |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
|
return 0; # Host not alive |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
1; |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
__END__ |