0

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?

Dylan666
  • 13
  • 4
  • The protocol allows different kinds of behaviors in that scenario, so it depends on the device you are managing to return what it feels the best. – Lex Li Nov 07 '21 at 23:04
  • I know what you mean but is it possible that if just ONE OID is wrong or missing for the device all the variable is set to "nothing" and I can't get all the valid values from other OIDs in the same String() array? – Dylan666 Nov 08 '21 at 06:30

1 Answers1

0

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.

Dylan666
  • 13
  • 4