mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Merge pull request #11868 from murrant/fping6
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) ? [$fping6] : [$fping, '-6'];
|
||||
}
|
||||
|
||||
// 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,24 +48,27 @@ 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'))) {
|
||||
$this->extraFpingChecks($validator, $bin, $cmd);
|
||||
} elseif ($bin == 'fping') {
|
||||
$this->extraFpingChecks($validator, $cmd);
|
||||
$this->checkFping6($validator, $cmd);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function extraFpingChecks(Validator $validator, $bin, $cmd)
|
||||
public function checkFping6(Validator $validator, $fping)
|
||||
{
|
||||
$target = ($bin == 'fping' ? '127.0.0.1' : '::1');
|
||||
$validator->execAsUser("$cmd $target 2>&1", $output, $return);
|
||||
$fping6 = $this->findExecutable('fping6');
|
||||
$fping6 = (!is_executable($fping6) && is_executable($fping)) ? "$fping -6" : $fping6;
|
||||
|
||||
$validator->execAsUser("$fping6 ::1 2>&1", $output, $return);
|
||||
$output = implode(" ", $output);
|
||||
|
||||
if ($return === 0 && $output == "$target is alive") {
|
||||
if ($return === 0 && $output == "::1 is alive") {
|
||||
return; // fping is working
|
||||
}
|
||||
|
||||
if ($output == '::1 address not found') {
|
||||
$validator->warn("fping6 does not have IPv6 support?!?!");
|
||||
$validator->warn("fping does not have IPv6 support?!?!");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -74,8 +77,27 @@ class Programs extends BaseValidation
|
||||
return;
|
||||
}
|
||||
|
||||
if (substr($fping6, -6) == 'fping6') {
|
||||
$this->failFping($validator, $fping6, $output);
|
||||
}
|
||||
}
|
||||
|
||||
public function extraFpingChecks(Validator $validator, $cmd)
|
||||
{
|
||||
$validator->execAsUser("$cmd 127.0.0.1 2>&1", $output, $return);
|
||||
$output = implode(" ", $output);
|
||||
|
||||
if ($return === 0 && $output == "127.0.0.1 is alive") {
|
||||
return; // fping is working
|
||||
}
|
||||
|
||||
$this->failFping($validator, $cmd, $output);
|
||||
}
|
||||
|
||||
private function failFping($validator, $cmd, $output)
|
||||
{
|
||||
$validator->fail(
|
||||
"$bin could not be executed. $bin must have CAP_NET_RAW capability (getcap) or suid. Selinux exlusions may be required.\n ($output)"
|
||||
"$cmd could not be executed. $cmd must have CAP_NET_RAW capability (getcap) or suid. Selinux exclusions may be required.\n ($output)"
|
||||
);
|
||||
|
||||
if ($getcap = $this->findExecutable('getcap')) {
|
||||
@@ -84,12 +106,12 @@ class Programs extends BaseValidation
|
||||
|
||||
if (is_null($matches) || !Str::contains($matches[1], 'cap_net_raw+ep')) {
|
||||
$validator->fail(
|
||||
"$bin should have CAP_NET_RAW!",
|
||||
"$cmd should have CAP_NET_RAW!",
|
||||
"setcap cap_net_raw+ep $cmd"
|
||||
);
|
||||
}
|
||||
} elseif (!(fileperms($cmd) & 2048)) {
|
||||
$validator->fail("$bin should be suid!", "chmod u+s $cmd");
|
||||
$validator->fail("$cmd should be suid!", "chmod u+s $cmd");
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user