ln.skyscanner/checks/APC.cs

99 lines
5.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 Microsoft.Win32.SafeHandles;
using Renci.SshNet.Messages.Connection;
using ln.skyscanner.services;
namespace ln.skyscanner.checks
{
public class APC : SkyCheck
{
public APC()
:base("apc")
{
}
public override void Check(CheckService checkService, ref SkyCheckState checkState,Node node)
{
foreach (URI snmpUri in node.FindURIs("snmp"))
{
using (SnmpInterface snmp = SnmpInterface.FromURI(snmpUri,checkService.SNMPEngine))
{
try
{
Sequence[][] inputs = snmp.snmpWalk(new string[]{
"1.3.6.1.2.1.33.1.3.3.1.2",
"1.3.6.1.2.1.33.1.3.3.1.3",
"1.3.6.1.2.1.33.1.3.3.1.4"
});
Sequence[][] outputs = snmp.snmpWalk(new string[]{
"1.3.6.1.2.1.33.1.4.4.1.2",
"1.3.6.1.2.1.33.1.4.4.1.3",
"1.3.6.1.2.1.33.1.4.4.1.5"
});
Sequence[][] batteries = snmp.snmpWalk(new string[] {
"1.3.6.1.2.1.33.1.2.1",
"1.3.6.1.2.1.33.1.2.3",
"1.3.6.1.2.1.33.1.2.4",
"1.3.6.1.2.1.33.1.2.5",
"1.3.6.1.2.1.33.1.2.7"
});
int n = 0;
foreach (Sequence[] input in inputs)
{
double frequency = (double)((Integer)(input[0].Items[1])).LongValue / 10.0;
double voltage = (double)((Integer)(input[1].Items[1])).LongValue;
double current = (double)((Integer)(input[2].Items[1])).LongValue;
node.WritePerformanceValue(checkService.PerformanceValueService, Name, String.Format("ups_input_{0}_frequency", n), frequency, 48, 52, 45, 55, "Hz");
node.WritePerformanceValue(checkService.PerformanceValueService, Name, String.Format("ups_input_{0}_voltage", n), voltage, 218.5, 238, 212, 245, "V");
node.WritePerformanceValue(checkService.PerformanceValueService, Name, String.Format("ups_input_{0}_current", n), current, perfUnit: "A");
n++;
}
n = 0;
foreach (Sequence[] output in outputs)
{
node.WritePerformanceValue(checkService.PerformanceValueService, Name, String.Format("ups_output_{0}_voltage", n), (double)((Integer)(output[0].Items[1])).LongValue, 218.5, 238, 212, 245, "V");
node.WritePerformanceValue(checkService.PerformanceValueService, Name, String.Format("ups_output_{0}_current", n), (double)((Integer)(output[1].Items[1])).LongValue / 10.0, perfUnit: "A");
node.WritePerformanceValue(checkService.PerformanceValueService, Name, String.Format("ups_output_{0}_load", n), (double)((Integer)(output[2].Items[1])).LongValue, 50, 75, perfUnit: "%");
n++;
}
n = 0;
foreach (Sequence[] battery in batteries)
{
node.WritePerformanceValue(checkService.PerformanceValueService, Name, String.Format("ups_battery_{0}_status", n), (double)((Integer)(battery[0].Items[1])).LongValue, perfUnit: "");
node.WritePerformanceValue(checkService.PerformanceValueService, Name, String.Format("ups_battery_{0}_minutes_remain", n), (double)((Integer)(battery[1].Items[1])).LongValue, wLower: 20, cLower: 10, perfUnit: "min");
node.WritePerformanceValue(checkService.PerformanceValueService, Name, String.Format("ups_battery_{0}_capacity", n), (double)((Integer)(battery[2].Items[1])).LongValue / 100.0, wLower: 0.75, cLower: 0.50, perfUnit: "%");
node.WritePerformanceValue(checkService.PerformanceValueService, Name, String.Format("ups_battery_{0}_voltage", n), (double)((Integer)(battery[3].Items[1])).LongValue / 10.0, perfUnit: "V");
node.WritePerformanceValue(checkService.PerformanceValueService, Name, String.Format("ups_battery_{0}_temperature", n), (double)((Integer)(battery[4].Items[1])).LongValue, wUpper: 40, cUpper: 60, perfUnit: "°C");
n++;
}
checkState.CheckState = CheckState.OK;
return;
} catch (TimeoutException)
{
} catch (SnmpError)
{
}
}
}
checkState.CheckState = CheckState.FAIL;
}
public override bool IsValid(Node node)
{
return (node.Vendor != null) && node.Vendor.Equals("APC");
}
}
}