mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Make fping work when fping6 is not present
This commit is contained in:
@@ -42,13 +42,17 @@ class Fping
|
||||
*/
|
||||
public function ping($host, $count = 3, $interval = 1000, $timeout = 500, $address_family = 'ipv4')
|
||||
{
|
||||
// Default to ipv4
|
||||
$fping_name = $address_family == 'ipv6' ? 'fping6' : 'fping';
|
||||
$interval = max($interval, 20);
|
||||
|
||||
$fping = Config::get('fping');
|
||||
$cmd = [$fping];
|
||||
if ($address_family == 'ipv6') {
|
||||
$fping6 = Config::get('fping6');
|
||||
$cmd = (!is_executable($fping6) && is_executable($fping)) ? [$fping, '-6'] : [$fping6];
|
||||
}
|
||||
|
||||
// build the command
|
||||
$cmd = [
|
||||
Config::get($fping_name, $fping_name),
|
||||
$cmd = array_merge($cmd, [
|
||||
'-e',
|
||||
'-q',
|
||||
'-c',
|
||||
@@ -58,7 +62,7 @@ class Fping
|
||||
'-t',
|
||||
max($timeout, $interval),
|
||||
$host
|
||||
];
|
||||
]);
|
||||
|
||||
$process = app()->make(Process::class, ['command' => $cmd]);
|
||||
Log::debug('[FPING] ' . $process->getCommandLine() . PHP_EOL);
|
||||
|
||||
@@ -40,7 +40,7 @@ class Programs extends BaseValidation
|
||||
public function validate(Validator $validator)
|
||||
{
|
||||
// Check programs
|
||||
$bins = array('fping', 'fping6', 'rrdtool', 'snmpwalk', 'snmpget', 'snmpgetnext', 'snmpbulkwalk');
|
||||
$bins = array('fping', 'rrdtool', 'snmpwalk', 'snmpget', 'snmpgetnext', 'snmpbulkwalk');
|
||||
foreach ($bins as $bin) {
|
||||
if (!($cmd = $this->findExecutable($bin))) {
|
||||
$validator->fail(
|
||||
@@ -48,16 +48,28 @@ class Programs extends BaseValidation
|
||||
"Install $bin or manually set the path to $bin by placing the following in config.php: " .
|
||||
"\$config['$bin'] = '/path/to/$bin';"
|
||||
);
|
||||
} elseif (in_array($bin, array('fping', 'fping6'))) {
|
||||
} elseif ($bin == 'fping') {
|
||||
$this->extraFpingChecks($validator, $bin, $cmd);
|
||||
|
||||
$fping6 = $this->findExecutable('fping6');
|
||||
$fping6 = (!is_executable($fping6) && is_executable($cmd)) ? 'fping -6' : 'fping6';
|
||||
$this->extraFpingChecks($validator, 'fping6', $fping6);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function extraFpingChecks(Validator $validator, $bin, $cmd)
|
||||
{
|
||||
$target = ($bin == 'fping' ? '127.0.0.1' : '::1');
|
||||
$validator->execAsUser("$cmd $target 2>&1", $output, $return);
|
||||
if ($bin == 'fping') {
|
||||
$target = '127.0.0.1';
|
||||
$extra = '';
|
||||
} else {
|
||||
$target = '::1';
|
||||
$fping6 = $this->findExecutable('fping6');
|
||||
$extra = (!is_executable($fping6) && is_executable($cmd)) ? ' -6' : '';
|
||||
}
|
||||
|
||||
$validator->execAsUser("$cmd$extra $target 2>&1", $output, $return);
|
||||
$output = implode(" ", $output);
|
||||
|
||||
if ($return === 0 && $output == "$target is alive") {
|
||||
|
||||
Reference in New Issue
Block a user