Skip to content

Commit cb70752

Browse files
authored
Cisco QoS polling cleanup (librenms#18510)
1 parent 2a6fc27 commit cb70752

File tree

1 file changed

+24
-24
lines changed

1 file changed

+24
-24
lines changed

LibreNMS/OS/Shared/Cisco.php

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -892,19 +892,22 @@ public function setQosParents($qos)
892892
public function pollQos($qos)
893893
{
894894
$poll_time = time();
895-
$preBytes = SnmpQuery::hideMib()->walk('CISCO-CLASS-BASED-QOS-MIB::cbQosCMPrePolicyByte64')->table(2);
896-
$postBytes = SnmpQuery::hideMib()->walk('CISCO-CLASS-BASED-QOS-MIB::cbQosCMPostPolicyByte64')->table(2);
897-
$dropBytes = SnmpQuery::hideMib()->walk('CISCO-CLASS-BASED-QOS-MIB::cbQosCMDropByte64')->table(2);
898-
$bufferDrops = SnmpQuery::hideMib()->walk('CISCO-CLASS-BASED-QOS-MIB::cbQosCMNoBufDropPkt64')->table(2);
899-
$prePackets = SnmpQuery::hideMib()->walk('CISCO-CLASS-BASED-QOS-MIB::cbQosCMPrePolicyPkt64')->table(2);
900-
$dropPackets = SnmpQuery::hideMib()->walk('CISCO-CLASS-BASED-QOS-MIB::cbQosCMDropPkt64')->table(2);
895+
$snmp_data = SnmpQuery::hideMib()->walk([
896+
'CISCO-CLASS-BASED-QOS-MIB::cbQosCMPrePolicyByte64',
897+
'CISCO-CLASS-BASED-QOS-MIB::cbQosCMPostPolicyByte64',
898+
'CISCO-CLASS-BASED-QOS-MIB::cbQosCMDropByte64',
899+
'CISCO-CLASS-BASED-QOS-MIB::cbQosCMNoBufDropPkt64',
900+
'CISCO-CLASS-BASED-QOS-MIB::cbQosCMPrePolicyPkt64',
901+
'CISCO-CLASS-BASED-QOS-MIB::cbQosCMDropPkt64',
902+
])->table(2);
901903

902904
foreach ($qos as $thisQos) {
903-
if ($thisQos->type == 'cisco_cbqos_classmap') {
904-
$snmp_parts = explode('.', (string) $thisQos->snmp_idx);
905+
$snmp_parts = explode('.', (string) $thisQos->snmp_idx);
906+
$data = $snmp_data[$snmp_parts[0]][$snmp_parts[1]] ?? [];
905907

908+
if ($thisQos->type == 'cisco_cbqos_classmap') {
906909
// Ignore changes to QoS maps between discovery runs
907-
if (! array_key_exists($snmp_parts[0], $preBytes) || ! array_key_exists($snmp_parts[1], $preBytes[$snmp_parts[0]])) {
910+
if (! $data) {
908911
d_echo('Cisco CBQoS ' . $thisQos->title . ' not processed because SNMP did not return any data');
909912

910913
// Null out all values so we get a break in the graph
@@ -924,36 +927,33 @@ public function pollQos($qos)
924927
}
925928

926929
// Values ony saved to RRD
927-
$thisQos->poll_data['postbytes'] = $postBytes ? $postBytes[$snmp_parts[0]][$snmp_parts[1]]['cbQosCMPostPolicyByte64'] : null;
928-
$thisQos->poll_data['bufferdrops'] = $bufferDrops ? $bufferDrops[$snmp_parts[0]][$snmp_parts[1]]['cbQosCMNoBufDropPkt64'] : null;
930+
$thisQos->poll_data['postbytes'] = $data['cbQosCMPostPolicyByte64'] ?? null;
931+
$thisQos->poll_data['bufferdrops'] = $data['cbQosCMNoBufDropPkt64'] ?? null;
929932

930933
// Cisco CBQoS is one directional
934+
$thisQos->last_polled = $poll_time;
931935
if ($thisQos->ingress) {
932-
$thisQos->last_polled = $poll_time;
933-
$thisQos->last_bytes_in = $preBytes ? (int) $preBytes[$snmp_parts[0]][$snmp_parts[1]]['cbQosCMPrePolicyByte64'] : null;
936+
$thisQos->last_bytes_in = isset($data['cbQosCMPrePolicyByte64']) ? (int) $data['cbQosCMPrePolicyByte64'] : null;
934937
$thisQos->last_bytes_out = null;
935-
$thisQos->last_bytes_drop_in = $dropBytes ? (int) $dropBytes[$snmp_parts[0]][$snmp_parts[1]]['cbQosCMDropByte64'] : null;
938+
$thisQos->last_bytes_drop_in = isset($data['cbQosCMDropByte64']) ? (int) $data['cbQosCMDropByte64'] : null;
936939
$thisQos->last_bytes_drop_out = null;
937-
$thisQos->last_packets_in = $prePackets ? (int) $prePackets[$snmp_parts[0]][$snmp_parts[1]]['cbQosCMPrePolicyPkt64'] : null;
940+
$thisQos->last_packets_in = isset($data['cbQosCMPrePolicyPkt64']) ? (int) $data['cbQosCMPrePolicyPkt64'] : null;
938941
$thisQos->last_packets_out = null;
939-
$thisQos->last_packets_drop_in = $dropPackets ? (int) $dropPackets[$snmp_parts[0]][$snmp_parts[1]]['cbQosCMDropPkt64'] : null;
942+
$thisQos->last_packets_drop_in = isset($data['cbQosCMDropPkt64']) ? (int) $data['cbQosCMDropPkt64'] : null;
940943
$thisQos->last_packets_drop_out = null;
941944
} elseif ($thisQos->egress) {
942-
$thisQos->last_polled = $poll_time;
943945
$thisQos->last_bytes_in = null;
944-
$thisQos->last_bytes_out = $preBytes ? (int) $preBytes[$snmp_parts[0]][$snmp_parts[1]]['cbQosCMPrePolicyByte64'] : null;
946+
$thisQos->last_bytes_out = isset($data['cbQosCMPrePolicyByte64']) ? (int) $data['cbQosCMPrePolicyByte64'] : null;
945947
$thisQos->last_bytes_drop_in = null;
946-
$thisQos->last_bytes_drop_out = $dropBytes ? (int) $dropBytes[$snmp_parts[0]][$snmp_parts[1]]['cbQosCMDropByte64'] : null;
948+
$thisQos->last_bytes_drop_out = isset($data['cbQosCMDropByte64']) ? (int) $data['cbQosCMDropByte64'] : null;
947949
$thisQos->last_packets_in = null;
948-
$thisQos->last_packets_out = $prePackets ? (int) $prePackets[$snmp_parts[0]][$snmp_parts[1]]['cbQosCMPrePolicyPkt64'] : null;
950+
$thisQos->last_packets_out = isset($data['cbQosCMPrePolicyPkt64']) ? (int) $data['cbQosCMPrePolicyPkt64'] : null;
949951
$thisQos->last_packets_drop_in = null;
950-
$thisQos->last_packets_drop_out = $dropPackets ? (int) $dropPackets[$snmp_parts[0]][$snmp_parts[1]]['cbQosCMDropPkt64'] : null;
952+
$thisQos->last_packets_drop_out = isset($data['cbQosCMDropPkt64']) ? (int) $data['cbQosCMDropPkt64'] : null;
951953
} else {
952954
d_echo('Cisco CBQoS ' . $thisQos->title . ' not processed because it it not marked as ingress or egress');
953955
}
954-
} elseif ($thisQos->type == 'cisco_cbqos_policymap') {
955-
// No polling for policymap
956-
} else {
956+
} elseif ($thisQos->type !== 'cisco_cbqos_policymap') { // No polling for policymap
957957
d_echo('Cisco CBQoS ' . $thisQos->type . ' not implemented in LibreNMS/OS/Shared/Cisco.php');
958958
}
959959
}

0 commit comments

Comments
 (0)