Login  
Search All Forums
Dart Home | PowerSNMP for .NET | Custom Development Reply | PowerSNMP for .NET Topics | Forums   
AuthorForum: PowerSNMP for .NET
Topic: Unable to set a value held by an agent
mc

From: United Kingdom
Posts: 5
Member Since: 10/10/14
posted October 10, 2014 10:48 AM

Hi,

Hopefully the solution to this is really easy and it's simply an error on my part...

I'm using version 4.7.0 of the library and samples.


I've attempted to narrow things down by creating a simple example of the problem I’m seeing by modifying the C# WinForms sample 'Agent' using Visual Studio 2010 (that’s the 'Agent.40' project).


I have made up the following simple MIB for this example:


TEST-MIB DEFINITIONS ::= BEGIN

IMPORTS
  MODULE-IDENTITY, enterprises      FROM SNMPv2-SMI;

testMIB MODULE-IDENTITY
  LAST-UPDATED "201410101430Z"
  ORGANIZATION "Unknown"
  CONTACT-INFO
   "me@here.com"
  DESCRIPTION
   "The Test MIB"
  ::= { test 1 }


test           OBJECT IDENTIFIER ::= { enterprises 50000 }

someNumber OBJECT-TYPE
  SYNTAX   Unsigned32
  MAX-ACCESS read-write
  STATUS   current
  DESCRIPTION
   "A number that can be read and written."
  ::= { test 1 }

END


I've used the agent ('agent1' that's part of the form for Main.cs when editing it through the designer) to generate the C# code for the above MIB file and then added it to the project (the import operation prompts to add it after you've closed the code generation dialog).

I've modified the 'finally' block of the code in the 'loadModel()' method in Main.cs to import the MIB into the agent, add a variable for 'someNumber' (in that MIB) and set it's value to '123' as follows:


Mib.Import(agent1.Mib);

string iid = agent1.Mib.GetByNodeName(Mib.NodeName.someNumber).Iid;
agent1.Variables.Add(iid, new Variable(agent1.Mib.GetByNodeName(Mib.NodeName.someNumber)));
agent1.Variables[iid].Value = new Dart.Snmp.SimpleType.OctetString("123");



I can successfully 'get' a correct return value for 'someNumber' but when attempting to 'set' it, it fails. The agent and manager are both running on the same PC but I've also run the manager on another machine with the same results, this is the detail from the Agent's message log window for the 'set':

Message Type: Dart.Snmp.SetMessage
Time Received: 10/10/2014 14:53:54
SNMP Version: One
Origin IP Address: 10.40.45.68
Destination IP Address: 10.40.45.68
Timestamp: 10/10/2014 14:53:54
Community: public
Id: 3
Variable IIDs and Values:
  1.3.6.1.4.1.50000.1.0 (someNumber): 99


This is the detail from the Agent's message log window for the 'response':

Message Type: Dart.Snmp.ResponseMessage
Time Sent: 10/10/2014 14:53:54
SNMP Version: One
Origin IP Address: 10.40.45.68
Destination IP Address: 10.40.45.68
Timestamp: 10/10/2014 14:53:54
Community: public
Id: 3
Variable IIDs and Values:
  1.3.6.1.4.1.50000.1.0 (someNumber): 99
Error Index: 1
Error Status: BadValue



I've tried this with a couple of different (and more complex) MIBs using single objects and a table but the results are always the same, it fails with an index of '1' and a status of 'BadValue'. So, what am I doing wrong? Or is the issue elsewhere?

As a side issue/question; according to the Dart documentation the error index is zero based but it would appear to be 1 based?

Thanks,
Mike
mc

From: United Kingdom
Posts: 5
Member Since: 10/10/14
posted October 10, 2014 11:09 AM

A minor change to the code added to the 'finally' block of the code in the 'loadModel()' method in Main.cs so that it doesn't throw an exception if you run it more than once:

Mib.Import(agent1.Mib);

string iid = agent1.Mib.GetByNodeName(Mib.NodeName.someNumber).Iid;

if (!agent1.Variables.ContainsKey(iid))
{
  agent1.Variables.Add(iid, new Variable(agent1.Mib.GetByNodeName(Mib.NodeName.someNumber)));
  agent1.Variables[iid].Value = new Dart.Snmp.SimpleType.UInteger(123);
}

Thanks,
Mike
mc

From: United Kingdom
Posts: 5
Member Since: 10/10/14
posted October 13, 2014 4:07 AM

Another change to correct an issue with the (hastily constructed) MIB plus extended it to include a string:

TEST-MIB DEFINITIONS ::= BEGIN

IMPORTS
  MODULE-IDENTITY, enterprises
      FROM SNMPv2-SMI
  DisplayString
      FROM SNMPv2-TC;

testMIB MODULE-IDENTITY
  LAST-UPDATED "201410101430Z"
  ORGANIZATION "Unknown"
  CONTACT-INFO
   "me@here.com"
  DESCRIPTION
   "The Test MIB"
  ::= { test 1 }


test           OBJECT IDENTIFIER ::= { enterprises 50000 }

someNumber OBJECT-TYPE
  SYNTAX   Unsigned32
  MAX-ACCESS read-write
  STATUS   current
  DESCRIPTION
   "A number that can be read and written."
  ::= { testMIB 1 }

someString OBJECT-TYPE
  SYNTAX   DisplayString (SIZE (0..255))
  MAX-ACCESS read-write
  STATUS   current
  DESCRIPTION
   "A string that can be read and written."
  ::= { testMIB 2 }

END

Attempting to set 'someNumber' still fails but setting 'someString' works.

Thanks,
Mike
mc

From: United Kingdom
Posts: 5
Member Since: 10/10/14
posted October 13, 2014 4:10 AM

And the extra code added to the 'finally' block of the code in the 'loadModel()' method in Main.cs:

iid = agent1.Mib.GetByNodeName(Mib.NodeName.someString).Iid;

if (!agent1.Variables.ContainsKey(iid))
{
  agent1.Variables.Add(iid, new Variable(agent1.Mib.GetByNodeName(Mib.NodeName.someString)));
  agent1.Variables[iid].Value = new Dart.Snmp.SimpleType.OctetString("456");
}

Thanks,
Mike
mc

From: United Kingdom
Posts: 5
Member Since: 10/10/14
posted October 13, 2014 6:33 AM

Ok, after more investigation it looks as though there's an issue regarding the agent's interpretation of the value's type.

I've extended the MIB further to cover these types; Unsigned32, DisplayString, INTEGER and Gauge32:

TEST-MIB DEFINITIONS ::= BEGIN

IMPORTS
  MODULE-IDENTITY, enterprises
      FROM SNMPv2-SMI
  DisplayString
      FROM SNMPv2-TC;

testMIB MODULE-IDENTITY
  LAST-UPDATED "201410101430Z"
  ORGANIZATION "Unknown"
  CONTACT-INFO
   "me@here.com"
  DESCRIPTION
   "The Test MIB"
  ::= { test 1 }


test           OBJECT IDENTIFIER ::= { enterprises 50000 }

someUintNumber OBJECT-TYPE
  SYNTAX   Unsigned32
  MAX-ACCESS read-write
  STATUS   current
  DESCRIPTION
   "An unsigned integer that can be read and written."
  ::= { testMIB 1 }

someString OBJECT-TYPE
  SYNTAX   DisplayString (SIZE (0..255))
  MAX-ACCESS read-write
  STATUS   current
  DESCRIPTION
   "A string that can be read and written."
  ::= { testMIB 2 }

someIntNumber OBJECT-TYPE
  SYNTAX   INTEGER
  MAX-ACCESS read-write
  STATUS   current
  DESCRIPTION
   "An integer that can be read and written."
  ::= { testMIB 3 }

someGaugeNumber OBJECT-TYPE
  SYNTAX   Gauge32
  MAX-ACCESS read-write
  STATUS   current
  DESCRIPTION
   "A gauge that can be read and written."
  ::= { testMIB 4 }

END


And the matching code

Mib.Import(agent1.Mib);

string iid = agent1.Mib.GetByNodeName(Mib.NodeName.someUintNumber).Iid;

if (!agent1.Variables.ContainsKey(iid))
{
  agent1.Variables.Add(iid, new Variable(agent1.Mib.GetByNodeName(Mib.NodeName.someUintNumber)));
  agent1.Variables[iid].Value = new Dart.Snmp.SimpleType.UInteger(123);
}

iid = agent1.Mib.GetByNodeName(Mib.NodeName.someString).Iid;

if (!agent1.Variables.ContainsKey(iid))
{
  agent1.Variables.Add(iid, new Variable(agent1.Mib.GetByNodeName(Mib.NodeName.someString)));
  agent1.Variables[iid].Value = new Dart.Snmp.SimpleType.OctetString("456");
}

iid = agent1.Mib.GetByNodeName(Mib.NodeName.someIntNumber).Iid;

if (!agent1.Variables.ContainsKey(iid))
{
  agent1.Variables.Add(iid, new Variable(agent1.Mib.GetByNodeName(Mib.NodeName.someIntNumber)));
  agent1.Variables[iid].Value = new Dart.Snmp.SimpleType.Integer(99);
}

iid = agent1.Mib.GetByNodeName(Mib.NodeName.someGaugeNumber).Iid;

if (!agent1.Variables.ContainsKey(iid))
{
  agent1.Variables.Add(iid, new Variable(agent1.Mib.GetByNodeName(Mib.NodeName.someGaugeNumber)));
  agent1.Variables[iid].Value = new Dart.Snmp.SimpleType.Gauge(77);
}


Setting each works on all except the Unsigned32.

Debugging the agent with Visual Studio 2010 and looking at the 'variable' contained within the 'request' (inside the RequestReceived() method in AgentModel.cs) and the 'Value' is being decoded as exactly the same type for both Unsigned32 and Gauge32. The info for 'Value' from the variable watch window in both cases is as below if that clarifies things:

- Value {111} Dart.Snmp.SimpleTaggedType {Dart.Snmp.SimpleType.Gauge}
- [Dart.Snmp.SimpleType.Gauge] {111} Dart.Snmp.SimpleType.Gauge
- base {111} Dart.Snmp.SimpleType.UInteger {Dart.Snmp.SimpleType.Gauge}
- base {111} Dart.Snmp.SimpleTaggedType {Dart.Snmp.SimpleType.Gauge}
- base {111} Dart.Snmp.TaggedType {Dart.Snmp.SimpleType.Gauge}


So, I assume then that internally the agent is comparing what it sees as a SimpleType.Gauge against what it's expecting which is a SimpleType.UInteger and so failing hence the 'BadValue' failure code returned?

The internal agent code isn't something I have access to so any help on this would be appreciated...

Thanks,
Mike


Jamie Powell (Admin)

From: Rome, NY USA
Posts: 448
Member Since: 03/13/07

Extra Support Options
Custom Application Development

posted October 13, 2014 12:24 PM

Mike,

Thank you for your recent forum communication. I have just sent an email to you off-line. Please let me know if you do not receive this email and I will be happy to resend it.

All the best,
Jamie
Reply | PowerSNMP for .NET Topics | Forums   
This site is powered by PowerTCP WebServer Tool PowerTCP WebServer for ActiveX