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:
parent
0b68c70a97
commit
d5a52ca4eb
|
@ -111,7 +111,6 @@ class Device
|
|||
return new \App\Models\Device;
|
||||
}
|
||||
|
||||
$device->loadOs();
|
||||
$this->devices[$device->device_id] = $device;
|
||||
return $device;
|
||||
}
|
||||
|
|
|
@ -170,7 +170,6 @@ class Config
|
|||
|
||||
/**
|
||||
* Get a setting from the $config['os'] array using the os of the given device
|
||||
* If that is not set, fallback to the same global config key
|
||||
*
|
||||
* @param string $os The os name
|
||||
* @param string $key period separated config variable name
|
||||
|
@ -180,21 +179,19 @@ class Config
|
|||
public static function getOsSetting($os, $key, $default = null)
|
||||
{
|
||||
if ($os) {
|
||||
\LibreNMS\Util\OS::loadDefinition($os);
|
||||
|
||||
if (isset(self::$config['os'][$os][$key])) {
|
||||
return self::$config['os'][$os][$key];
|
||||
}
|
||||
|
||||
if (!Str::contains($key, '.')) {
|
||||
return self::get($key, $default);
|
||||
}
|
||||
|
||||
$os_key = "os.$os.$key";
|
||||
if (self::has($os_key)) {
|
||||
return self::get($os_key);
|
||||
}
|
||||
}
|
||||
|
||||
return self::get($key, $default);
|
||||
return $default;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -210,7 +207,7 @@ class Config
|
|||
public static function getCombined($os, $key, $default = array())
|
||||
{
|
||||
if (!self::has($key)) {
|
||||
return self::get("os.$os.$key", $default);
|
||||
return self::getOsSetting($os, $key, $default);
|
||||
}
|
||||
|
||||
if (!isset(self::$config['os'][$os][$key])) {
|
||||
|
|
|
@ -81,4 +81,18 @@ class Graph
|
|||
{
|
||||
return Config::get("graph_types.$type.$subtype.section") == 'mib';
|
||||
}
|
||||
|
||||
public static function getOverviewGraphsForDevice($device)
|
||||
{
|
||||
if ($device->snmp_disable) {
|
||||
return Config::getOsSetting('ping', 'over');
|
||||
}
|
||||
|
||||
if ($graphs = Config::getOsSetting($device->os, 'over')) {
|
||||
return $graphs;
|
||||
}
|
||||
|
||||
$os_group = Config::getOsSetting($device->os, 'group');
|
||||
return Config::get("os_group.$os_group.over", Config::get('os.default.over'));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,115 @@
|
|||
<?php
|
||||
/**
|
||||
* OS.php
|
||||
*
|
||||
* OS related functions (may belong in LibreNMS/OS, but here for now)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @package LibreNMS
|
||||
* @link http://librenms.org
|
||||
* @copyright 2020 Tony Murray
|
||||
* @author Tony Murray <murraytony@gmail.com>
|
||||
*/
|
||||
|
||||
namespace LibreNMS\Util;
|
||||
|
||||
use App\Models\Device;
|
||||
use LibreNMS\Config;
|
||||
use LibreNMS\DB\Eloquent;
|
||||
use Log;
|
||||
use Symfony\Component\Yaml\Yaml;
|
||||
|
||||
class OS
|
||||
{
|
||||
/**
|
||||
* Load os from yaml into config if not already loaded, preserving user os config
|
||||
* @param string $os
|
||||
*/
|
||||
public static function loadDefinition($os)
|
||||
{
|
||||
if (!Config::get("os.$os.definition_loaded")) {
|
||||
$yaml_file = base_path("/includes/definitions/$os.yaml");
|
||||
if (file_exists($yaml_file)) {
|
||||
$os_def = Yaml::parse(file_get_contents($yaml_file));
|
||||
|
||||
Config::set("os.$os", array_replace_recursive($os_def, Config::get("os.$os", [])));
|
||||
Config::set("os.$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
|
||||
*/
|
||||
public static function loadAllDefinitions($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
|
||||
$exists = Device::query()->distinct()->pluck('os')->flip()->all();
|
||||
$os_defs = array_intersect_key($os_defs, $exists);
|
||||
}
|
||||
\LibreNMS\Config::set('os', array_replace_recursive($os_defs, \LibreNMS\Config::get('os')));
|
||||
} else {
|
||||
// load from yaml
|
||||
if ($existing && Eloquent::isConnected()) {
|
||||
$os_list = Device::query()->distinct()->pluck('os');
|
||||
} else {
|
||||
$os_list = glob($install_dir . '/includes/definitions/*.yaml');
|
||||
}
|
||||
foreach ($os_list as $file) {
|
||||
$os = basename($file, '.yaml');
|
||||
self::loadDefinition($os);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the OS cache file cache/os_defs.cache
|
||||
* @param bool $force
|
||||
* @return bool true if the cache was updated
|
||||
*/
|
||||
public static function updateCache($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) {
|
||||
Log::debug('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"; // FIXME load db settings too or don't load config.php
|
||||
Config::set('os', $config['os']);
|
||||
|
||||
// load the os defs fresh from cache (merges with existing OS settings)
|
||||
self::loadAllDefinitions(false, false);
|
||||
|
||||
file_put_contents($cache_file, serialize(Config::get('os')));
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -73,7 +73,7 @@ class Url
|
|||
}
|
||||
|
||||
$class = self::deviceLinkDisplayClass($device);
|
||||
$graphs = self::getOverviewGraphsForDevice($device);
|
||||
$graphs = Graph::getOverviewGraphsForDevice($device);
|
||||
$url = Url::deviceUrl($device, $vars);
|
||||
|
||||
// beginning of overlib box contains large hostname followed by hardware & OS details
|
||||
|
@ -421,26 +421,6 @@ class Url
|
|||
return '<img class="' . $class . '" width="' . $width . '" height="' . $height . '" src="' . url('graph.php') . '?' . implode($sep, $vars) . '">';
|
||||
}
|
||||
|
||||
private static function getOverviewGraphsForDevice($device)
|
||||
{
|
||||
if ($device->snmp_disable) {
|
||||
return Config::getOsSetting('ping', 'over');
|
||||
}
|
||||
|
||||
if ($graphs = Config::getOsSetting($device->os, 'over')) {
|
||||
return $graphs;
|
||||
}
|
||||
|
||||
if ($os_group = Config::getOsSetting($device->os, 'os_group')) {
|
||||
$name = key($os_group);
|
||||
if (isset($os_group[$name]['over'])) {
|
||||
return $os_group[$name]['over'];
|
||||
}
|
||||
}
|
||||
|
||||
return Config::getOsSetting('default', 'over');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Device $device
|
||||
* @return string
|
||||
|
@ -551,7 +531,7 @@ class Url
|
|||
|
||||
$vars = [];
|
||||
foreach ($parts as $part) {
|
||||
list($key, $value) = explode('=', $part);
|
||||
[$key, $value] = explode('=', $part);
|
||||
$vars[$key] = $value;
|
||||
}
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@ use Gate;
|
|||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Arr;
|
||||
use LibreNMS\Config;
|
||||
use LibreNMS\Util\Graph;
|
||||
use LibreNMS\Util\Url;
|
||||
|
||||
class DeviceController extends Controller
|
||||
|
@ -130,7 +131,7 @@ class DeviceController extends Controller
|
|||
];
|
||||
|
||||
$graphs = [];
|
||||
foreach ($this->getDeviceGraphs($device) as $graph) {
|
||||
foreach (Graph::getOverviewGraphsForDevice($device) as $graph) {
|
||||
$graph_array['type'] = $graph['graph'];
|
||||
$graph_array['popup_title'] = __($graph['text']);
|
||||
$graphs[] = $graph_array;
|
||||
|
@ -139,18 +140,6 @@ class DeviceController extends Controller
|
|||
return $graphs;
|
||||
}
|
||||
|
||||
private function getDeviceGraphs(Device $device)
|
||||
{
|
||||
if ($device->snmp_disable) {
|
||||
return Config::get('os.ping.over');
|
||||
} elseif (Config::has("os.$device->os.over")) {
|
||||
return Config::get("os.$device->os.over");
|
||||
}
|
||||
|
||||
$os_group = Config::getOsSetting($device->os, 'group');
|
||||
return Config::get("os.$os_group.over", Config::get('os.default.over'));
|
||||
}
|
||||
|
||||
private function deviceLinkMenu(Device $device)
|
||||
{
|
||||
$device_links = [];
|
||||
|
|
|
@ -154,8 +154,7 @@ class OverviewController extends Controller
|
|||
->get();
|
||||
|
||||
$devices_uptime = $devices_uptime->reject(function ($device) {
|
||||
$device->loadOs(); // TODO: needed?
|
||||
return Config::get("os.{$device->os}.bad_uptime") == true;
|
||||
return Config::getOsSetting($device->os, 'bad_uptime') == true;
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -82,7 +82,6 @@ class DeviceFieldController extends SelectController
|
|||
|
||||
$text = $device[$field];
|
||||
if ($field == 'os') {
|
||||
$device->loadOs();
|
||||
$text = Config::getOsSetting($text, 'text');
|
||||
} elseif ($field == 'type') {
|
||||
$text = ucfirst($text);
|
||||
|
|
|
@ -202,7 +202,6 @@ class DeviceController extends TableController
|
|||
*/
|
||||
private function getOsText($device)
|
||||
{
|
||||
$device->loadOs();
|
||||
$os_text = Config::getOsSetting($device->os, 'text');
|
||||
|
||||
if ($this->isDetailed()) {
|
||||
|
|
|
@ -8,7 +8,6 @@ use Illuminate\Database\Eloquent\Builder;
|
|||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
use Illuminate\Database\Query\JoinClause;
|
||||
use Illuminate\Support\Str;
|
||||
use LibreNMS\DB\Eloquent;
|
||||
use LibreNMS\Exceptions\InvalidIpException;
|
||||
use LibreNMS\Util\IP;
|
||||
use LibreNMS\Util\IPv4;
|
||||
|
@ -30,17 +29,6 @@ class Device extends BaseModel
|
|||
'status' => 'boolean',
|
||||
];
|
||||
|
||||
/**
|
||||
* Initialize this class
|
||||
*/
|
||||
public static function boot()
|
||||
{
|
||||
parent::boot();
|
||||
if (!app()->runningInConsole()) {
|
||||
self::loadAllOs(true);
|
||||
}
|
||||
}
|
||||
|
||||
// ---- Helper Functions ----
|
||||
|
||||
public static function findByHostname($hostname)
|
||||
|
@ -171,56 +159,6 @@ class Device extends BaseModel
|
|||
return $query->exists();
|
||||
}
|
||||
|
||||
public function loadOs($force = false)
|
||||
{
|
||||
$yaml_file = base_path('/includes/definitions/' . $this->os . '.yaml');
|
||||
|
||||
if ((!\LibreNMS\Config::getOsSetting($this->os, 'definition_loaded') || $force) && file_exists($yaml_file)) {
|
||||
$os = \Symfony\Component\Yaml\Yaml::parse(file_get_contents($yaml_file));
|
||||
|
||||
\LibreNMS\Config::set("os.$this->os", array_replace_recursive($os, \LibreNMS\Config::get("os.$this->os", [])));
|
||||
\LibreNMS\Config::set("os.$this->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
|
||||
*/
|
||||
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 && Eloquent::isConnected()) {
|
||||
$os_list = [];
|
||||
foreach (self::distinct('os')->get('os')->toArray() as $os) {
|
||||
$os_list[] = $install_dir . '/includes/definitions/' . $os['os'] . '.yaml';
|
||||
}
|
||||
} 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.
|
||||
|
@ -408,7 +346,6 @@ class Device extends BaseModel
|
|||
|
||||
public function getIconAttribute($icon)
|
||||
{
|
||||
$this->loadOs();
|
||||
return Str::start(Url::findOsImage($this->os, $this->features, $icon), 'images/os/');
|
||||
}
|
||||
|
||||
|
|
|
@ -83,7 +83,7 @@ EOH;
|
|||
if (isset($options['v'])) {
|
||||
$vdebug = true;
|
||||
}
|
||||
update_os_cache(true); // Force update of OS Cache
|
||||
\LibreNMS\Util\OS::updateCache(true); // Force update of OS Cache
|
||||
}
|
||||
|
||||
if (!$where) {
|
||||
|
|
|
@ -54,7 +54,7 @@ function levsortos($base, $obj, $keys)
|
|||
|
||||
header('Content-type: application/json');
|
||||
if (isset($_GET['term'])) {
|
||||
load_all_os();
|
||||
\LibreNMS\Util\OS::loadAllDefinitions(false, true);
|
||||
$_GET['term'] = clean($_GET['term']);
|
||||
$sortos = levsortos($_GET['term'], \LibreNMS\Config::get('os'), ["text", "os"]);
|
||||
$sortos = array_slice($sortos, 0, 20);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -960,21 +960,21 @@ function get_toner_capacity($raw_capacity)
|
|||
*/
|
||||
function ignore_storage($os, $descr)
|
||||
{
|
||||
foreach (Config::getOsSetting($os, 'ignore_mount') as $im) {
|
||||
foreach (Config::getCombined($os, 'ignore_mount', []) as $im) {
|
||||
if ($im == $descr) {
|
||||
d_echo("ignored $descr (matched: $im)\n");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (Config::getOsSetting($os, 'ignore_mount_string') as $ims) {
|
||||
foreach (Config::getCombined($os, 'ignore_mount_string', []) as $ims) {
|
||||
if (Str::contains($descr, $ims)) {
|
||||
d_echo("ignored $descr (matched: $ims)\n");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (Config::getOsSetting($os, 'ignore_mount_regexp') as $imr) {
|
||||
foreach (Config::getCombined($os, 'ignore_mount_regexp', []) as $imr) {
|
||||
if (preg_match($imr, $descr)) {
|
||||
d_echo("ignored $descr (matched: $imr)\n");
|
||||
return true;
|
||||
|
|
|
@ -126,7 +126,7 @@ function parse_modules($type, $options)
|
|||
foreach (explode(',', $options['m']) as $module) {
|
||||
// parse submodules (only supported by some modules)
|
||||
if (Str::contains($module, '/')) {
|
||||
list($module, $submodule) = explode('/', $module, 2);
|
||||
[$module, $submodule] = explode('/', $module, 2);
|
||||
$existing_submodules = Config::get("{$type}_submodules.$module", []);
|
||||
$existing_submodules[] = $submodule;
|
||||
Config::set("{$type}_submodules.$module", $existing_submodules);
|
||||
|
@ -1049,7 +1049,7 @@ function is_port_valid($port, $device)
|
|||
}
|
||||
|
||||
// ifDescr should not be empty unless it is explicitly allowed
|
||||
if (!Config::getOsSetting($device['os'], 'empty_ifdescr', false)) {
|
||||
if (!Config::getOsSetting($device['os'], 'empty_ifdescr', Config::get('empty_ifdescr', false))) {
|
||||
d_echo("ignored: empty ifDescr\n");
|
||||
return false;
|
||||
}
|
||||
|
@ -1061,7 +1061,7 @@ function is_port_valid($port, $device)
|
|||
$ifType = $port['ifType'];
|
||||
$ifOperStatus = $port['ifOperStatus'];
|
||||
|
||||
if (str_i_contains($ifDescr, Config::getOsSetting($device['os'], 'good_if'))) {
|
||||
if (str_i_contains($ifDescr, Config::getOsSetting($device['os'], 'good_if', Config::get('good_if')))) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -1495,7 +1495,7 @@ function fping($host, $count = 3, $interval = 1000, $timeout = 500, $address_fam
|
|||
$output = $process->getErrorOutput();
|
||||
|
||||
preg_match('#= (\d+)/(\d+)/(\d+)%(, min/avg/max = ([\d.]+)/([\d.]+)/([\d.]+))?$#', $output, $parsed);
|
||||
list(, $xmt, $rcv, $loss, , $min, $avg, $max) = array_pad($parsed, 8, 0);
|
||||
[, $xmt, $rcv, $loss, , $min, $avg, $max] = array_pad($parsed, 8, 0);
|
||||
|
||||
if ($loss < 0) {
|
||||
$xmt = 1;
|
||||
|
|
|
@ -31,7 +31,7 @@ if ($device['features']) {
|
|||
$device['features'] = '('.$device['features'].')';
|
||||
}
|
||||
|
||||
$device['os_text'] = Config::get("os.{$device['os']}.text");
|
||||
$device['os_text'] = Config::getOsSetting($device['os'], 'text');
|
||||
|
||||
echo '<div class="row">
|
||||
<div class="col-sm-4">System Name</div>
|
||||
|
|
|
@ -1,66 +0,0 @@
|
|||
<?php
|
||||
|
||||
use LibreNMS\Alert\AlertUtil;
|
||||
use LibreNMS\Config;
|
||||
|
||||
echo getLogoTag($device, 'device-icon-header pull-left') .'
|
||||
<div class="pull-left" style="margin-top: 5px;">';
|
||||
|
||||
$host_id = get_vm_parent_id($device);
|
||||
if ($host_id > 0) {
|
||||
echo '
|
||||
<a href="'.generate_url(array('page'=>'device','device'=>$host_id)).'"><i class="fa fa-server fa-fw fa-lg"></i></a>';
|
||||
}
|
||||
|
||||
if (AlertUtil::isMaintenance($device['device_id'])) {
|
||||
echo ('<span title="Scheduled Maintenance" class="glyphicon glyphicon-wrench"></span>');
|
||||
}
|
||||
|
||||
echo '
|
||||
<span style="font-size: 20px;">'.generate_device_link($device).'</span><br />
|
||||
'.generate_link($device['location'], array('page' => 'devices', 'location' => $device['location'])) .'
|
||||
</div>';
|
||||
//<div class="col-xs-6 col-sm-8 col-md-8">';
|
||||
|
||||
|
||||
if ($device['snmp_disable']) {
|
||||
$graphs = Config::get('os.ping.over');
|
||||
} elseif (Config::has("os.{$device['os']}.over")) {
|
||||
$graphs = Config::get("os.{$device['os']}.over");
|
||||
} elseif (isset($device['os_group']) && Config::has("os.{$device['os_group']}.over")) {
|
||||
$graphs = Config::get("os.{$device['os_group']}.over");
|
||||
} else {
|
||||
$graphs = Config::get('os.default.over');
|
||||
}
|
||||
|
||||
$graph_array = array();
|
||||
$graph_array['height'] = '100';
|
||||
$graph_array['width'] = '310';
|
||||
$graph_array['to'] = Config::get('time.now');
|
||||
$graph_array['device'] = $device['device_id'];
|
||||
$graph_array['type'] = 'device_bits';
|
||||
$graph_array['from'] = Config::get('time.day');
|
||||
$graph_array['legend'] = 'no';
|
||||
$graph_array['popup_title'] = $descr;
|
||||
|
||||
$graph_array['height'] = '45';
|
||||
$graph_array['width'] = '150';
|
||||
$graph_array['bg'] = 'FFFFFF00';
|
||||
|
||||
if (device_permitted($device['device_id']) || Config::get('allow_unauth_graphs')) {
|
||||
echo '<div class="pull-right">';
|
||||
foreach ($graphs as $entry) {
|
||||
if ($entry['graph']) {
|
||||
$graph_array['type'] = $entry['graph'];
|
||||
|
||||
echo "<div style='float: right; text-align: center; padding: 1px 5px; margin: 0 1px; ' class='rounded-5px'>";
|
||||
print_graph_popup($graph_array);
|
||||
echo "<div style='font-weight: bold; font-size: 7pt; margin: -3px;'>" . $entry['text'] . '</div>';
|
||||
echo '</div>';
|
||||
}
|
||||
}
|
||||
echo '</div>';
|
||||
}
|
||||
echo '<br style="clear: both;" />';
|
||||
|
||||
unset($graph_array);
|
|
@ -177,15 +177,7 @@ function generate_device_link($device, $text = null, $vars = array(), $start = 0
|
|||
|
||||
$text = format_hostname($device, $text);
|
||||
|
||||
if ($device['snmp_disable']) {
|
||||
$graphs = Config::get('os.ping.over');
|
||||
} elseif (Config::has("os.{$device['os']}.over")) {
|
||||
$graphs = Config::get("os.{$device['os']}.over");
|
||||
} elseif (isset($device['os_group']) && Config::has("os.{$device['os_group']}.over")) {
|
||||
$graphs = Config::get("os.{$device['os_group']}.over");
|
||||
} else {
|
||||
$graphs = Config::get('os.default.over');
|
||||
}
|
||||
$graphs = \LibreNMS\Util\Graph::getOverviewGraphsForDevice(DeviceCache::get($device['device_id']));
|
||||
|
||||
$url = generate_device_url($device, $vars);
|
||||
|
||||
|
@ -196,7 +188,7 @@ function generate_device_link($device, $text = null, $vars = array(), $start = 0
|
|||
}
|
||||
|
||||
if ($device['os']) {
|
||||
$contents .= ' - ' . Config::get("os.{$device['os']}.text");
|
||||
$contents .= ' - ' . Config::getOsSetting($device['os'], 'text');
|
||||
}
|
||||
|
||||
if ($device['version']) {
|
||||
|
@ -1126,7 +1118,7 @@ function search_oxidized_config($search_in_conf_textbox)
|
|||
)
|
||||
);
|
||||
$context = stream_context_create($opts);
|
||||
|
||||
|
||||
$nodes = json_decode(file_get_contents($oxidized_search_url, false, $context), true);
|
||||
// Look up Oxidized node names to LibreNMS devices for a link
|
||||
foreach ($nodes as &$n) {
|
||||
|
@ -1205,7 +1197,7 @@ function get_oxidized_nodes_list()
|
|||
//user cannot see this device, so let's skip it.
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
echo "<tr>
|
||||
<td>" . $device['device_id'] . "</td>
|
||||
<td>" . $object['name'] . "</td>
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
$procs = dbFetchRows('SELECT * FROM `processors` where `device_id` = ?', array($device['device_id']));
|
||||
|
||||
if (\LibreNMS\Config::get("os.{$device['os']}.processor_stacked")) {
|
||||
if (\LibreNMS\Config::getOsSetting($device['os'], 'processor_stacked')) {
|
||||
include 'includes/html/graphs/device/processor_stack.inc.php';
|
||||
} else {
|
||||
include 'includes/html/graphs/device/processor_separate.inc.php';
|
||||
|
|
|
@ -272,8 +272,6 @@ if ($format == "graph") {
|
|||
|
||||
$os_selected = '""';
|
||||
if (isset($vars['os'])) {
|
||||
$device = ['os' => $vars['os']];
|
||||
load_os($device);
|
||||
$os_selected = json_encode(['id' => $vars['os'], 'text' => \LibreNMS\Config::getOsSetting($vars['os'], 'text', $vars['os'])]);
|
||||
}
|
||||
|
||||
|
|
|
@ -134,11 +134,11 @@ try {
|
|||
exit();
|
||||
}
|
||||
|
||||
if (module_selected('discovery', $init_modules) && !update_os_cache()) {
|
||||
// load_all_os() is called by update_os_cache() if updated, no need to call twice
|
||||
load_all_os();
|
||||
if (module_selected('discovery', $init_modules) && !\LibreNMS\Util\OS::updateCache(false)) {
|
||||
// OS::loadAllDefinitions() is called by update_os_cache() if updated, no need to call twice
|
||||
\LibreNMS\Util\OS::loadAllDefinitions(false, true);
|
||||
} elseif (module_selected('web', $init_modules)) {
|
||||
load_all_os(!module_selected('nodb', $init_modules));
|
||||
\LibreNMS\Util\OS::loadAllDefinitions(!module_selected('nodb', $init_modules), true);
|
||||
}
|
||||
|
||||
if (module_selected('web', $init_modules)) {
|
||||
|
|
|
@ -1387,7 +1387,7 @@ function snmpwalk_array_num($device, $oid, $indexes = 1)
|
|||
function get_device_max_repeaters($device)
|
||||
{
|
||||
return $device['attribs']['snmp_max_repeaters'] ??
|
||||
Config::getOsSetting($device['os'], 'snmp.max_repeaters', false);
|
||||
Config::getOsSetting($device['os'], 'snmp.max_repeaters', Config::get('snmp.max_repeaters', false));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -115,7 +115,7 @@ EOH;
|
|||
if (isset($options['v'])) {
|
||||
$vdebug = true;
|
||||
}
|
||||
update_os_cache(true); // Force update of OS Cache
|
||||
\LibreNMS\Util\OS::updateCache(true); // Force update of OS Cache
|
||||
}
|
||||
|
||||
// If we've specified modules with -m, use them
|
||||
|
|
|
@ -124,7 +124,7 @@ try {
|
|||
|
||||
|
||||
echo "Capturing Data: ";
|
||||
update_os_cache(true); // Force update of OS Cache
|
||||
\LibreNMS\Util\OS::updateCache(true); // Force update of OS Cache
|
||||
$capture->captureFromDevice($device['device_id'], true, $prefer_new_snmprec);
|
||||
} catch (InvalidModuleException $e) {
|
||||
echo $e->getMessage() . PHP_EOL;
|
||||
|
|
|
@ -128,7 +128,7 @@ try {
|
|||
}
|
||||
echo PHP_EOL;
|
||||
|
||||
update_os_cache(true); // Force update of OS Cache
|
||||
\LibreNMS\Util\OS::updateCache(true); // Force update of OS Cache
|
||||
$tester = new ModuleTestHelper($modules, $target_os, $target_variant);
|
||||
if (!$no_save && !empty($output_file)) {
|
||||
$tester->setJsonSavePath($output_file);
|
||||
|
|
|
@ -100,7 +100,7 @@ class ConfigTest extends TestCase
|
|||
$this->assertNull(Config::getOsSetting('nullos', 'unset'), 'Non-existing settings should return null');
|
||||
$this->assertFalse(Config::getOsSetting('nullos', 'unset', false), 'Non-existing settings should return $default');
|
||||
$this->assertTrue(Config::getOsSetting('nullos', 'fancy'), 'Failed to get setting');
|
||||
$this->assertTrue(Config::getOsSetting('nullos', 'fallback'), 'Failed to fallback to global setting');
|
||||
$this->assertNull(Config::getOsSetting('nullos', 'fallback'), 'Incorrectly loaded global setting');
|
||||
}
|
||||
|
||||
public function testGetCombined()
|
||||
|
|
|
@ -27,6 +27,9 @@ namespace LibreNMS\Tests;
|
|||
|
||||
use Illuminate\Support\Str;
|
||||
use LibreNMS\Config;
|
||||
use LibreNMS\Util\OS;
|
||||
use const false;
|
||||
use const true;
|
||||
|
||||
class OSDiscoveryTest extends TestCase
|
||||
{
|
||||
|
@ -145,7 +148,7 @@ class OSDiscoveryTest extends TestCase
|
|||
// make sure all OS are loaded
|
||||
$config_os = array_keys(Config::get('os'));
|
||||
if (count($config_os) < count(glob(Config::get('install_dir').'/includes/definitions/*.yaml'))) {
|
||||
load_all_os();
|
||||
OS::loadAllDefinitions(false, true);
|
||||
$config_os = array_keys(Config::get('os'));
|
||||
}
|
||||
|
||||
|
|
|
@ -42,8 +42,6 @@ chdir($install_dir);
|
|||
ini_set('display_errors', 1);
|
||||
//error_reporting(E_ALL & ~E_WARNING);
|
||||
|
||||
update_os_cache(true); // Force update of OS Cache
|
||||
|
||||
$snmpsim = new Snmpsim('127.1.6.2', 1162, null);
|
||||
if (getenv('SNMPSIM')) {
|
||||
$snmpsim->fork();
|
||||
|
@ -77,6 +75,5 @@ if (getenv('DBTEST')) {
|
|||
unset($db_config);
|
||||
}
|
||||
|
||||
// reload the config including database config
|
||||
Config::reload();
|
||||
load_all_os();
|
||||
Config::reload(); // reload the config including database config
|
||||
\LibreNMS\Util\OS::updateCache(true); // Force update of OS Cache
|
||||
|
|
Loading…
Reference in New Issue