ln.skyscanner/checks/Ubiquiti.cs

106 lines
4.2 KiB
C#

using System;
using ln.skyscanner.entities;
using ln.types;
using ln.snmp;
using System.Collections.Generic;
using ln.snmp.types;
using ln.logging;
using System.Linq;
using ln.skyscanner.services;
namespace ln.skyscanner.checks
{
public class Ubiquiti : SkyCheck
{
public Ubiquiti()
:base("ubiquiti")
{
}
public override void Check(CheckService checkService,ref SkyCheckState checkState,Node node)
{
UbiquityCheckState ubiquityCheckState = checkState as UbiquityCheckState;
foreach (URI snmpUri in node.FindURIs("snmp"))
{
using (SnmpInterface snmp = SnmpInterface.FromURI(snmpUri,checkService.SNMPEngine))
{
List<String> mibs = null;
try
{
mibs = new List<String>();
foreach (Sequence s in snmp.snmpWalk("1.3.6.1.2.1.1.9.1.2"))
{
if (CheckService.DEBUG)
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",
"1.3.6.1.4.1.41112.1.3.2.1.14",
"1.3.6.1.4.1.41112.1.3.3.1.64",
"1.3.6.1.4.1.41112.1.3.3.1.66"
});
foreach (Sequence[] row in ptp)
{
node.WritePerformanceValue(checkService.PerformanceValueService, Name, "ptp_rx_capa", (double)((Integer)(row[0].Items[1])).LongValue);
node.WritePerformanceValue(checkService.PerformanceValueService, Name, "ptp_tx_capa", (double)((Integer)(row[1].Items[1])).LongValue);
node.WritePerformanceValue(checkService.PerformanceValueService, Name, "ptp_rx_pwr", (double)((Integer)(row[2].Items[1])).LongValue, -75.0, 0, -80.0, 0);
node.WritePerformanceValue(checkService.PerformanceValueService, Name, "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;
ubiquityCheckState.RXRate.Update(rxBytes * 8);
ubiquityCheckState.TXRate.Update(txBytes * 8);
node.WritePerformanceValue(checkService.PerformanceValueService, Name, "ptp_rx_rate", ubiquityCheckState.RXRate.Current);
node.WritePerformanceValue(checkService.PerformanceValueService, Name, "ptp_tx_rate", ubiquityCheckState.TXRate.Current);
}
}
}
break;
}
checkState.CheckState = CheckState.OK;
}
public override bool IsValid(Node node)
{
return (node.Vendor != null) && node.Vendor.Equals("Ubiquiti");
}
public override SkyCheckState PrepareCheckState(CheckService skyChecker, Node node)
{
return new UbiquityCheckState(this, node);
}
}
class UbiquityCheckState : SkyCheckState
{
public dVdT RXRate { get; private set; }
public dVdT TXRate { get; private set; }
public UbiquityCheckState(SkyCheck skyCheck,Node node)
:base(skyCheck,node)
{
RXRate = new dVdT();
TXRate = new dVdT();
}
private UbiquityCheckState()
{ }
}
}