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

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

View File

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

View File

@@ -11,7 +11,6 @@
*
*/
use LibreNMS\Config;
use LibreNMS\Exceptions\HostExistsException;
use LibreNMS\Exceptions\HostIpExistsException;
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)
{
// 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 (empty($port['ifAlias']) && empty($port['ifName'])) {
return false;
$valid = 0;
} 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']);
}
// ifDescr should not be empty unless it is explicitly allowed
if (!Config::getOsSetting($device['os'], 'empty_ifdescr', false)) {
return false;
$config['good_if'] = $config['good_if'] ?: array();
if (is_array($config['os'][$device['os']]['good_if'])) {
$good_if = array_merge($config['good_if'], $config['os'][$device['os']]['good_if']);
}
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'];
$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;
return $valid;
}
function scan_new_plugins()