mirror of
				https://github.com/librenms/librenms.git
				synced 2024-10-07 16:52:45 +00:00 
			
		
		
		
	refactor: move include based discovery after yaml discovery (#5401)
This commit is contained in:
		
				
					committed by
					
						
						Neil Lathwood
					
				
			
			
				
	
			
			
			
						parent
						
							569a3b4a8b
						
					
				
				
					commit
					8156fd547f
				
			@@ -8,3 +8,5 @@ over:
 | 
			
		||||
    - { graph: device_bits, text: 'Device Traffic' }
 | 
			
		||||
    - { graph: device_processor, text: 'CPU Usage' }
 | 
			
		||||
    - { graph: device_mempool, text: 'Memory Usage' }
 | 
			
		||||
discovery:
 | 
			
		||||
  - { sysObjectId: .1.3.6.1.4.1.4413, sysDescr_regex: [ '/^EdgeSwitch/', '/^EdgePoint/' ] }
 | 
			
		||||
 
 | 
			
		||||
@@ -4,9 +4,9 @@ group: zyxel
 | 
			
		||||
type: network
 | 
			
		||||
icon: zyxel
 | 
			
		||||
discovery:
 | 
			
		||||
    - sysObjectId:
 | 
			
		||||
        - .1.3.6.1.4.1.890
 | 
			
		||||
    - sysDescr_regex:
 | 
			
		||||
        - '^ES'
 | 
			
		||||
        - '^GS'
 | 
			
		||||
        - '^MES'
 | 
			
		||||
    -
 | 
			
		||||
      sysObjectId: .1.3.6.1.4.1.890
 | 
			
		||||
      sysDescr_regex:
 | 
			
		||||
        - '/^ES/'
 | 
			
		||||
        - '/^GS/'
 | 
			
		||||
        - '/^MES/'
 | 
			
		||||
 
 | 
			
		||||
@@ -5,3 +5,8 @@ type: firewall
 | 
			
		||||
over:
 | 
			
		||||
    - { graph: device_bits, text: Traffic }
 | 
			
		||||
icon: zyxel
 | 
			
		||||
discovery:
 | 
			
		||||
    - sysObjectId:
 | 
			
		||||
        - .1.3.6.1.4.1.890.1.6
 | 
			
		||||
        - .1.3.6.1.4.1.890.1.15
 | 
			
		||||
    - sysDescr_regex: '/^ZyWALL 2X/'
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +0,0 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
if (starts_with($sysObjectId, '.1.3.6.1.4.1.4413') && !str_contains($sysDescr, array('vxworks', 'Quanta', 'FASTPATH Switching'), true)) {
 | 
			
		||||
    $os = 'edgeswitch';
 | 
			
		||||
}
 | 
			
		||||
@@ -1,19 +1,7 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
$skip_oids = array(
 | 
			
		||||
    '.1.3.6.1.4.1.674.10892.2',
 | 
			
		||||
    '.1.3.6.1.4.1.17163.1.1',
 | 
			
		||||
    '.1.3.6.1.4.1.17713.21',
 | 
			
		||||
    '.1.3.6.1.4.1.2.3.51.3',
 | 
			
		||||
    '.1.3.6.1.4.1.7779.', // nios
 | 
			
		||||
    '.1.3.6.1.4.1.9.1.1348', // Cisco Unified Communications Manager
 | 
			
		||||
    '.1.3.6.1.4.1.3375.2.1', // F5
 | 
			
		||||
    '.1.3.6.1.4.1.534.', // Eaton
 | 
			
		||||
    '.1.3.6.1.4.1.2620.1.6.123.1' // Checkpoint
 | 
			
		||||
);
 | 
			
		||||
 | 
			
		||||
if (starts_with($sysDescr, 'Linux') && !starts_with($sysObjectId, $skip_oids)) {
 | 
			
		||||
if (starts_with($sysDescr, 'Linux')) {
 | 
			
		||||
    $os = 'linux';
 | 
			
		||||
 | 
			
		||||
    // Specific Linux-derivatives
 | 
			
		||||
 
 | 
			
		||||
@@ -1,9 +0,0 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
if (starts_with($sysDescr, 'ZyWALL 2X')) {
 | 
			
		||||
    $os = 'zywall';
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
if (starts_with($sysObjectId, array('.1.3.6.1.4.1.890.1.6', '.1.3.6.1.4.1.890.1.15'))) {
 | 
			
		||||
    $os = 'zywall';
 | 
			
		||||
}
 | 
			
		||||
@@ -98,25 +98,7 @@ function getHostOS($device)
 | 
			
		||||
 | 
			
		||||
    d_echo("| $sysDescr | $sysObjectId | \n");
 | 
			
		||||
 | 
			
		||||
    $os = null;
 | 
			
		||||
    $pattern = $config['install_dir'] . '/includes/discovery/os/*.inc.php';
 | 
			
		||||
    foreach (glob($pattern) as $file) {
 | 
			
		||||
        include $file;
 | 
			
		||||
        if (isset($os)) {
 | 
			
		||||
            return $os;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    return discover_os($sysObjectId, $sysDescr);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @param $sysObjectId
 | 
			
		||||
 * @param $sysDescr
 | 
			
		||||
 * @return string
 | 
			
		||||
 */
 | 
			
		||||
function discover_os($sysObjectId, $sysDescr)
 | 
			
		||||
{
 | 
			
		||||
    global $config;
 | 
			
		||||
    // check yaml files
 | 
			
		||||
    $pattern = $config['install_dir'] . '/includes/definitions/*.yaml';
 | 
			
		||||
    foreach (glob($pattern) as $file) {
 | 
			
		||||
        $tmp = Symfony\Component\Yaml\Yaml::parse(
 | 
			
		||||
@@ -149,6 +131,17 @@ function discover_os($sysObjectId, $sysDescr)
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // check include files
 | 
			
		||||
    $os = null;
 | 
			
		||||
    $pattern = $config['install_dir'] . '/includes/discovery/os/*.inc.php';
 | 
			
		||||
    foreach (glob($pattern) as $file) {
 | 
			
		||||
        include $file;
 | 
			
		||||
        if (isset($os)) {
 | 
			
		||||
            return $os;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return 'generic';
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1 +1,2 @@
 | 
			
		||||
1.3.6.1.2.1.1.1.0|4|EdgeSwitch 24-Port 250W, 1.0.1.4720839, Linux 3.6.5-f4a26ed5
 | 
			
		||||
1.3.6.1.2.1.1.2.0|6|1.3.6.1.4.1.4413
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user