mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
added central function and updated
This commit is contained in:
@@ -86,14 +86,6 @@ Devices may be excluded from cdp discovery by platform.
|
|||||||
$config['autodiscovery']['cdp_exclude']['platform_regexp'][] = '/WS-C3750G/';
|
$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
|
#### OSPF
|
||||||
Enabled by default.
|
Enabled by default.
|
||||||
|
|
||||||
|
|||||||
@@ -199,9 +199,6 @@ $config['icmp_check'] = true;
|
|||||||
|
|
||||||
// Autodiscovery Settings
|
// Autodiscovery Settings
|
||||||
$config['autodiscovery']['xdp'] = true;
|
$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
|
// Autodiscover hosts via discovery protocols
|
||||||
$config['autodiscovery']['ospf'] = true;
|
$config['autodiscovery']['ospf'] = true;
|
||||||
// Autodiscover hosts via OSPF
|
// Autodiscover hosts via OSPF
|
||||||
|
|||||||
@@ -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']));
|
$remote_device_id = dbFetchCell('SELECT `device_id` FROM `devices` WHERE `sysName` = ? OR `hostname` = ?', array($fdp['snFdpCacheDeviceId'], $fdp['snFdpCacheDeviceId']));
|
||||||
|
|
||||||
if (!$remote_device_id) {
|
if (!$remote_device_id) {
|
||||||
unset($skip_discovery);
|
$skip_discovery = false;
|
||||||
foreach ($config['autodiscovery']['xdp_exclude']['sysname_regexp'] as $filter) {
|
if ($skip_discovery === false) {
|
||||||
if (preg_match($filter ."i", $fdp['snFdpCacheDeviceId'])) {
|
$skip_discovery = can_skip_discovery($config['autodiscovery']['xdp_exclude']['sysname_regexp'], $fdp['snFdpCacheDeviceId'], $fdp['snFdpCacheDeviceId']);
|
||||||
$skip_discovery = 1;
|
|
||||||
d_echo("{$fdp['snFdpCacheDeviceId']} - regexp '{$filter}' matches '{$fdp['snFdpCacheDeviceId']}' - skipping device discovery \n");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
foreach ($config['autodiscovery']['xdp_exclude']['sysdesc_regexp'] as $filter) {
|
if ($skip_discovery === false) {
|
||||||
if (preg_match($filter ."i", $fdp['cdpCacheVersion'])) {
|
$skip_discovery = can_skip_discovery($config['autodiscovery']['xdp_exclude']['sysdesc_regexp'], $fdp['cdpCacheVersion'], $fdp['snFdpCacheDeviceId']);
|
||||||
$skip_discovery = 1;
|
|
||||||
d_echo("{$fdp['snFdpCacheDeviceId']} - regexp '{$filter}' matches '{$fdp['cdpCacheVersion']}' - skipping device discovery \n");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$skip_discovery) {
|
if ($skip_discovery === false) {
|
||||||
$remote_device_id = discover_new_device($fdp['snFdpCacheDeviceId'], $device, 'FDP', $interface);
|
$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']));
|
$remote_device_id = dbFetchCell('SELECT `device_id` FROM `devices` WHERE `sysName` = ? OR `hostname` = ?', array($cdp['cdpCacheDeviceId'], $cdp['cdpCacheDeviceId']));
|
||||||
|
|
||||||
if (!$remote_device_id) {
|
if (!$remote_device_id) {
|
||||||
unset($skip_discovery);
|
$skip_discovery = false;
|
||||||
foreach ($config['autodiscovery']['cdp_exclude']['platform_regexp'] as $filter) {
|
if ($skip_discovery === false) {
|
||||||
if (preg_match($filter ."i", $cdp['cdpCachePlatform'])) {
|
$skip_discovery = can_skip_discovery($config['autodiscovery']['cdp_exclude']['platform_regexp'], $cdp['cdpCachePlatform'], $cdp['cdpCacheDeviceId']);
|
||||||
$skip_discovery = 1;
|
|
||||||
d_echo("{$cdp['cdpCacheDeviceId']} - regexp '{$filter}' matches '{$cdp['cdpCachePlatform']}' - skipping device discovery \n");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
foreach ($config['autodiscovery']['xdp_exclude']['sysname_regexp'] as $filter) {
|
if ($skip_discovery === false) {
|
||||||
if (preg_match($filter ."i", $cdp['cdpCacheDeviceId'])) {
|
$skip_discovery = can_skip_discovery($config['autodiscovery']['xdp_exclude']['sysname_regexp'], $cdp['cdpCacheDeviceId'], $cdp['cdpCacheDeviceId']);
|
||||||
$skip_discovery = 1;
|
|
||||||
d_echo("{$cdp['cdpCacheDeviceId']} - regexp '{$filter}' matches '{$cdp['cdpCacheDeviceId']}' - skipping device discovery \n");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
foreach ($config['autodiscovery']['xdp_exclude']['sysdesc_regexp'] as $filter) {
|
if ($skip_discovery === false) {
|
||||||
if (preg_match($filter ."i", $cdp['cdpCacheVersion'])) {
|
$skip_discovery = can_skip_discovery($config['autodiscovery']['xdp_exclude']['sysdesc_regexp'], $cdp['cdpCacheVersion'], $cdp['cdpCacheDeviceId']);
|
||||||
$skip_discovery = 1;
|
|
||||||
d_echo("{$cdp['cdpCacheDeviceId']} - regexp '{$filter}' matches '{$cdp['cdpCacheVersion']}' - skipping device discovery \n");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$skip_discovery) {
|
if ($skip_discovery === false) {
|
||||||
if ($config['discovery_by_ip'] !== true) {
|
if ($config['discovery_by_ip'] !== true) {
|
||||||
$remote_device_id = discover_new_device($cdp['cdpCacheDeviceId'], $device, 'CDP', $interface);
|
$remote_device_id = discover_new_device($cdp['cdpCacheDeviceId'], $device, 'CDP', $interface);
|
||||||
} else {
|
} 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']));
|
$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'])) {
|
if (!$remote_device_id && is_valid_hostname($lldp['lldpRemSysName'])) {
|
||||||
unset($skip_discovery);
|
$skip_discovery = false;
|
||||||
foreach ($config['autodiscovery']['xdp_exclude']['sysname_regexp'] as $filter) {
|
if ($skip_discovery === false) {
|
||||||
if (preg_match($filter ."i", $lldp['lldpRemSysName'])) {
|
$skip_discovery = can_skip_discovery($config['autodiscovery']['xdp_exclude']['sysname_regexp'], $lldp['lldpRemSysName'], $lldp['lldpRemSysName']);
|
||||||
$skip_discovery = 1;
|
|
||||||
d_echo("{$lldp['lldpRemSysName']} - regexp '{$filter}' matches '{$lldp['lldpRemSysName']}' - skipping device discovery \n");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
foreach ($config['autodiscovery']['xdp_exclude']['sysdesc_regexp'] as $filter) {
|
if ($skip_discovery === false) {
|
||||||
if (preg_match($filter ."i", $lldp['lldpRemSysDesc'])) {
|
$skip_discovery = can_skip_discovery($config['autodiscovery']['xdp_exclude']['sysdesc_regexp'], $lldp['lldpRemSysDesc'], $lldp['lldpRemSysName']);
|
||||||
$skip_discovery = 1;
|
|
||||||
d_echo("{$lldp['lldpRemSysName']} - regexp '{$filter}' matches '{$lldp['lldpRemSysDesc']}' - skipping device discovery \n");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$skip_discovery) {
|
if ($skip_discovery === false) {
|
||||||
$remote_device_id = discover_new_device($lldp['lldpRemSysName'], $device, 'LLDP', $interface);
|
$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']));
|
$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'])) {
|
if (!$remote_device_id && is_valid_hostname($lldp['lldpRemSysName'])) {
|
||||||
unset($skip_discovery);
|
$skip_discovery = false;
|
||||||
foreach ($config['autodiscovery']['xdp_exclude']['sysname_regexp'] as $filter) {
|
if ($skip_discovery === false) {
|
||||||
if (preg_match($filter ."i", $lldp['lldpRemSysName'])) {
|
$skip_discovery = can_skip_discovery($config['autodiscovery']['xdp_exclude']['sysname_regexp'], $lldp['lldpRemSysName'], $lldp['lldpRemSysName']);
|
||||||
$skip_discovery = 1;
|
|
||||||
d_echo("{$lldp['lldpRemSysName']} - regexp '{$filter}' matches '{$lldp['lldpRemSysName']}' - skipping device discovery \n");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
foreach ($config['autodiscovery']['xdp_exclude']['sysdesc_regexp'] as $filter) {
|
if ($skip_discovery === false) {
|
||||||
if (preg_match($filter ."i", $lldp['lldpRemSysDesc'])) {
|
$skip_discovery = can_skip_discovery($config['autodiscovery']['xdp_exclude']['sysdesc_regexp'], $lldp['lldpRemSysDesc'], $lldp['lldpRemSysName']);
|
||||||
$skip_discovery = 1;
|
|
||||||
d_echo("{$lldp['lldpRemSysName']} - regexp '{$filter}' matches '{$lldp['lldpRemSysDesc']}' - skipping device discovery \n");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$skip_discovery) {
|
if ($skip_discovery === true) {
|
||||||
$remote_device_id = discover_new_device($lldp['lldpRemSysName'], $device, 'LLDP', $interface);
|
$remote_device_id = discover_new_device($lldp['lldpRemSysName'], $device, 'LLDP', $interface);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1736,3 +1736,21 @@ function get_toner_levels($device, $raw_value, $capacity)
|
|||||||
|
|
||||||
return round($raw_value / $capacity * 100);
|
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;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user