I'm trying to monitor system up time by using #snmp (Lextm.SharpSnmpLib.9.0.1) and C#.
Here's my code:
public int GetUptime()
{
var uptimeMessage = new GetNextRequestMessage(0, VersionCode.V1, new OctetString("public"),
new List<Variable>
{
new Variable(new ObjectIdentifier(Oids.SystemUpTime))
});
var response = uptimeMessage.GetResponse(10000, _agentEndPoint);
var ticks = response.Pdu().Variables[0].Data.ToString();
return int.Parse(ticks);
}
But i'm getting a CS0103 error when trying to get .Data property for a response of type TimeTicks.
Here's the Inspection Window of VS2015
If this is not a bug, how can i access raw ticks value using #snmp ?
By checking the source code of TimeTicks
in this library you can see the ToString
method in fact generates a string based in .NET TimeSpan
. That's why when you try to parse it as int
exceptions come.
As for this OID you already know the Data
would be a TimeTicks
you should cast to that type and then call ToUInt32
.