diff --git a/AUTHORS.md b/AUTHORS.md index a6d321b4cc..b4d1526c09 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -142,6 +142,7 @@ LibreNMS contributors: - Justin Settle (jquagga) - Alexander Kratzsch (klump) - Joseph Eames (j-ems) +- Eric Conroy (NetworkNub) - Timothy Willey (twilley) [1]: http://observium.org/ "Observium web site" diff --git a/doc/Extensions/Auto-Discovery.md b/doc/Extensions/Auto-Discovery.md index c4760b59b1..ada1d57dd6 100644 --- a/doc/Extensions/Auto-Discovery.md +++ b/doc/Extensions/Auto-Discovery.md @@ -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. diff --git a/includes/defaults.inc.php b/includes/defaults.inc.php index 943fcb390a..f6af442054 100644 --- a/includes/defaults.inc.php +++ b/includes/defaults.inc.php @@ -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 diff --git a/includes/discovery/discovery-protocols.inc.php b/includes/discovery/discovery-protocols.inc.php index 11a01b08b5..6dd4d44ae0 100644 --- a/includes/discovery/discovery-protocols.inc.php +++ b/includes/discovery/discovery-protocols.inc.php @@ -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 = ''; diff --git a/includes/functions.php b/includes/functions.php index 73858ebc49..c2e85714dd 100644 --- a/includes/functions.php +++ b/includes/functions.php @@ -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; +}