Login  
Search All Forums
Dart Home | PowerSNMP for .NET | Custom Development Reply | PowerSNMP for .NET Topics | Forums   
AuthorForum: PowerSNMP for .NET
Topic: Using octet string as table index
andershavn

From: Denmark
Posts: 16
Member Since: 01/07/14
posted January 7, 2014 9:16 AM

Hi,

I want to use an octet string as index in my table. How do I do that with PowerSNMP? It is easy when using an integer as index:

string iid = agentEntity.Mib.GetByNodeName(Mib.NodeName.meterEntryIndex).Oid + "." + index;
   agentEntity.Variables[iid] = new Variable(iid, new UInteger(index));

Thank you.

Best Regards,
Anders Havn
Nick B (Admin)

From: Utica, NY USA
Posts: 619
Member Since: 05/25/10

Extra Support Options
Custom Application Development

posted January 7, 2014 11:28 AM

Hello Anders,

The IID (OID + Index) must be an integer value, but to set the value to an octet string, use the OctetString (inherits from SimpleTaggedType) constructor for the 2nd parameter of the Variable constructor. So:

string iid = agentEntity.Mib.GetByNodeName(Mib.NodeName.meterEntryIndex).Oid + "." + index;
agentEntity.Variables[iid] = new Variable(iid, new OctetString("mystring"));
andershavn

From: Denmark
Posts: 16
Member Since: 01/07/14
posted January 8, 2014 3:01 AM

Hi again,

Thank you for the reply. I decided to keep the index as an octet string, but then turn it into a dottet string.

...
string index = ConvertStringToIndexString(value);
string iid = agentEntity.Mib.GetByNodeName(Mib.NodeName.meterEntryIndex).Oid + "." + index;
   agentEntity.Variables[iid] = new Variable(iid, new OctetString(index));
...

private string ConvertStringToIndexString(string value)
  {
   string index = "";
   foreach (char character in value)
   {
    if (index.Length > 0)
    {
     index += ".";
    }
    index += Convert.ToInt32(character) - '0';
   }
   return index;
  }

That means the string "AB12", will become "15.16.1.2" and it works fine.

This way the manager can index into the table by only knowing the id (in this case "AB12") and get the values for this id.

Best Regards,
Anders Havn
Reply | PowerSNMP for .NET Topics | Forums   
This site is powered by PowerTCP WebServer Tool PowerTCP WebServer for ActiveX