mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Fix various issues with loading os definitions (#11640)
* Ping only device doesn't display if os was set to something, ping os wasn't loaded and we try to get overview graphs from it. * Fix snmp_disable device page load error When other os is set. * Revamp os setting loading the only safe way to access is Config::getOsSetting() * Remove getOsSetting fallback behavior Most instances don't use it and it can have unexpected results Config::getOsSetting('blah', 'group') == 'librenms' * refactor and remove unneeded load_os/loadOs calls now since getOsSetting automatically loads it. * restore unix overview graphs, they are different small cleanups * fix
This commit is contained in:
@@ -16,12 +16,12 @@
|
||||
* the source code distribution for details.
|
||||
*/
|
||||
|
||||
use App\Models\Device;
|
||||
use LibreNMS\Config;
|
||||
use LibreNMS\Exceptions\InvalidIpException;
|
||||
use LibreNMS\Util\Git;
|
||||
use LibreNMS\Util\IP;
|
||||
use LibreNMS\Util\Laravel;
|
||||
use LibreNMS\Util\OS;
|
||||
|
||||
function generate_priority_label($priority)
|
||||
{
|
||||
@@ -1000,7 +1000,7 @@ function version_info($remote = false)
|
||||
curl_setopt($api, CURLOPT_CONNECTTIMEOUT, 5);
|
||||
$output['github'] = json_decode(curl_exec($api), true);
|
||||
}
|
||||
list($local_sha, $local_date) = explode('|', rtrim(`git show --pretty='%H|%ct' -s HEAD`));
|
||||
[$local_sha, $local_date] = explode('|', rtrim(`git show --pretty='%H|%ct' -s HEAD`));
|
||||
$output['local_sha'] = $local_sha;
|
||||
$output['local_date'] = $local_date;
|
||||
$output['local_branch'] = rtrim(`git rev-parse --abbrev-ref HEAD`);
|
||||
@@ -1217,7 +1217,7 @@ function ResolveGlues($tables, $target, $x = 0, $hist = array(), $last = array()
|
||||
if (sizeof($glues) == 1 && $glues[0]['COLUMN_NAME'] != $target) {
|
||||
//Search for new candidates to expand
|
||||
$ntables = array();
|
||||
list($tmp) = explode('_', $glues[0]['COLUMN_NAME'], 2);
|
||||
[$tmp] = explode('_', $glues[0]['COLUMN_NAME'], 2);
|
||||
$ntables[] = $tmp;
|
||||
$ntables[] = $tmp.'s';
|
||||
$tmp = dbFetchRows('SELECT TABLE_NAME FROM information_schema.TABLES WHERE TABLE_NAME LIKE "'.substr($table, 0, -1).'_%" && TABLE_NAME != "'.$table.'"');
|
||||
@@ -1233,7 +1233,7 @@ function ResolveGlues($tables, $target, $x = 0, $hist = array(), $last = array()
|
||||
if ($glue['COLUMN_NAME'] == $target) {
|
||||
return array_merge($last, array($table.'.'.$target));
|
||||
} else {
|
||||
list($tmp) = explode('_', $glue['COLUMN_NAME']);
|
||||
[$tmp] = explode('_', $glue['COLUMN_NAME']);
|
||||
$tmp .= 's';
|
||||
if (!in_array($tmp, $tables) && !in_array($tmp, $hist)) {
|
||||
//Expand table
|
||||
@@ -1361,13 +1361,7 @@ function load_os(&$device)
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Config::get("os.{$device['os']}.definition_loaded")) {
|
||||
$tmp_os = Symfony\Component\Yaml\Yaml::parse(
|
||||
file_get_contents(Config::get('install_dir') . '/includes/definitions/' . $device['os'] . '.yaml')
|
||||
);
|
||||
|
||||
Config::set("os.{$device['os']}", array_replace_recursive($tmp_os, Config::get("os.{$device['os']}", [])));
|
||||
}
|
||||
\LibreNMS\Util\OS::loadDefinition($device['os']);
|
||||
|
||||
// Set type to a predefined type for the OS if it's not already set
|
||||
$loaded_os_type = Config::get("os.{$device['os']}.type");
|
||||
@@ -1383,50 +1377,6 @@ function load_os(&$device)
|
||||
} else {
|
||||
unset($device['os_group']);
|
||||
}
|
||||
|
||||
Config::set("os.{$device['os']}.definition_loaded", true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load all OS, optionally load just the OS used by existing devices
|
||||
* Default cache time is 1 day. Controlled by os_def_cache_time.
|
||||
*
|
||||
* @param bool $existing Only load OS that have existing OS in the database
|
||||
* @param bool $cached Load os definitions from the cache file
|
||||
*/
|
||||
function load_all_os($existing = false, $cached = true)
|
||||
{
|
||||
Device::loadAllOs($existing, $cached);
|
||||
}
|
||||
|
||||
/**
|
||||
* * Update the OS cache file cache/os_defs.cache
|
||||
* @param bool $force
|
||||
* @return bool true if the cache was updated
|
||||
*/
|
||||
function update_os_cache($force = false)
|
||||
{
|
||||
$install_dir = Config::get('install_dir');
|
||||
$cache_file = "$install_dir/cache/os_defs.cache";
|
||||
$cache_keep_time = Config::get('os_def_cache_time', 86400) - 7200; // 2hr buffer
|
||||
|
||||
if ($force === true || !is_file($cache_file) || time() - filemtime($cache_file) > $cache_keep_time) {
|
||||
d_echo('Updating os_def.cache... ');
|
||||
|
||||
// remove previously cached os settings and replace with user settings
|
||||
$config = ['os' => []]; // local $config variable, not global
|
||||
include "$install_dir/config.php";
|
||||
Config::set('os', $config['os']);
|
||||
|
||||
// load the os defs fresh from cache (merges with existing OS settings)
|
||||
load_all_os(false, false);
|
||||
|
||||
file_put_contents($cache_file, serialize(Config::get('os')));
|
||||
d_echo("Done\n");
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user