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')
|
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);
|
$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
|
// build the command
|
||||||
$cmd = [
|
$cmd = array_merge($cmd, [
|
||||||
Config::get($fping_name, $fping_name),
|
|
||||||
'-e',
|
'-e',
|
||||||
'-q',
|
'-q',
|
||||||
'-c',
|
'-c',
|
||||||
@@ -58,7 +62,7 @@ class Fping
|
|||||||
'-t',
|
'-t',
|
||||||
max($timeout, $interval),
|
max($timeout, $interval),
|
||||||
$host
|
$host
|
||||||
];
|
]);
|
||||||
|
|
||||||
$process = app()->make(Process::class, ['command' => $cmd]);
|
$process = app()->make(Process::class, ['command' => $cmd]);
|
||||||
Log::debug('[FPING] ' . $process->getCommandLine() . PHP_EOL);
|
Log::debug('[FPING] ' . $process->getCommandLine() . PHP_EOL);
|
||||||
|
@@ -40,7 +40,7 @@ class Programs extends BaseValidation
|
|||||||
public function validate(Validator $validator)
|
public function validate(Validator $validator)
|
||||||
{
|
{
|
||||||
// Check programs
|
// Check programs
|
||||||
$bins = array('fping', 'fping6', 'rrdtool', 'snmpwalk', 'snmpget', 'snmpgetnext', 'snmpbulkwalk');
|
$bins = array('fping', 'rrdtool', 'snmpwalk', 'snmpget', 'snmpgetnext', 'snmpbulkwalk');
|
||||||
foreach ($bins as $bin) {
|
foreach ($bins as $bin) {
|
||||||
if (!($cmd = $this->findExecutable($bin))) {
|
if (!($cmd = $this->findExecutable($bin))) {
|
||||||
$validator->fail(
|
$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: " .
|
"Install $bin or manually set the path to $bin by placing the following in config.php: " .
|
||||||
"\$config['$bin'] = '/path/to/$bin';"
|
"\$config['$bin'] = '/path/to/$bin';"
|
||||||
);
|
);
|
||||||
} elseif (in_array($bin, array('fping', 'fping6'))) {
|
} elseif ($bin == 'fping') {
|
||||||
$this->extraFpingChecks($validator, $bin, $cmd);
|
$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');
|
$fping6 = $this->findExecutable('fping6');
|
||||||
$validator->execAsUser("$cmd $target 2>&1", $output, $return);
|
$fping6 = (!is_executable($fping6) && is_executable($fping)) ? "$fping -6" : $fping6;
|
||||||
|
|
||||||
|
$validator->execAsUser("$fping6 ::1 2>&1", $output, $return);
|
||||||
$output = implode(" ", $output);
|
$output = implode(" ", $output);
|
||||||
|
|
||||||
if ($return === 0 && $output == "$target is alive") {
|
if ($return === 0 && $output == "::1 is alive") {
|
||||||
return; // fping is working
|
return; // fping is working
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($output == '::1 address not found') {
|
if ($output == '::1 address not found') {
|
||||||
$validator->warn("fping6 does not have IPv6 support?!?!");
|
$validator->warn("fping does not have IPv6 support?!?!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -74,8 +77,27 @@ class Programs extends BaseValidation
|
|||||||
return;
|
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(
|
$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')) {
|
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')) {
|
if (is_null($matches) || !Str::contains($matches[1], 'cap_net_raw+ep')) {
|
||||||
$validator->fail(
|
$validator->fail(
|
||||||
"$bin should have CAP_NET_RAW!",
|
"$cmd should have CAP_NET_RAW!",
|
||||||
"setcap cap_net_raw+ep $cmd"
|
"setcap cap_net_raw+ep $cmd"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} elseif (!(fileperms($cmd) & 2048)) {
|
} 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