mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
refactor: Allow os discovery deferral (#7561)
Defer some os till last, generic or slow ones. (linux, freebsd, ibmtl) last file standing is ubnt.inc.php
This commit is contained in:
committed by
Neil Lathwood
parent
db3d9dc4ab
commit
b73c4e9d6e
@@ -8,3 +8,5 @@ over:
|
||||
- { graph: device_ucd_memory, text: 'Memory Usage' }
|
||||
discovery_modules:
|
||||
applications: 1
|
||||
discovery:
|
||||
- sysDescr: FreeBSD
|
||||
|
@@ -31,3 +31,6 @@ register_mibs:
|
||||
KNIrxCounter: GANDI-MIB
|
||||
KNItxCounter: GANDI-MIB
|
||||
KNIdropCounter: GANDI-MIB
|
||||
discovery:
|
||||
- sysObjectId: .1.3.6.1.4.1.8072.3.2.10
|
||||
- sysDescr_regex: '/^Linux/'
|
||||
|
@@ -1,6 +0,0 @@
|
||||
<?php
|
||||
|
||||
// do not move to yaml, this check needs to happen last
|
||||
if (str_contains($sysDescr, 'FreeBSD')) {
|
||||
$os = 'freebsd';
|
||||
}
|
@@ -1,7 +0,0 @@
|
||||
<?php
|
||||
|
||||
// do not move to yaml, this check needs to happen last
|
||||
|
||||
if (starts_with($sysDescr, 'Linux') || starts_with($sysObjectId, '.1.3.6.1.4.1.8072.3.2.10')) {
|
||||
$os = 'linux';
|
||||
}
|
@@ -95,31 +95,24 @@ function getHostOS($device)
|
||||
{
|
||||
global $config;
|
||||
|
||||
$deferred_os = array(
|
||||
'freebsd',
|
||||
'linux',
|
||||
'ibmtl' //only has snmpget check
|
||||
);
|
||||
|
||||
$sysDescr = snmp_get($device, "SNMPv2-MIB::sysDescr.0", "-Ovq");
|
||||
$sysObjectId = snmp_get($device, "SNMPv2-MIB::sysObjectID.0", "-Ovqn");
|
||||
|
||||
d_echo("| $sysDescr | $sysObjectId | \n");
|
||||
|
||||
// check yaml files
|
||||
$pattern = $config['install_dir'] . '/includes/definitions/*.yaml';
|
||||
foreach (glob($pattern) as $file) {
|
||||
$os = basename($file, '.yaml');
|
||||
if (isset($config['os'][$os]['os'])) {
|
||||
$tmp = $config['os'][$os];
|
||||
} else {
|
||||
$tmp = Symfony\Component\Yaml\Yaml::parse(
|
||||
file_get_contents($file)
|
||||
);
|
||||
// pull in user overrides
|
||||
if (isset($config['os'][$os])) {
|
||||
$tmp = array_replace_recursive($tmp, $config['os'][$os]);
|
||||
}
|
||||
}
|
||||
if (isset($tmp['discovery']) && is_array($tmp['discovery'])) {
|
||||
foreach ($tmp['discovery'] as $item) {
|
||||
// check each item individually, if all the conditions in that item are true, we have a match
|
||||
$os_defs = Config::get('os');
|
||||
foreach ($os_defs as $os => $def) {
|
||||
if (isset($def['discovery']) && !in_array($os, $deferred_os)) {
|
||||
foreach ($def['discovery'] as $item) {
|
||||
if (checkDiscovery($device, $item, $sysObjectId, $sysDescr)) {
|
||||
return $tmp['os'];
|
||||
return $os;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -135,6 +128,17 @@ function getHostOS($device)
|
||||
}
|
||||
}
|
||||
|
||||
// check deferred os
|
||||
foreach ($deferred_os as $os) {
|
||||
if (isset($os_defs[$os]['discovery'])) {
|
||||
foreach ($os_defs[$os]['discovery'] as $item) {
|
||||
if (checkDiscovery($device, $item, $sysObjectId, $sysDescr)) {
|
||||
return $os;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 'generic';
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user