From 81ac2c1a039d404806a7e7c20a87c46189182f9d Mon Sep 17 00:00:00 2001 From: Harald Wolff Date: Mon, 8 Jul 2019 13:15:35 +0200 Subject: [PATCH] Fix SNMP exception handling, loop iteration --- checks/Ubiquiti.cs | 48 +++++++++++++++++++++++++++++++--------------- 1 file changed, 33 insertions(+), 15 deletions(-) diff --git a/checks/Ubiquiti.cs b/checks/Ubiquiti.cs index 141b1a1..388d161 100644 --- a/checks/Ubiquiti.cs +++ b/checks/Ubiquiti.cs @@ -5,6 +5,7 @@ using ln.snmp; using System.Collections.Generic; using ln.snmp.types; using ln.logging; +using System.Linq; namespace ln.skyscanner.checks { @@ -15,7 +16,6 @@ namespace ln.skyscanner.checks { } - public override void Check(SkyChecker skyChecker,ref SkyCheckState checkState,Node node) { UbiquityCheckState ubiquityCheckState = checkState as UbiquityCheckState; @@ -24,7 +24,24 @@ namespace ln.skyscanner.checks { using (SnmpInterface snmp = SnmpInterface.FromURI(snmpUri,skyChecker.SNMPEngine)) { - Sequence[][] ptp = snmp.snmpWalk(new string[] { + List mibs = null; + try + { + mibs = new List(); + + foreach (Sequence s in snmp.snmpWalk("1.3.6.1.2.1.1.9.1.2")) + { + Logging.Log(LogLevel.DEBUG, "Ubiquiti: snmpWalk over OIDs: {0}", (s.Items[1] as ObjectIdentifier).AsString); + mibs.Add((s.Items[1] as ObjectIdentifier).AsString); + } + + } catch (TimeoutException) + { + } + + if (mibs.Contains("1.3.6.1.4.1.41112")) // RF Device + { + Sequence[][] ptp = snmp.snmpWalk(new string[] { "1.3.6.1.4.1.41112.1.3.2.1.5", "1.3.6.1.4.1.41112.1.3.2.1.6", "1.3.6.1.4.1.41112.1.3.2.1.11", @@ -33,24 +50,25 @@ namespace ln.skyscanner.checks "1.3.6.1.4.1.41112.1.3.3.1.66" }); - foreach (Sequence[] row in ptp) - { - ubiquityCheckState.WritePerformanceValue("ptp_rx_capa", (double)((Integer)(row[0].Items[1])).LongValue); - ubiquityCheckState.WritePerformanceValue("ptp_tx_capa", (double)((Integer)(row[1].Items[1])).LongValue); - ubiquityCheckState.WritePerformanceValue("ptp_rx_pwr", (double)((Integer)(row[2].Items[1])).LongValue, -75.0,0,-80.0,0); - ubiquityCheckState.WritePerformanceValue("ptp_tx_pwr", (double)((Integer)(row[3].Items[1])).LongValue); + foreach (Sequence[] row in ptp) + { + ubiquityCheckState.WritePerformanceValue("ptp_rx_capa", (double)((Integer)(row[0].Items[1])).LongValue); + ubiquityCheckState.WritePerformanceValue("ptp_tx_capa", (double)((Integer)(row[1].Items[1])).LongValue); + ubiquityCheckState.WritePerformanceValue("ptp_rx_pwr", (double)((Integer)(row[2].Items[1])).LongValue, -75.0, 0, -80.0, 0); + ubiquityCheckState.WritePerformanceValue("ptp_tx_pwr", (double)((Integer)(row[3].Items[1])).LongValue); - long rxBytes = ((Integer)(row[4].Items[1])).LongValue; - long txBytes = ((Integer)(row[5].Items[1])).LongValue; + long rxBytes = ((Integer)(row[4].Items[1])).LongValue; + long txBytes = ((Integer)(row[5].Items[1])).LongValue; - ubiquityCheckState.RXRate.Update(rxBytes * 8); - ubiquityCheckState.TXRate.Update(txBytes * 8); + ubiquityCheckState.RXRate.Update(rxBytes * 8); + ubiquityCheckState.TXRate.Update(txBytes * 8); - ubiquityCheckState.WritePerformanceValue("ptp_rx_rate", ubiquityCheckState.RXRate.Current); - ubiquityCheckState.WritePerformanceValue("ptp_tx_rate", ubiquityCheckState.TXRate.Current); + ubiquityCheckState.WritePerformanceValue("ptp_rx_rate", ubiquityCheckState.RXRate.Current); + ubiquityCheckState.WritePerformanceValue("ptp_tx_rate", ubiquityCheckState.TXRate.Current); + } } - } + break; } checkState.CheckState = CheckState.OK; }