diff --git a/includes/discovery/ports.inc.php b/includes/discovery/ports.inc.php index 4170ed616c..98228666e1 100644 --- a/includes/discovery/ports.inc.php +++ b/includes/discovery/ports.inc.php @@ -10,6 +10,11 @@ $port_stats = snmpwalk_cache_oid($device, 'ifAlias', $port_stats, 'IF-MIB'); $port_stats = snmpwalk_cache_oid($device, 'ifType', $port_stats, 'IF-MIB'); $port_stats = snmpwalk_cache_oid($device, 'ifOperStatus', $port_stats, 'IF-MIB'); +// Get correct eth0 port status for AirFiber 5XHD devices +if ($device['os'] == 'airos-af-ltu') { + require 'ports/airos-af-ltu.inc.php'; +} + // End Building SNMP Cache Array d_echo($port_stats); diff --git a/includes/discovery/ports/airos-af-ltu.inc.php b/includes/discovery/ports/airos-af-ltu.inc.php new file mode 100644 index 0000000000..1f6455e59a --- /dev/null +++ b/includes/discovery/ports/airos-af-ltu.inc.php @@ -0,0 +1,46 @@ +. + * + * @package LibreNMS + * @link http://librenms.org + * @copyright 2020 Denny Friebe + * @author Denny Friebe + */ + +$airos_eth_stat = snmpwalk_cache_oid($device, 'afLTUethConnected', array(), 'UBNT-AFLTU-MIB', null, '-OteQUsb'); + +foreach ($port_stats as $index => $afport_stats) { + if ($afport_stats['ifDescr'] == 'eth0') { + if (isset($airos_eth_stat[0]['afLTUethConnected'])) { + $port_stats[$index]['ifOperStatus'] = ($airos_eth_stat[0]['afLTUethConnected'] == 1 ? "up" : "down"); + } else { + /** + * Ubiquiti uses separate OIDs for ethernet status. Sometimes the devices have difficulties to return + * a value for the OID "afLTUethConnected". + * Because "IF-MIB" reads wrong information we remove the existing entry for "eth0" if "afLTUethConnected" + * could not be read to prevent wrong information from being stored. + */ + + unset($port_stats[$index]); + } + break; + } +} + +unset($airos_eth_stat); diff --git a/includes/polling/ports/os/airos-af-ltu.inc.php b/includes/polling/ports/os/airos-af-ltu.inc.php index 35e7dff4f9..da86a8adab 100644 --- a/includes/polling/ports/os/airos-af-ltu.inc.php +++ b/includes/polling/ports/os/airos-af-ltu.inc.php @@ -25,18 +25,26 @@ $airos_stats = snmpwalk_cache_oid($device, '.1.3.6.1.4.1.41112.1.10.1.6', array(), 'UBNT-AFLTU-MIB'); -if (isset($airos_stats[0]['afLTUethConnected'])) { - foreach ($port_stats as $index => $afport_stats) { - if ($afport_stats['ifDescr'] == 'eth0') { +foreach ($port_stats as $index => $afport_stats) { + if ($afport_stats['ifDescr'] == 'eth0') { + if (isset($airos_stats[0]['afLTUethConnected'])) { $port_stats[$index]['ifOperStatus'] = ($airos_stats[0]['afLTUethConnected'] == "connected" ? "up" : "down"); $port_stats[$index]['ifHCInOctets'] = $airos_stats[0]['afLTUethRxBytes']; $port_stats[$index]['ifHCOutOctets'] = $airos_stats[0]['afLTUethTxBytes']; $port_stats[$index]['ifHCInUcastPkts'] = $airos_stats[0]['afLTUethRxPps']; $port_stats[$index]['ifHCOutUcastPkts'] = $airos_stats[0]['afLTUethTxPps']; $port_stats[$index]['ifHighSpeed'] = '1000'; + } else { + /** + * Ubiquiti uses separate OIDs for ethernet status. Sometimes the devices have difficulties to return + * a value for the OID "afLTUethConnected". + * Because "IF-MIB" reads wrong information we remove the existing entry for "eth0" if "afLTUethConnected" + * could not be read to prevent wrong information from being stored. + */ - break; + unset($port_stats[$index]); } + break; } } diff --git a/tests/data/airos-af-ltu.json b/tests/data/airos-af-ltu.json index 4d5b531dd9..5a2d7d3c8d 100644 --- a/tests/data/airos-af-ltu.json +++ b/tests/data/airos-af-ltu.json @@ -163,7 +163,7 @@ "ifPromiscuousMode": null, "ifHighSpeed": null, "ifHighSpeed_prev": null, - "ifOperStatus": "down", + "ifOperStatus": "up", "ifOperStatus_prev": null, "ifAdminStatus": null, "ifAdminStatus_prev": null, @@ -1131,7 +1131,7 @@ "ifHighSpeed": 1000, "ifHighSpeed_prev": null, "ifOperStatus": "up", - "ifOperStatus_prev": "down", + "ifOperStatus_prev": "up", "ifAdminStatus": "up", "ifAdminStatus_prev": null, "ifDuplex": null, diff --git a/tests/data/airos-af-ltu_1.4.0.json b/tests/data/airos-af-ltu_1.4.0.json index 50705d7f9d..63be38475c 100644 --- a/tests/data/airos-af-ltu_1.4.0.json +++ b/tests/data/airos-af-ltu_1.4.0.json @@ -163,7 +163,7 @@ "ifPromiscuousMode": null, "ifHighSpeed": null, "ifHighSpeed_prev": null, - "ifOperStatus": "down", + "ifOperStatus": "up", "ifOperStatus_prev": null, "ifAdminStatus": null, "ifAdminStatus_prev": null, @@ -917,7 +917,7 @@ "ifHighSpeed": 1000, "ifHighSpeed_prev": null, "ifOperStatus": "up", - "ifOperStatus_prev": "down", + "ifOperStatus_prev": "up", "ifAdminStatus": "up", "ifAdminStatus_prev": null, "ifDuplex": null,