mirror of
https://github.com/librenms/librenms.git
synced 2024-09-21 18:38:25 +00:00
Fix Device Mouseover View (#10962)
* fix device mouseover view * move function to App/Models/Device.php * load OS Setting in Device Constructor * retrigger travis
This commit is contained in:
parent
15e29a49b1
commit
299da2600e
@ -34,6 +34,7 @@ class Device extends BaseModel
|
||||
public static function boot()
|
||||
{
|
||||
parent::boot();
|
||||
self::loadAllOs(true);
|
||||
|
||||
static::deleting(function (Device $device) {
|
||||
// delete related data
|
||||
@ -204,6 +205,43 @@ class Device extends BaseModel
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
public static function loadAllOs($existing = false, $cached = true)
|
||||
{
|
||||
$install_dir = \LibreNMS\Config::get('install_dir');
|
||||
$cache_file = $install_dir . '/cache/os_defs.cache';
|
||||
if ($cached && is_file($cache_file) && (time() - filemtime($cache_file) < \LibreNMS\Config::get('os_def_cache_time'))) {
|
||||
// Cached
|
||||
$os_defs = unserialize(file_get_contents($cache_file));
|
||||
if ($existing) {
|
||||
// remove unneeded os
|
||||
$os_defs = array_diff_key($os_defs, self::distinct('os')->get('os')->toArray());
|
||||
}
|
||||
\LibreNMS\Config::set('os', array_replace_recursive($os_defs, \LibreNMS\Config::get('os')));
|
||||
} else {
|
||||
// load from yaml
|
||||
if ($existing) {
|
||||
$os_list = array_map(function ($os) use ($install_dir) {
|
||||
return $install_dir . '/includes/definitions/' . $os . '.yaml';
|
||||
}, self::distinct('os')->get('os')->toArray());
|
||||
} else {
|
||||
$os_list = glob($install_dir . '/includes/definitions/*.yaml');
|
||||
}
|
||||
foreach ($os_list as $file) {
|
||||
if (is_readable($file)) {
|
||||
$tmp = \Symfony\Component\Yaml\Yaml::parse(file_get_contents($file));
|
||||
\LibreNMS\Config::set("os.{$tmp['os']}", array_replace_recursive($tmp, \LibreNMS\Config::get("os.{$tmp['os']}", [])));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the shortened display name of this device.
|
||||
* Length is always overridden by shorthost_target_length.
|
||||
|
@ -1497,37 +1497,7 @@ function load_os(&$device)
|
||||
*/
|
||||
function load_all_os($existing = false, $cached = true)
|
||||
{
|
||||
$install_dir = Config::get('install_dir');
|
||||
$cache_file = $install_dir . '/cache/os_defs.cache';
|
||||
|
||||
if ($cached && is_file($cache_file) && (time() - filemtime($cache_file) < Config::get('os_def_cache_time'))) {
|
||||
// Cached
|
||||
$os_defs = unserialize(file_get_contents($cache_file));
|
||||
|
||||
if ($existing) {
|
||||
// remove unneeded os
|
||||
$os_defs = array_diff_key($os_defs, dbFetchColumn('SELECT DISTINCT(`os`) FROM `devices`'));
|
||||
}
|
||||
|
||||
Config::set('os', array_replace_recursive($os_defs, Config::get('os')));
|
||||
} else {
|
||||
// load from yaml
|
||||
if ($existing) {
|
||||
$os_list = array_map(function ($os) use ($install_dir) {
|
||||
return $install_dir . '/includes/definitions/' . $os . '.yaml';
|
||||
}, dbFetchColumn('SELECT DISTINCT(`os`) FROM `devices`'));
|
||||
} else {
|
||||
$os_list = glob($install_dir . '/includes/definitions/*.yaml');
|
||||
}
|
||||
|
||||
foreach ($os_list as $file) {
|
||||
if (is_readable($file)) {
|
||||
$tmp = Symfony\Component\Yaml\Yaml::parse(file_get_contents($file));
|
||||
|
||||
Config::set("os.{$tmp['os']}", array_replace_recursive($tmp, Config::get("os.{$tmp['os']}", [])));
|
||||
}
|
||||
}
|
||||
}
|
||||
Device::loadAllOs($existing, $cached);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user