fix: ping fails on servers that don't set PATH in cron (#7603)

* fix: ping fails on servers that don't set PATH in cron
Find the full path to fping and persist it in the database.
Adds the ability to persist settings with Config::set()

* Add ability to set webui settings.
No display of for paths, because it would be inconsistent.
This commit is contained in:
Tony Murray
2017-11-01 16:56:47 -05:00
committed by Neil Lathwood
parent 47b999cebd
commit fb45f00340
5 changed files with 76 additions and 3 deletions

View File

@@ -42,8 +42,8 @@ $config['db_socket'] = null;
$config['own_hostname'] = 'localhost';
// Location of executables
$config['fping'] = 'fping';
$config['fping6'] = 'fping6';
//$config['fping'] = '/usr/sbin/fping';
//$config['fping6'] = '/usr/sbin/fping6';
$config['fping_options']['retries'] = 3;
$config['fping_options']['timeout'] = 500;
$config['fping_options']['count'] = 3;

View File

@@ -2318,3 +2318,23 @@ function return_num($entry)
return $num_response[0];
}
}
/**
* Locate the actual path of a binary
*
* @param $binary
* @return mixed
*/
function locate_binary($binary)
{
if (!str_contains($binary, '/')) {
$output = `whereis -b $binary`;
$target = trim(substr($output, strpos($output, ':') + 1));
if (file_exists($target)) {
return $target;
}
}
return $binary;
}

View File

@@ -23,6 +23,8 @@
* @author Neil Lathwood <neil@lathwood.co.uk>
*/
use LibreNMS\Config;
if (empty($config['email_from'])) {
$config['email_from'] = '"' . $config['project_name'] . '" <' . $config['email_user'] . '@' . php_uname('n') . '>';
}
@@ -42,3 +44,10 @@ if ($config['secure_cookies']) {
if ($config['rrdgraph_real_95th']) {
$config['rrdgraph_real_percentile'] = $config['rrdgraph_real_95th'];
}
// make sure we have full path to binaries in case PATH isn't set
foreach (array('fping', 'fping6') as $bin) {
if (!is_executable(Config::get($bin))) {
Config::set($bin, locate_binary($bin), true, $bin, "Path to $bin", 'external', 'paths');
}
}