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, wLower: 48, wUpper: 52, cLower: 45, cUpper: 55); node.WritePerformanceValue(checkService.PerformanceValueService, Name, String.Format("ups_input_{0}_voltage", n), voltage, wLower: 218.5, wUpper: 238, cLower: 212, cUpper: 245); node.WritePerformanceValue(checkService.PerformanceValueService, Name, String.Format("ups_input_{0}_current", n), current); 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, wLower: 218.5, wUpper: 238, cLower: 212, cUpper: 245); node.WritePerformanceValue(checkService.PerformanceValueService, Name, String.Format("ups_output_{0}_current", n), (double)((Integer)(output[1].Items[1])).LongValue / 10.0); node.WritePerformanceValue(checkService.PerformanceValueService, Name, String.Format("ups_output_{0}_load", n), (double)((Integer)(output[2].Items[1])).LongValue, wUpper: 50, cUpper: 75); 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); node.WritePerformanceValue(checkService.PerformanceValueService, Name, String.Format("ups_battery_{0}_minutes_remain", n), (double)((Integer)(battery[1].Items[1])).LongValue, wLower: 20, cLower: 10 ); node.WritePerformanceValue(checkService.PerformanceValueService, Name, String.Format("ups_battery_{0}_capacity", n), (double)((Integer)(battery[2].Items[1])).LongValue, wLower: 75, cLower: 50); node.WritePerformanceValue(checkService.PerformanceValueService, Name, String.Format("ups_battery_{0}_voltage", n), (double)((Integer)(battery[3].Items[1])).LongValue / 10.0); node.WritePerformanceValue(checkService.PerformanceValueService, Name, String.Format("ups_battery_{0}_temperature", n), (double)((Integer)(battery[4].Items[1])).LongValue, wUpper: 40, cUpper: 60); n++; } checkState.CheckState = CheckState.OK; return; } catch (SnmpError) { } } } checkState.CheckState = CheckState.FAIL; } public override bool IsValid(Node node) { return (node.Vendor != null) && node.Vendor.Equals("APC"); } } }