From 398d5fe2b781acdec0efa197d5c79a1b8aab654b Mon Sep 17 00:00:00 2001 From: Albert Siersema Date: Sat, 1 Feb 2020 11:01:36 +0100 Subject: [PATCH] Fixed missing PoE graphs for Cisco devices (#11087) * Fixed missing PoE graphs for Cisco devices where portIfIndex can't be retrieved from CISCO-STACK-MIB * Codeclimate & Travis error corrections Co-authored-by: PipoCanaja <38363551+PipoCanaja@users.noreply.github.com> --- includes/polling/ports.inc.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/includes/polling/ports.inc.php b/includes/polling/ports.inc.php index 043f50b11d..db2b38ba82 100644 --- a/includes/polling/ports.inc.php +++ b/includes/polling/ports.inc.php @@ -326,8 +326,18 @@ if (Config::get('enable_ports_poe')) { if ($device['os'] == 'ios' || $device['os'] == 'iosxe') { echo 'cpeExtPsePortEntry'; - $port_stats_poe = snmpwalk_cache_oid($device, 'cpeExtPsePortEntry', array(), 'CISCO-POWER-ETHERNET-EXT-MIB'); - $port_ent_to_if = snmpwalk_cache_oid($device, 'portIfIndex', array(), 'CISCO-STACK-MIB'); + $port_stats_poe = snmpwalk_cache_oid($device, 'cpeExtPsePortEntry', [], 'CISCO-POWER-ETHERNET-EXT-MIB'); + $port_ent_to_if = snmpwalk_cache_oid($device, 'portIfIndex', [], 'CISCO-STACK-MIB'); + + if (!$port_ent_to_if) { + $ifTable_ifDescr = snmpwalk_cache_oid($device, 'ifDescr', [], 'IF-MIB'); + $port_ent_to_if = []; + foreach ($ifTable_ifDescr as $if_index => $if_descr) { + if (preg_match('/^[[:alpha:]]+ethernet([0-9\/.]+)$/i', $if_descr['ifDescr'], $matches)) { + $port_ent_to_if[str_replace('/', '.', $matches[1])] = ['portIfIndex' => $if_index]; + } + } + } foreach ($port_stats_poe as $p_index => $p_stats) { //We replace the ENTITY EntIndex by the IfIndex using the portIfIndex table (stored in $port_ent_to_if).