mirror of
https://github.com/librenms/librenms.git
synced 2024-09-22 02:48:37 +00:00
feature: Added ability to exclude devices from xDP disco based on sysdescr, sysname or platform
This commit is contained in:
commit
b8bcbef015
@ -142,6 +142,7 @@ LibreNMS contributors:
|
||||
- Justin Settle <jus10@partlycloudy.org> (jquagga)
|
||||
- Alexander Kratzsch <klump@devrandom.se> (klump)
|
||||
- Joseph Eames <j.eames@outlook.com> (j-ems)
|
||||
- Eric Conroy <eric@conroy.co> (NetworkNub)
|
||||
- Timothy Willey <developer@timothywilley.net> (twilley)
|
||||
|
||||
[1]: http://observium.org/ "Observium web site"
|
||||
|
@ -67,6 +67,32 @@ Enabled by default.
|
||||
|
||||
This includes FDP, CDP and LLDP support based on the device type.
|
||||
|
||||
Devices may be excluded from xdp discovery by sysname and sysdesc.
|
||||
|
||||
```php
|
||||
//Exclude devices by name
|
||||
$config['autodiscovery']['xdp_exclude']['sysname_regexp'][] = '/host1/';
|
||||
$config['autodiscovery']['xdp_exclude']['sysname_regexp'][] = '/^dev/';
|
||||
|
||||
//Exclude devices by description
|
||||
$config['autodiscovery']['xdp_exclude']['sysdesc_regexp'][] = '/Vendor X/';
|
||||
$config['autodiscovery']['xdp_exclude']['sysdesc_regexp'][] = '/Vendor Y/';
|
||||
```
|
||||
|
||||
Devices may be excluded from cdp discovery by platform.
|
||||
|
||||
```php
|
||||
//Exclude devices by platform(Cisco only)
|
||||
$config['autodiscovery']['cdp_exclude']['platform_regexp'][] = '/WS-C3750G/';
|
||||
```
|
||||
|
||||
These devices are excluded by default:
|
||||
|
||||
```php
|
||||
$config['autodiscovery']['xdp_exclude']['sysdesc_regexp'][] = '/-K9W8-/'; // Cisco Lightweight Access Point
|
||||
$config['autodiscovery']['cdp_exclude']['platform_regexp'][] = '/^Cisco IP Phone/'; //Cisco IP Phone
|
||||
```
|
||||
|
||||
#### OSPF
|
||||
Enabled by default.
|
||||
|
||||
|
@ -199,6 +199,8 @@ $config['icmp_check'] = true;
|
||||
|
||||
// Autodiscovery Settings
|
||||
$config['autodiscovery']['xdp'] = true;
|
||||
$config['autodiscovery']['xdp_exclude']['sysdesc_regexp'][] = '/-K9W8-/'; // Cisco Lightweight Access Point
|
||||
$config['autodiscovery']['cdp_exclude']['platform_regexp'][] = '/^Cisco IP Phone/'; //Cisco IP Phone
|
||||
// Autodiscover hosts via discovery protocols
|
||||
$config['autodiscovery']['ospf'] = true;
|
||||
// Autodiscover hosts via OSPF
|
||||
|
@ -19,7 +19,17 @@ if ($device['os'] == 'ironware' && $config['autodiscovery']['xdp'] === true) {
|
||||
$remote_device_id = dbFetchCell('SELECT `device_id` FROM `devices` WHERE `sysName` = ? OR `hostname` = ?', array($fdp['snFdpCacheDeviceId'], $fdp['snFdpCacheDeviceId']));
|
||||
|
||||
if (!$remote_device_id) {
|
||||
$remote_device_id = discover_new_device($fdp['snFdpCacheDeviceId'], $device, 'FDP', $interface);
|
||||
$skip_discovery = false;
|
||||
if ($skip_discovery === false) {
|
||||
$skip_discovery = can_skip_discovery($config['autodiscovery']['xdp_exclude']['sysname_regexp'], $fdp['snFdpCacheDeviceId'], $fdp['snFdpCacheDeviceId']);
|
||||
}
|
||||
if ($skip_discovery === false) {
|
||||
$skip_discovery = can_skip_discovery($config['autodiscovery']['xdp_exclude']['sysdesc_regexp'], $fdp['snFdpCacheVersion'], $fdp['snFdpCacheDeviceId']);
|
||||
}
|
||||
|
||||
if ($skip_discovery === false) {
|
||||
$remote_device_id = discover_new_device($fdp['snFdpCacheDeviceId'], $device, 'FDP', $interface);
|
||||
}
|
||||
}
|
||||
|
||||
if ($remote_device_id) {
|
||||
@ -52,19 +62,32 @@ if ($config['autodiscovery']['xdp'] === true) {
|
||||
$remote_device_id = dbFetchCell('SELECT `device_id` FROM `devices` WHERE `sysName` = ? OR `hostname` = ?', array($cdp['cdpCacheDeviceId'], $cdp['cdpCacheDeviceId']));
|
||||
|
||||
if (!$remote_device_id) {
|
||||
if ($config['discovery_by_ip'] !== true) {
|
||||
$remote_device_id = discover_new_device($cdp['cdpCacheDeviceId'], $device, 'CDP', $interface);
|
||||
} else {
|
||||
$ip_arr = explode(" ", $cdp['cdpCacheAddress']);
|
||||
$skip_discovery = false;
|
||||
if ($skip_discovery === false) {
|
||||
$skip_discovery = can_skip_discovery($config['autodiscovery']['cdp_exclude']['platform_regexp'], $cdp['cdpCachePlatform'], $cdp['cdpCacheDeviceId']);
|
||||
}
|
||||
if ($skip_discovery === false) {
|
||||
$skip_discovery = can_skip_discovery($config['autodiscovery']['xdp_exclude']['sysname_regexp'], $cdp['cdpCacheDeviceId'], $cdp['cdpCacheDeviceId']);
|
||||
}
|
||||
if ($skip_discovery === false) {
|
||||
$skip_discovery = can_skip_discovery($config['autodiscovery']['xdp_exclude']['sysdesc_regexp'], $cdp['cdpCacheVersion'], $cdp['cdpCacheDeviceId']);
|
||||
}
|
||||
|
||||
$a = hexdec($ip_arr[0]);
|
||||
$b = hexdec($ip_arr[1]);
|
||||
$c = hexdec($ip_arr[2]);
|
||||
$d = hexdec($ip_arr[3]);
|
||||
if ($skip_discovery === false) {
|
||||
if ($config['discovery_by_ip'] !== true) {
|
||||
$remote_device_id = discover_new_device($cdp['cdpCacheDeviceId'], $device, 'CDP', $interface);
|
||||
} else {
|
||||
$ip_arr = explode(" ", $cdp['cdpCacheAddress']);
|
||||
|
||||
$cdp_ip = "$a.$b.$c.$d";
|
||||
$a = hexdec($ip_arr[0]);
|
||||
$b = hexdec($ip_arr[1]);
|
||||
$c = hexdec($ip_arr[2]);
|
||||
$d = hexdec($ip_arr[3]);
|
||||
|
||||
$remote_device_id = discover_new_device($cdp_ip, $device, 'CDP', $interface);
|
||||
$cdp_ip = "$a.$b.$c.$d";
|
||||
|
||||
$remote_device_id = discover_new_device($cdp_ip, $device, 'CDP', $interface);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -102,7 +125,17 @@ if ($device['os'] == 'pbn' && $config['autodiscovery']['xdp'] === true) {
|
||||
$remote_device_id = dbFetchCell('SELECT `device_id` FROM `devices` WHERE `sysName` = ? OR `hostname` = ?', array($lldp['lldpRemSysName'], $lldp['lldpRemSysName']));
|
||||
|
||||
if (!$remote_device_id && is_valid_hostname($lldp['lldpRemSysName'])) {
|
||||
$remote_device_id = discover_new_device($lldp['lldpRemSysName'], $device, 'LLDP', $interface);
|
||||
$skip_discovery = false;
|
||||
if ($skip_discovery === false) {
|
||||
$skip_discovery = can_skip_discovery($config['autodiscovery']['xdp_exclude']['sysname_regexp'], $lldp['lldpRemSysName'], $lldp['lldpRemSysName']);
|
||||
}
|
||||
if ($skip_discovery === false) {
|
||||
$skip_discovery = can_skip_discovery($config['autodiscovery']['xdp_exclude']['sysdesc_regexp'], $lldp['lldpRemSysDesc'], $lldp['lldpRemSysName']);
|
||||
}
|
||||
|
||||
if ($skip_discovery === false) {
|
||||
$remote_device_id = discover_new_device($lldp['lldpRemSysName'], $device, 'LLDP', $interface);
|
||||
}
|
||||
}
|
||||
|
||||
if ($remote_device_id) {
|
||||
@ -144,7 +177,17 @@ if ($device['os'] == 'pbn' && $config['autodiscovery']['xdp'] === true) {
|
||||
$remote_device_id = dbFetchCell('SELECT `device_id` FROM `devices` WHERE `sysName` = ? OR `hostname` = ?', array($lldp['lldpRemSysName'], $lldp['lldpRemSysName']));
|
||||
|
||||
if (!$remote_device_id && is_valid_hostname($lldp['lldpRemSysName'])) {
|
||||
$remote_device_id = discover_new_device($lldp['lldpRemSysName'], $device, 'LLDP', $interface);
|
||||
$skip_discovery = false;
|
||||
if ($skip_discovery === false) {
|
||||
$skip_discovery = can_skip_discovery($config['autodiscovery']['xdp_exclude']['sysname_regexp'], $lldp['lldpRemSysName'], $lldp['lldpRemSysName']);
|
||||
}
|
||||
if ($skip_discovery === false) {
|
||||
$skip_discovery = can_skip_discovery($config['autodiscovery']['xdp_exclude']['sysdesc_regexp'], $lldp['lldpRemSysDesc'], $lldp['lldpRemSysName']);
|
||||
}
|
||||
|
||||
if ($skip_discovery === false) {
|
||||
$remote_device_id = discover_new_device($lldp['lldpRemSysName'], $device, 'LLDP', $interface);
|
||||
}
|
||||
}
|
||||
// normalize MAC address if present
|
||||
$remote_port_mac_address = '';
|
||||
|
@ -1736,3 +1736,21 @@ function get_toner_levels($device, $raw_value, $capacity)
|
||||
|
||||
return round($raw_value / $capacity * 100);
|
||||
}
|
||||
|
||||
/**
|
||||
* check if we should skip this device from discovery
|
||||
* @param $needles
|
||||
* @param $haystack
|
||||
* @param $name
|
||||
* @return bool
|
||||
*/
|
||||
function can_skip_discovery($needles, $haystack, $name)
|
||||
{
|
||||
foreach ((array)$needles as $needle) {
|
||||
if (preg_match($needle ."i", $haystack)) {
|
||||
d_echo("{$name} - regexp '{$needle}' matches '{$haystack}' - skipping device discovery \n");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user