mirror of
https://github.com/ovh/the-bastion.git
synced 2025-09-05 20:44:16 +08:00
fix: ping: force a deadline, and restore default sighandlers
This commit is contained in:
parent
884b4bbaf0
commit
4f99c4fe6c
2 changed files with 14 additions and 5 deletions
|
@ -25,7 +25,7 @@ Usage: --osh SCRIPT_NAME [--host HOST] [-c COUNT] [-s PKTSZ] [-t TTL] [-w TIMEOU
|
||||||
--host HOST Remote host to ping
|
--host HOST Remote host to ping
|
||||||
-c COUNT Number of pings to send (default: infinite)
|
-c COUNT Number of pings to send (default: infinite)
|
||||||
-t TTL TTL to set in the ICMP packet (default: OS dependent)
|
-t TTL TTL to set in the ICMP packet (default: OS dependent)
|
||||||
-w TIMEOUT Exit unconditionally after this amount of seconds
|
-w TIMEOUT Exit unconditionally after this amount of seconds (default & max: 86400)
|
||||||
EOF
|
EOF
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -45,6 +45,11 @@ if (not $host) {
|
||||||
osh_exit 'ERR_MISSING_PARAMETER', "Missing required host parameter";
|
osh_exit 'ERR_MISSING_PARAMETER', "Missing required host parameter";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# restore default handlers (exit) for HUP and PIPE, we don't want to have this
|
||||||
|
# plugin looping endlessly in the void when there's no longer a terminal attached
|
||||||
|
$SIG{'PIPE'} = 'DEFAULT';
|
||||||
|
$SIG{'HUP'} = 'DEFAULT';
|
||||||
|
|
||||||
my @command = qw{ ping };
|
my @command = qw{ ping };
|
||||||
if ($count and $count > 0) {
|
if ($count and $count > 0) {
|
||||||
push @command, ('-c', $count);
|
push @command, ('-c', $count);
|
||||||
|
@ -55,9 +60,13 @@ if ($packetsize and $packetsize > 0 and $packetsize < 10000) {
|
||||||
if ($ttl and $ttl > 0 and $ttl < 256) {
|
if ($ttl and $ttl > 0 and $ttl < 256) {
|
||||||
push @command, ('-t', $ttl);
|
push @command, ('-t', $ttl);
|
||||||
}
|
}
|
||||||
if ($deadline and $deadline > 0 and $deadline <= 3600) {
|
|
||||||
|
# ensure there's always a deadline, to avoid having a plugin running for months,
|
||||||
|
# especially because this one caches stdout to be able to compute stats at the
|
||||||
|
# end, and return these in the JSON output
|
||||||
|
$deadline = 86400 if (!$deadline || $deadline < 0 || $deadline > 86400);
|
||||||
push @command, (OVH::Bastion::is_freebsd() ? '-t' : '-w', $deadline);
|
push @command, (OVH::Bastion::is_freebsd() ? '-t' : '-w', $deadline);
|
||||||
}
|
|
||||||
push @command, $host;
|
push @command, $host;
|
||||||
|
|
||||||
osh_info "Pinging $host...";
|
osh_info "Pinging $host...";
|
||||||
|
|
|
@ -28,5 +28,5 @@ Ping a remote host from the bastion
|
||||||
|
|
||||||
.. option:: -w TIMEOUT
|
.. option:: -w TIMEOUT
|
||||||
|
|
||||||
Exit unconditionally after this amount of seconds
|
Exit unconditionally after this amount of seconds (default & max: 86400)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue