You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ngcpcfg/lib/get_default_pingnodes

31 lines
758 B

[%
# vi: ft=tt2
# Returns a list of IPs to ping.
#
# @param argv.dns A boolean selecting whether to add DNS IPs.
# @return out List of pingnodes.
-%]
[% PERL -%]
my $gateway = (split(" ", `ip route | grep default`))[2];
my @nodes = ($gateway);
[% IF argv.dns == 'yes' %]
my @dnsnodes = (split(" ", `grep -v '^#' /etc/resolv.conf | grep nameserver | cut -f2 -d' '|xargs`));
foreach my $host (@dnsnodes) {
my $res = `/bin/ping -c 1 -s 164 $host -W 1 2>/dev/null`;
if ($res =~ '1 received') {
if ($res =~ 'truncated') {
print "#$host reply truncated\n";
} else {
push(@nodes, $host);
}
} else {
print "# $host error\n";
}
}
[% END %]
$stash->set(out => \@nodes);
[% END -%]