added central function and updated

This commit is contained in:
laf
2016-10-18 03:06:03 +00:00
parent 51a1ddf34f
commit 46d2f578e7
4 changed files with 44 additions and 64 deletions

View File

@@ -86,14 +86,6 @@ Devices may be excluded from cdp discovery by platform.
$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
$config['autodiscovery']['cdp_exclude']['platform_regexp'][] = '/^CIVS-IPC-/'; //Cisco IP Camera
```
#### OSPF
Enabled by default.

View File

@@ -199,9 +199,6 @@ $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
$config['autodiscovery']['cdp_exclude']['platform_regexp'][] = '/^CIVS-IPC-/'; //Cisco IP Camera
// Autodiscover hosts via discovery protocols
$config['autodiscovery']['ospf'] = true;
// Autodiscover hosts via OSPF

View File

@@ -19,21 +19,15 @@ 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) {
unset($skip_discovery);
foreach ($config['autodiscovery']['xdp_exclude']['sysname_regexp'] as $filter) {
if (preg_match($filter ."i", $fdp['snFdpCacheDeviceId'])) {
$skip_discovery = 1;
d_echo("{$fdp['snFdpCacheDeviceId']} - regexp '{$filter}' matches '{$fdp['snFdpCacheDeviceId']}' - skipping device discovery \n");
}
$skip_discovery = false;
if ($skip_discovery === false) {
$skip_discovery = can_skip_discovery($config['autodiscovery']['xdp_exclude']['sysname_regexp'], $fdp['snFdpCacheDeviceId'], $fdp['snFdpCacheDeviceId']);
}
foreach ($config['autodiscovery']['xdp_exclude']['sysdesc_regexp'] as $filter) {
if (preg_match($filter ."i", $fdp['cdpCacheVersion'])) {
$skip_discovery = 1;
d_echo("{$fdp['snFdpCacheDeviceId']} - regexp '{$filter}' matches '{$fdp['cdpCacheVersion']}' - skipping device discovery \n");
}
if ($skip_discovery === false) {
$skip_discovery = can_skip_discovery($config['autodiscovery']['xdp_exclude']['sysdesc_regexp'], $fdp['cdpCacheVersion'], $fdp['snFdpCacheDeviceId']);
}
if (!$skip_discovery) {
if ($skip_discovery === false) {
$remote_device_id = discover_new_device($fdp['snFdpCacheDeviceId'], $device, 'FDP', $interface);
}
}
@@ -68,27 +62,18 @@ 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) {
unset($skip_discovery);
foreach ($config['autodiscovery']['cdp_exclude']['platform_regexp'] as $filter) {
if (preg_match($filter ."i", $cdp['cdpCachePlatform'])) {
$skip_discovery = 1;
d_echo("{$cdp['cdpCacheDeviceId']} - regexp '{$filter}' matches '{$cdp['cdpCachePlatform']}' - skipping device discovery \n");
}
$skip_discovery = false;
if ($skip_discovery === false) {
$skip_discovery = can_skip_discovery($config['autodiscovery']['cdp_exclude']['platform_regexp'], $cdp['cdpCachePlatform'], $cdp['cdpCacheDeviceId']);
}
foreach ($config['autodiscovery']['xdp_exclude']['sysname_regexp'] as $filter) {
if (preg_match($filter ."i", $cdp['cdpCacheDeviceId'])) {
$skip_discovery = 1;
d_echo("{$cdp['cdpCacheDeviceId']} - regexp '{$filter}' matches '{$cdp['cdpCacheDeviceId']}' - skipping device discovery \n");
}
if ($skip_discovery === false) {
$skip_discovery = can_skip_discovery($config['autodiscovery']['xdp_exclude']['sysname_regexp'], $cdp['cdpCacheDeviceId'], $cdp['cdpCacheDeviceId']);
}
foreach ($config['autodiscovery']['xdp_exclude']['sysdesc_regexp'] as $filter) {
if (preg_match($filter ."i", $cdp['cdpCacheVersion'])) {
$skip_discovery = 1;
d_echo("{$cdp['cdpCacheDeviceId']} - regexp '{$filter}' matches '{$cdp['cdpCacheVersion']}' - skipping device discovery \n");
}
if ($skip_discovery === false) {
$skip_discovery = can_skip_discovery($config['autodiscovery']['xdp_exclude']['sysdesc_regexp'], $cdp['cdpCacheVersion'], $cdp['cdpCacheDeviceId']);
}
if (!$skip_discovery) {
if ($skip_discovery === false) {
if ($config['discovery_by_ip'] !== true) {
$remote_device_id = discover_new_device($cdp['cdpCacheDeviceId'], $device, 'CDP', $interface);
} else {
@@ -140,21 +125,15 @@ 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'])) {
unset($skip_discovery);
foreach ($config['autodiscovery']['xdp_exclude']['sysname_regexp'] as $filter) {
if (preg_match($filter ."i", $lldp['lldpRemSysName'])) {
$skip_discovery = 1;
d_echo("{$lldp['lldpRemSysName']} - regexp '{$filter}' matches '{$lldp['lldpRemSysName']}' - skipping device discovery \n");
}
$skip_discovery = false;
if ($skip_discovery === false) {
$skip_discovery = can_skip_discovery($config['autodiscovery']['xdp_exclude']['sysname_regexp'], $lldp['lldpRemSysName'], $lldp['lldpRemSysName']);
}
foreach ($config['autodiscovery']['xdp_exclude']['sysdesc_regexp'] as $filter) {
if (preg_match($filter ."i", $lldp['lldpRemSysDesc'])) {
$skip_discovery = 1;
d_echo("{$lldp['lldpRemSysName']} - regexp '{$filter}' matches '{$lldp['lldpRemSysDesc']}' - skipping device discovery \n");
}
if ($skip_discovery === false) {
$skip_discovery = can_skip_discovery($config['autodiscovery']['xdp_exclude']['sysdesc_regexp'], $lldp['lldpRemSysDesc'], $lldp['lldpRemSysName']);
}
if (!$skip_discovery) {
if ($skip_discovery === false) {
$remote_device_id = discover_new_device($lldp['lldpRemSysName'], $device, 'LLDP', $interface);
}
}
@@ -198,21 +177,15 @@ 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'])) {
unset($skip_discovery);
foreach ($config['autodiscovery']['xdp_exclude']['sysname_regexp'] as $filter) {
if (preg_match($filter ."i", $lldp['lldpRemSysName'])) {
$skip_discovery = 1;
d_echo("{$lldp['lldpRemSysName']} - regexp '{$filter}' matches '{$lldp['lldpRemSysName']}' - skipping device discovery \n");
}
$skip_discovery = false;
if ($skip_discovery === false) {
$skip_discovery = can_skip_discovery($config['autodiscovery']['xdp_exclude']['sysname_regexp'], $lldp['lldpRemSysName'], $lldp['lldpRemSysName']);
}
foreach ($config['autodiscovery']['xdp_exclude']['sysdesc_regexp'] as $filter) {
if (preg_match($filter ."i", $lldp['lldpRemSysDesc'])) {
$skip_discovery = 1;
d_echo("{$lldp['lldpRemSysName']} - regexp '{$filter}' matches '{$lldp['lldpRemSysDesc']}' - skipping device discovery \n");
}
if ($skip_discovery === false) {
$skip_discovery = can_skip_discovery($config['autodiscovery']['xdp_exclude']['sysdesc_regexp'], $lldp['lldpRemSysDesc'], $lldp['lldpRemSysName']);
}
if (!$skip_discovery) {
if ($skip_discovery === true) {
$remote_device_id = discover_new_device($lldp['lldpRemSysName'], $device, 'LLDP', $interface);
}
}

View File

@@ -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;
}