mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Use modern device attrib handling (#15429)
* Use modern attrib handling Remove device attribs array. fixes #15422 * Apply fixes from StyleCI --------- Co-authored-by: StyleCI Bot <bot@styleci.io>
This commit is contained in:
@@ -80,7 +80,6 @@ class LegacyModule implements Module
|
|||||||
}
|
}
|
||||||
|
|
||||||
$device = &$os->getDeviceArray();
|
$device = &$os->getDeviceArray();
|
||||||
$device['attribs'] = $os->getDevice()->attribs->toArray();
|
|
||||||
Debug::disableErrorReporting(); // ignore errors in legacy code
|
Debug::disableErrorReporting(); // ignore errors in legacy code
|
||||||
|
|
||||||
include_once base_path('includes/datastore.inc.php');
|
include_once base_path('includes/datastore.inc.php');
|
||||||
@@ -114,7 +113,6 @@ class LegacyModule implements Module
|
|||||||
}
|
}
|
||||||
|
|
||||||
$device = &$os->getDeviceArray();
|
$device = &$os->getDeviceArray();
|
||||||
$device['attribs'] = $os->getDevice()->attribs->toArray();
|
|
||||||
Debug::disableErrorReporting(); // ignore errors in legacy code
|
Debug::disableErrorReporting(); // ignore errors in legacy code
|
||||||
|
|
||||||
include_once base_path('includes/datastore.inc.php');
|
include_once base_path('includes/datastore.inc.php');
|
||||||
|
@@ -234,7 +234,6 @@ function device_by_id_cache($device_id, $refresh = false)
|
|||||||
$device['location'] = $model->location->location ?? null;
|
$device['location'] = $model->location->location ?? null;
|
||||||
$device['lat'] = $model->location->lat ?? null;
|
$device['lat'] = $model->location->lat ?? null;
|
||||||
$device['lng'] = $model->location->lng ?? null;
|
$device['lng'] = $model->location->lng ?? null;
|
||||||
$device['attribs'] = $model->getAttribs();
|
|
||||||
|
|
||||||
return $device;
|
return $device;
|
||||||
}
|
}
|
||||||
|
@@ -129,8 +129,6 @@ function discover_device(&$device, $force_module = false)
|
|||||||
global $valid;
|
global $valid;
|
||||||
|
|
||||||
$valid = [];
|
$valid = [];
|
||||||
// Reset $valid array
|
|
||||||
$device['attribs'] = DeviceCache::getPrimary()->getAttribs();
|
|
||||||
|
|
||||||
// Start counting device poll time
|
// Start counting device poll time
|
||||||
echo $device['hostname'] . ' ' . $device['device_id'] . ' ' . $device['os'] . ' ';
|
echo $device['hostname'] . ' ' . $device['device_id'] . ' ' . $device['os'] . ' ';
|
||||||
@@ -149,13 +147,14 @@ function discover_device(&$device, $force_module = false)
|
|||||||
|
|
||||||
foreach ($discovery_modules as $module => $module_status) {
|
foreach ($discovery_modules as $module => $module_status) {
|
||||||
$os_module_status = Config::getOsSetting($device['os'], "discovery_modules.$module");
|
$os_module_status = Config::getOsSetting($device['os'], "discovery_modules.$module");
|
||||||
|
$device_module_status = DeviceCache::getPrimary()->getAttrib('discover_' . $module);
|
||||||
d_echo('Modules status: Global' . (isset($module_status) ? ($module_status ? '+ ' : '- ') : ' '));
|
d_echo('Modules status: Global' . (isset($module_status) ? ($module_status ? '+ ' : '- ') : ' '));
|
||||||
d_echo('OS' . (isset($os_module_status) ? ($os_module_status ? '+ ' : '- ') : ' '));
|
d_echo('OS' . (isset($os_module_status) ? ($os_module_status ? '+ ' : '- ') : ' '));
|
||||||
d_echo('Device' . (isset($device['attribs']['discover_' . $module]) ? ($device['attribs']['discover_' . $module] ? '+ ' : '- ') : ' '));
|
d_echo('Device' . ($device_module_status !== null ? ($device_module_status ? '+ ' : '- ') : ' '));
|
||||||
if ($force_module === true ||
|
if ($force_module === true ||
|
||||||
! empty($device['attribs']['discover_' . $module]) ||
|
$device_module_status ||
|
||||||
($os_module_status && ! isset($device['attribs']['discover_' . $module])) ||
|
($os_module_status && $device_module_status === null) ||
|
||||||
($module_status && ! isset($os_module_status) && ! isset($device['attribs']['discover_' . $module]))
|
($module_status && ! isset($os_module_status) && $device_module_status === null)
|
||||||
) {
|
) {
|
||||||
$module_start = microtime(true);
|
$module_start = microtime(true);
|
||||||
$start_memory = memory_get_usage();
|
$start_memory = memory_get_usage();
|
||||||
@@ -181,7 +180,7 @@ function discover_device(&$device, $force_module = false)
|
|||||||
printf("\n>> Runtime for discovery module '%s': %.4f seconds with %s bytes\n", $module, $module_time, $module_mem);
|
printf("\n>> Runtime for discovery module '%s': %.4f seconds with %s bytes\n", $module, $module_time, $module_mem);
|
||||||
$measurements->printChangedStats();
|
$measurements->printChangedStats();
|
||||||
echo "#### Unload disco module $module ####\n\n";
|
echo "#### Unload disco module $module ####\n\n";
|
||||||
} elseif (isset($device['attribs']['discover_' . $module]) && $device['attribs']['discover_' . $module] == '0') {
|
} elseif ($device_module_status == '0') {
|
||||||
echo "Module [ $module ] disabled on host.\n\n";
|
echo "Module [ $module ] disabled on host.\n\n";
|
||||||
} elseif (isset($os_module_status) && $os_module_status == '0') {
|
} elseif (isset($os_module_status) && $os_module_status == '0') {
|
||||||
echo "Module [ $module ] disabled on os.\n\n";
|
echo "Module [ $module ] disabled on os.\n\n";
|
||||||
|
@@ -8,7 +8,6 @@
|
|||||||
* @copyright (C) 2006 - 2012 Adam Armstrong
|
* @copyright (C) 2006 - 2012 Adam Armstrong
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use App\Models\Device;
|
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
use LibreNMS\Config;
|
use LibreNMS\Config;
|
||||||
use LibreNMS\Enum\Severity;
|
use LibreNMS\Enum\Severity;
|
||||||
@@ -362,7 +361,8 @@ function port_fill_missing_and_trim(&$port, $device)
|
|||||||
$port['ifDescr'] = $port['ifName'];
|
$port['ifDescr'] = $port['ifName'];
|
||||||
d_echo(' Using ifName as ifDescr');
|
d_echo(' Using ifName as ifDescr');
|
||||||
}
|
}
|
||||||
if (! empty($device['attribs']['ifName:' . $port['ifName']])) {
|
$attrib = DeviceCache::get($device['device_id'] ?? null)->getAttrib('ifName:' . $port['ifName']);
|
||||||
|
if (! empty($attrib)) {
|
||||||
// ifAlias overridden by user, don't update it
|
// ifAlias overridden by user, don't update it
|
||||||
unset($port['ifAlias']);
|
unset($port['ifAlias']);
|
||||||
d_echo(' ifAlias overriden by user');
|
d_echo(' ifAlias overriden by user');
|
||||||
@@ -885,8 +885,9 @@ function cache_peeringdb()
|
|||||||
function get_device_oid_limit($device)
|
function get_device_oid_limit($device)
|
||||||
{
|
{
|
||||||
// device takes priority
|
// device takes priority
|
||||||
if (! empty($device['attribs']['snmp_max_oid'])) {
|
$attrib = DeviceCache::get($device['device_id'] ?? null)->getAttrib('snmp_max_oid');
|
||||||
return $device['attribs']['snmp_max_oid'];
|
if ($attrib !== null) {
|
||||||
|
return $attrib;
|
||||||
}
|
}
|
||||||
|
|
||||||
// then os
|
// then os
|
||||||
|
@@ -8,13 +8,14 @@ $ipmi_rows = dbFetchRows("SELECT * FROM sensors WHERE device_id = ? AND poller_t
|
|||||||
if (is_array($ipmi_rows)) {
|
if (is_array($ipmi_rows)) {
|
||||||
d_echo($ipmi_rows);
|
d_echo($ipmi_rows);
|
||||||
|
|
||||||
if (isset($device['attribs']['ipmi_hostname'])) {
|
if ($ipmi_hostname = DeviceCache::getPrimary()->getAttrib('ipmi_hostname')) {
|
||||||
$ipmi['host'] = $device['attribs']['ipmi_hostname'];
|
$ipmi['host'] = $ipmi_hostname;
|
||||||
$ipmi['port'] = filter_var($device['attribs']['ipmi_port'], FILTER_VALIDATE_INT) ? $device['attribs']['ipmi_port'] : '623';
|
$ipmi_port = DeviceCache::getPrimary()->getAttrib('ipmi_port');
|
||||||
$ipmi['user'] = $device['attribs']['ipmi_username'];
|
$ipmi['port'] = filter_var($ipmi_port, FILTER_VALIDATE_INT) ? $ipmi_port : '623';
|
||||||
$ipmi['password'] = $device['attribs']['ipmi_password'];
|
$ipmi['user'] = DeviceCache::getPrimary()->getAttrib('ipmi_username');
|
||||||
$ipmi['kg_key'] = $device['attribs']['ipmi_kg_key'];
|
$ipmi['password'] = DeviceCache::getPrimary()->getAttrib('ipmi_password');
|
||||||
$ipmi['type'] = $device['attribs']['ipmi_type'];
|
$ipmi['kg_key'] = DeviceCache::getPrimary()->getAttrib('ipmi_kg_key');
|
||||||
|
$ipmi['type'] = DeviceCache::getPrimary()->getAttrib('ipmi_type');
|
||||||
|
|
||||||
echo 'Fetching IPMI sensor data...';
|
echo 'Fetching IPMI sensor data...';
|
||||||
|
|
||||||
|
@@ -213,7 +213,8 @@ if ($device['os'] === 'f5' && (version_compare($device['version'], '11.2.0', '>=
|
|||||||
} elseif ($device['os'] === 'exalink-fusion') {
|
} elseif ($device['os'] === 'exalink-fusion') {
|
||||||
require 'ports/exalink-fusion.inc.php';
|
require 'ports/exalink-fusion.inc.php';
|
||||||
} else {
|
} else {
|
||||||
if (Config::getOsSetting($device['os'], 'polling.selected_ports') || (isset($device['attribs']['selected_ports']) && $device['attribs']['selected_ports'] == 'true')) {
|
$selected_attrib = DeviceCache::get($device['device_id'] ?? null)->getAttrib('selected_ports');
|
||||||
|
if ($selected_attrib !== null ? $selected_attrib == 'true' : Config::getOsSetting($device['os'], 'polling.selected_ports')) {
|
||||||
echo 'Selected ports polling ';
|
echo 'Selected ports polling ';
|
||||||
|
|
||||||
// remove the deleted and disabled ports and mark them skipped
|
// remove the deleted and disabled ports and mark them skipped
|
||||||
@@ -225,7 +226,7 @@ if ($device['os'] === 'f5' && (version_compare($device['version'], '11.2.0', '>=
|
|||||||
|
|
||||||
// only try to guess if we should walk base oids if selected_ports is set only globally
|
// only try to guess if we should walk base oids if selected_ports is set only globally
|
||||||
$walk_base = false;
|
$walk_base = false;
|
||||||
if (! Config::has("os.{$device['os']}.polling.selected_ports") && ! array_key_exists('selected_ports', $device['attribs'])) {
|
if (! Config::has("os.{$device['os']}.polling.selected_ports") && $selected_attrib === null) {
|
||||||
// if less than 5 ports or less than 10% of the total ports are skipped, walk the base oids instead of get
|
// if less than 5 ports or less than 10% of the total ports are skipped, walk the base oids instead of get
|
||||||
$polled_port_count = count($polled_ports);
|
$polled_port_count = count($polled_ports);
|
||||||
$total_port_count = count($ports);
|
$total_port_count = count($ports);
|
||||||
@@ -690,8 +691,8 @@ foreach ($ports as $port) {
|
|||||||
// if the value is different, update it
|
// if the value is different, update it
|
||||||
|
|
||||||
// rrdtune if needed
|
// rrdtune if needed
|
||||||
$port_tune = $device['attribs']['ifName_tune:' . $port['ifName']] ?? null;
|
$port_tune = DeviceCache::getPrimary()->getAttrib('ifName_tune:' . $port['ifName']);
|
||||||
$device_tune = $device['attribs']['override_rrdtool_tune'] ?? null;
|
$device_tune = DeviceCache::getPrimary()->getAttrib('override_rrdtool_tune');
|
||||||
if ($port_tune == 'true' ||
|
if ($port_tune == 'true' ||
|
||||||
($device_tune == 'true' && $port_tune != 'false') ||
|
($device_tune == 'true' && $port_tune != 'false') ||
|
||||||
(Config::get('rrdtool_tune') == 'true' && $port_tune != 'false' && $device_tune != 'false')) {
|
(Config::get('rrdtool_tune') == 'true' && $port_tune != 'false' && $device_tune != 'false')) {
|
||||||
|
@@ -797,6 +797,7 @@ function snmpwalk_array_num($device, $oid, $indexes = 1)
|
|||||||
*/
|
*/
|
||||||
function get_device_max_repeaters($device)
|
function get_device_max_repeaters($device)
|
||||||
{
|
{
|
||||||
return $device['attribs']['snmp_max_repeaters'] ??
|
$attrib = DeviceCache::get($device['device_id'] ?? null)->getAttrib('snmp_max_repeaters');
|
||||||
Config::getOsSetting($device['os'], 'snmp.max_repeaters', Config::get('snmp.max_repeaters', false));
|
|
||||||
|
return $attrib ?? Config::getOsSetting($device['os'], 'snmp.max_repeaters', Config::get('snmp.max_repeaters', false));
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user