Search code examples
vb.netsnmpsnmpsharpnet

SnmpSharpNet and Get with a single wrong OID in a list


I am writing a simple application based on this example: https://snmpsharpnet.com/index.php/simplesnmp-with-vb-net/

There you can see how to get two different OID values:

Imports System
Imports SnmpSharpNet
Module Module1
    Sub Main()
        Dim host As String = "localhost"
        Dim community As String = "public"
        Dim requestOid() As String
        Dim result As Dictionary(Of Oid, AsnType)
        requestOid = New String() {"1.3.6.1.2.1.1.1.0", "1.3.6.1.2.1.1.2.0"}
        Dim snmp As SimpleSnmp = New SimpleSnmp(host, community)
        If Not snmp.Valid Then
            Console.WriteLine("Invalid hostname/community.")
            Exit Sub
        End If
        result = snmp.Get(SnmpVersion.Ver1, requestOid)
        If result IsNot Nothing Then
            Dim kvp As KeyValuePair(Of Oid, AsnType)
            For Each kvp In result
                Console.WriteLine("{0}: ({1}) {2}", kvp.Key.ToString(), _
                                  SnmpConstants.GetTypeName(kvp.Value.Type), _
                                  kvp.Value.ToString())
            Next
        Else
            Console.WriteLine("No results received.")
        End If
    End Sub
End Module

But In my tests I noticed that if the device doesn't reply to ONE of the OIDs (for example is not valid for the device I'm questioning) the the "result" is "nothing" even if the other OID is valid (and has a valid response). Is this normal? Should I open a new connection and query for each single OID to get all the anwers from the valid OIDs?


Solution

  • Found the answer:

    http://www.docs.snmpsharpnet.com/docs-0-9-0/html/T_SnmpSharpNet_SimpleSnmp.htm

    If you are using the simplest way, you will leave SuppressExceptions flag to true and get all errors causing methods to return "null" result which will not tell you why operation failed. You can change the SuppressExceptions flag to false and catch any and all exception throwing errors. Either way, have fun.