Revert "refactor: rewrite is_valid_port()" (#7355)

* Revert "refactor: Added detection of vlan name changes (#7348)"

This reverts commit 4ad8faecdc.

* Revert "refactor: Rewrite is_valid_port() (#7337)"

This reverts commit 31607418e1.
This commit is contained in:
Neil Lathwood
2017-09-17 08:21:28 +01:00
committed by GitHub
parent 4ad8faecdc
commit b19b9e90d2
5 changed files with 83 additions and 133 deletions

View File

@@ -37,15 +37,6 @@ class Config
public static function get($key, $default = null) public static function get($key, $default = null)
{ {
global $config; global $config;
if (isset($config[$key])) {
return $config[$key];
}
if (!str_contains($key, '.')) {
return $default;
}
$keys = explode('.', $key); $keys = explode('.', $key);
$curr = &$config; $curr = &$config;
@@ -99,18 +90,9 @@ class Config
*/ */
public static function getOsSetting($os, $key, $default = null) public static function getOsSetting($os, $key, $default = null)
{ {
global $config;
if ($os) { if ($os) {
if (isset($config['os'][$os][$key])) {
return $config['os'][$os][$key];
}
if (!str_contains($key, '.')) {
return self::get($key, $default);
}
$os_key = "os.$os.$key"; $os_key = "os.$os.$key";
if (self::has($os_key)) { if (self::has($os_key)) {
return self::get($os_key); return self::get($os_key);
} }
@@ -131,21 +113,6 @@ class Config
*/ */
public static function getCombined($os, $key, $default = array()) public static function getCombined($os, $key, $default = array())
{ {
global $config;
if (!self::has($key)) {
return self::get("os.$os.$key", $default);
}
if (!isset($config['os'][$os][$key])) {
if (!str_contains($key, '.')) {
return $default;
}
if (!self::has("os.$os.$key")) {
return self::get($key, $default);
}
}
return array_unique(array_merge( return array_unique(array_merge(
(array)self::get($key, $default), (array)self::get($key, $default),
(array)self::getOsSetting($os, $key, $default) (array)self::getOsSetting($os, $key, $default)
@@ -180,15 +147,6 @@ class Config
public static function has($key) public static function has($key)
{ {
global $config; global $config;
if (isset($config[$key])) {
return true;
}
if (!str_contains($key, '.')) {
return false;
}
$keys = explode('.', $key); $keys = explode('.', $key);
$last = array_pop($keys); $last = array_pop($keys);

View File

@@ -11,28 +11,6 @@ For example, to set an alternate icon for ios:
$config['os']['ios']['icon'] = 'fuzzybunny'; $config['os']['ios']['icon'] = 'fuzzybunny';
``` ```
### Ignoring Interfaces
See also: [Global Ignoring Interfaces Config](../../Support/Configuration.md#interfaces-to-be-ignored)
> These settings are merged with the global settings, so you can only undo global ones with good_if
```yaml
empty_ifdescr: false # allow empty ifDescr
bad_if: # ifDescr (substring, case insensitive)
- lp0
bad_if_regexp: # ifDescr (regex, case insensitive)
- "/^ng[0-9]+$/"
bad_ifname_regexp: # ifName (regex, case insensitive)
- "/^xdsl_channel /"
bad_ifalias_regexp: # ifAlias (regex, case insensitive)
- "/^vlan/"
bad_iftype: # ifType (substring)
- sonet
good_if: # ignore all other bad_if settings ifDescr (substring, case insensitive)
- virtual
```
### Storage Settings ### Storage Settings
See also: [Global Storage Config](../../Support/Configuration.md#storage-configuration) See also: [Global Storage Config](../../Support/Configuration.md#storage-configuration)

View File

@@ -32,5 +32,3 @@ discovery_modules:
discovery: discovery:
- sysDescr: - sysDescr:
- Cisco Catalyst Operating System Software - Cisco Catalyst Operating System Software
bad_if:
- vlan

View File

@@ -10,6 +10,3 @@ discovery:
- sysDescr_regex: - sysDescr_regex:
- '/^DES-/' - '/^DES-/'
- '/^DGS-/' - '/^DGS-/'
good_if:
- po
- vlan

View File

@@ -11,7 +11,6 @@
* *
*/ */
use LibreNMS\Config;
use LibreNMS\Exceptions\HostExistsException; use LibreNMS\Exceptions\HostExistsException;
use LibreNMS\Exceptions\HostIpExistsException; use LibreNMS\Exceptions\HostIpExistsException;
use LibreNMS\Exceptions\HostUnreachableException; use LibreNMS\Exceptions\HostUnreachableException;
@@ -980,75 +979,95 @@ function include_dir($dir, $regex = "")
} }
} }
/**
* Check if port is valid to poll.
* Settings: empty_ifdescr, good_if, bad_if, bad_if_regexp, bad_ifname_regexp, bad_ifalias_regexp, bad_iftype
*
* @param array $port
* @param array $device
* @return bool
*/
function is_port_valid($port, $device) function is_port_valid($port, $device)
{ {
// check empty values first
if (empty($port['ifDescr'])) { global $config;
if (empty($port['ifDescr']) && empty($port['ifAlias']) && empty($port['ifName'])) {
// If these are all empty, we are just going to show blank names in the ui // If these are all empty, we are just going to show blank names in the ui
if (empty($port['ifAlias']) && empty($port['ifName'])) { $valid = 0;
return false; } else {
$valid = 1;
$if = strtolower($port['ifDescr']);
$ifname = strtolower($port['ifName']);
$ifalias = strtolower($port['ifAlias']);
$fringe = $config['bad_if'];
if (is_array($config['os'][$device['os']]['bad_if'])) {
$fringe = array_merge($config['bad_if'], $config['os'][$device['os']]['bad_if']);
} }
$config['good_if'] = $config['good_if'] ?: array();
// ifDescr should not be empty unless it is explicitly allowed if (is_array($config['os'][$device['os']]['good_if'])) {
if (!Config::getOsSetting($device['os'], 'empty_ifdescr', false)) { $good_if = array_merge($config['good_if'], $config['os'][$device['os']]['good_if']);
return false; }
foreach ($fringe as $bi) {
if (stristr($if, $bi)) {
if (!str_contains($good_if, $if)) {
$valid = 0;
d_echo("ignored : $bi : $if");
}
}
}
if (is_array($config['bad_if_regexp'])) {
$fringe = $config['bad_if_regexp'];
if (is_array($config['os'][$device['os']]['bad_if_regexp'])) {
$fringe = array_merge($config['bad_if_regexp'], $config['os'][$device['os']]['bad_if_regexp']);
}
foreach ($fringe as $bi) {
if (preg_match($bi ."i", $if)) {
$valid = 0;
d_echo("ignored : $bi : " . $if);
}
}
}
if (is_array($config['bad_ifname_regexp'])) {
$fringe = $config['bad_ifname_regexp'];
if (is_array($config['os'][$device['os']]['bad_ifname_regexp'])) {
$fringe = array_merge($config['bad_ifname_regexp'], $config['os'][$device['os']]['bad_ifname_regexp']);
}
foreach ($fringe as $bi) {
if (preg_match($bi ."i", $ifname)) {
$valid = 0;
d_echo("ignored : $bi : ".$ifname);
}
}
}
if (is_array($config['bad_ifalias_regexp'])) {
$fringe = $config['bad_ifalias_regexp'];
if (is_array($config['os'][$device['os']]['bad_ifalias_regexp'])) {
$fringe = array_merge($config['bad_ifalias_regexp'], $config['os'][$device['os']]['bad_ifalias_regexp']);
}
foreach ($fringe as $bi) {
if (preg_match($bi ."i", $ifalias)) {
$valid = 0;
d_echo("ignored : $bi : ".$ifalias);
}
}
}
if (is_array($config['bad_iftype'])) {
$fringe = $config['bad_iftype'];
if (is_array($config['os'][$device['os']]['bad_iftype'])) {
$fringe = array_merge($config['bad_iftype'], $config['os'][$device['os']]['bad_iftype']);
}
foreach ($fringe as $bi) {
if (stristr($port['ifType'], $bi)) {
$valid = 0;
d_echo("ignored ifType : ".$port['ifType']." (matched: ".$bi." )");
}
}
}
if (empty($port['ifDescr']) && !$config['os'][$device['os']]['empty_ifdescr']) {
$valid = 0;
}
if ($device['os'] == "catos" && strstr($if, "vlan")) {
$valid = 0;
}
if ($device['os'] == "dlink") {
$valid = 1;
} }
} }
$ifDescr = $port['ifDescr']; return $valid;
$ifName = $port['ifName'];
$ifAlias = $port['ifAlias'];
$ifType = $port['ifType'];
if (str_contains($ifDescr, Config::getOsSetting($device['os'], 'good_if'), true)) {
return true;
}
foreach (Config::getCombined($device['os'], 'bad_if') as $bi) {
if (str_contains($ifDescr, $bi, true)) {
d_echo("ignored by ifDescr: $ifDescr (matched: $bi)\n");
return false;
}
}
foreach (Config::getCombined($device['os'], 'bad_if_regexp') as $bir) {
if (preg_match($bir ."i", $ifDescr)) {
d_echo("ignored by ifDescr: $ifDescr (matched: $bir)\n");
return false;
}
}
foreach (Config::getCombined($device['os'], 'bad_ifname_regexp') as $bnr) {
if (preg_match($bnr ."i", $ifName)) {
d_echo("ignored by ifName: $ifName (matched: $bnr)\n");
return false;
}
}
foreach (Config::getCombined($device['os'], 'bad_ifalias_regexp') as $bar) {
if (preg_match($bar ."i", $ifAlias)) {
d_echo("ignored by ifName: $ifAlias (matched: $bar)\n");
return false;
}
}
foreach (Config::getCombined($device['os'], 'bad_iftype') as $bt) {
if (str_contains($ifType, $bt)) {
d_echo("ignored by ifType: $ifType (matched: $bt )\n");
return false;
}
}
return true;
} }
function scan_new_plugins() function scan_new_plugins()