質問

I am writing an application to monitor SNMP devices and save the data into SQL. But I am running into problems with timeticks.

Most values are easily recordable as floats. The raw timeticks number would also be very easy to store. However, SNMPSharpNet, when I run (SnmpV1Packet)target.Request(pdu, param); returns a string with the value decoded: 0d 4h 56m 0s 0ms

I suppose I could parse this value, but it seems a waste of cycles to convert the number twice. How do I get the raw number of milliseconds?

役に立ちましたか?

解決

Have you tried casting the AsnType to SnmpSharpNet.TimeTicks:

UdpTarget target = new UdpTarget(IPAddress.Parse("192.168.1.1"));
Pdu pdu = new Pdu(PduType.Get);
pdu.VbList.Add("1.3.6.1.2.1.1.3.0");
AgentParameters param = new AgentParameters(SnmpVersion.Ver1, new OctetString("public"));
SnmpV1Packet packet = (SnmpV1Packet)target.Request(pdu, param);
AsnType uptimeAsn = packet.Pdu.VbList["1.3.6.1.2.1.1.3.0"].Value;

long uptime = ((TimeTicks)uptimeAsn).Milliseconds;

Console.WriteLine(uptime);
Console.WriteLine(new TimeSpan(0,0,(int)(uptime/1000)));

Just make sure to surround this with try/catch, in case the cast fails.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top