lextudio / sharpsnmplib

C# SNMP Library (#SNMP) - Open source SNMP implementation for C# and .NET
https://sharpsnmp.com
MIT License
358 stars 151 forks source link

How to get use named integers and other textual conventions? #683

Closed lextudio-support closed 1 month ago

lextudio-support commented 1 month ago

Hi all,

I would like to utilize the named integer values and other textual conventions for presenting variable values.
For example when I have object of a type:

TruthValue ::= TEXTUAL-CONVENTION
STATUS current
DESCRIPTION "Represents a boolean value."
SYNTAX INTEGER
{
true(1),
false(2)
}

or:

ifOperStatus OBJECT-TYPE
SYNTAX INTEGER {
up(1),
down(2),
testing(3)
}

I would like to present the value of the object as text description.
Is that possible with current version of the software?

regards
Tomek

Original Reported Date: 2012-11-22T06:01:53.093-08:00 Original CodePlex Discussion Thread ID: 404223

lextudio-support commented 1 month ago

Copied from CodePlex without authors:

How should I interpret "I would like to present the value of the object as text description"? If possible, please make up some code fragment to illustrate your ideas.

In #SNMP 8 we will try to complete the new compiler and enrich MIB support. So if your idea is useful and not hard to implement, you might see it coming in

SNMP 8.

Regards,

Lex

Original Posted Date: 2012-11-22T18:39:29.363-08:00

lextudio-support commented 1 month ago

Copied from CodePlex without authors:

Thanks for response.

Below is more detailed example what I mean.
In my application I have the SimpleObjectRegistry object which I use for translating numeric oids to textual representations

Lextm.SharpSnmpLib.Mib.SimpleObjectRegistry registry = new Lextm.SharpSnmpLib.Mib.SimpleObjectRegistry();
registry.CompileFolder( "mibs", "*");
Lextm.SharpSnmpLib.IObjectTree tree = registry.Tree;

When my application receives trap. for example the below one:
enterprise: .1.3.6.1.6.3.1.1.5.3
...
variable 2: .1.3.6.1.2.1.2.2.1.3.10 = (Integer32) 22

The following code is executed:

Lextm.SharpSnmpLib.SearchResult o = tree.Search(oid);
return o.AlternativeText;

and have all oids translated as follows:
enterprise: .iso.org.dod.internet.snmpV2.snmpModules.snmpMIB.snmpMIBObjects.snmpTraps.linkDown
variable 2: .iso.org.dod.internet.mgmt.mib-2.interfaces.ifTable.ifEntry.ifType.10 = (Integer32) 22

I can see that ifType is 22, and int the RFC1213-MIB file I can find that:
ifType OBJECT-TYPE
SYNTAX INTEGER {
other(1), -- none of the following
regular1822(2),
hdh1822(3),
...
propPointToPointSerial(22),

}
So I would like to have possibility to translate also the value and be able to present the value somehow similar to:
variable 2: .iso.org.dod.internet.mgmt.mib-2.interfaces.ifTable.ifEntry.ifType.10 = propPointToPointSerial(22)

Another example,
I use SNMP GET request for getting some information from the iso.org.dod.internet.mgmt.mib-2.interfaces.ifTable,
for example when I get physical address of first interface:
GET iso.org.dod.internet.mgmt.mib-2.interfaces.ifTable.ifEntry.ifPhysAddress.1
I receive value of type OctetString that contains some non-printable characters.

In the RFC1213 MIB I found that:

ifPhysAddress OBJECT-TYPE
SYNTAX PhysAddress

and in the SNMPv2TC MIB I found:

PhysAddress ::= TEXTUAL-CONVENTION
DISPLAY-HINT "1x:"
STATUS current
DESCRIPTION
"Represents media- or physical-level addresses."
SYNTAX OCTET STRING

So I would like to be able to present the value in the appropriate format, like follows:
0:b0:64:f:1b:c0

Please let me know If there is something that I could explain better.

Regards
Tomek O

Original Posted Date: 2012-11-23T00:07:25.71-08:00

lextudio-support commented 1 month ago

Copied from CodePlex without authors:

This discussion has been copied to a work item. Click #211 to go to the work item and continue the discussion.

Original Posted Date: 2012-11-29T02:56:45.747-08:00

lextudio-support commented 1 month ago

Marked as Answer Date: 2013-10-06T20:27:58.97-07:00