0

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 enter image description here

If this is not a bug, how can i access raw ticks value using #snmp ?

Nomada
  • 343
  • 2
  • 10
  • Looks like something in `Data` is trying to access the non-existent `count` when it should be accessing `_count`. – wablab Jun 16 '16 at 12:05
  • @Nomada Just out of interest is Oid.SystemUpTime a dotted oid string or string oid? Am looking to convert a string oid to its dotted oid equivalent. Any code example would be great. – Joseph Jul 04 '16 at 07:41
  • @Joseph Oids is a static class with const strings: For example: `public const string SysUpTime = "1.3.6.1.2.1.1.3";` `public const string SystemUpTime = "1.3.6.1.2.1.25.1.1";` – Nomada Jul 04 '16 at 10:43
  • @Nomada oh cool, thanks – Joseph Jul 04 '16 at 12:13

1 Answers1

1

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.

Lex Li
  • 60,503
  • 9
  • 116
  • 147