Search code examples
c#snmp

C# SNMP Agent Command handler


The current context is on one side I have a system in which we have camera adaptors (that we develop) that helps us integrate cameras in the system. And on the other side we have a camera simulator.

In my camera adaptor, to get the current UpTime of the camera, I send an SNMP Get command with the correct Oid for system UpTime.

In my adaptor, I am using the SnmpSharpNet library.

public static void GetSystemUptime(string host, out TimeSpan? uptime)
{
   SimpleSnmp snmp = new SimpleSnmp();
   snmp.PeerIP = IPAddress.Parse(host);
   Oid oid = new Oid(SnmpOid.SYS_UPTIME);
   Dictionary<Oid, AsnType> dict = snmp.Get(SnmpVersion.Ver1, new[] { oid.ToString()});
   AsnType asnType;

   if (dict == null || dict.TryGetValue(oid, out asnType) == false || asnType == null || asnType.GetType() != typeof(TimeTicks))
   {
      uptime = null;
      return;
   }

   uptime = (TimeSpan)(asnType as TimeTicks);
}

But now, I'm working on the camera simulator which actually simulates cameras. So I now need to make the SNMP Agent. I can't seem to find information on how to handle Get commands in an SNMP Agent so I can afterwords reply the right information.

Can anyone link me to relevant information or guide me though the process.

Tanks,

Pat


Solution

  • https://docs.lextudio.com/blog/sharpsnmp-vs-snmpsharpnet-5fdce55232e7

    What you asked is probably what every SNMP#NET user wonders.

    SNMP#NET does not support agent development that well. You need to switch to another library, either commercial or open source.