Link to home
Start Free TrialLog in
Avatar of LadyVyxen
LadyVyxenFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Reading an SNMP OID - Code Only Solution

I have to get the value of an SNMP OID in a code only solution. I've managed to open a session, but am struggling to send an OID and return valid data. If anyone can help complete the below function, or suggest a complete code replacement, the points are theirs.

I need a NON-3rd part control/dll/ocx solution. MGMTAPI.dll is allowed because its inherent to Windows NT.

LadyVyxen.

Option Explicit
Private Declare Function SnmpMgrOpen Lib "MGMTAPI" (ByVal pszAgentAddress As Long, ByVal pszCommunityName As Long, ByVal nTimeout As Long, ByVal nRetries As Long) As Long
Private Declare Function SnmpMgrClose Lib "MGMTAPI" (ghMgmtSession As Long) As Long
Private Declare Function SnmpMgrRequest Lib "MGMTAPI" (ByVal ghMgmtSession As Long, ByVal requestType As Long, ByVal SnmpVarBindList As Long, ByVal nErrorStatus As Long, ByVal nErrorIndex As Long) As Long
Public Function GetSNMPData(ByVal strIPAddress As String, ByVal strCommunityString As String, ByVal strOID As String) As String
    Dim lngReturnCode As Long
    Dim lngSession As Long
    lngSession = SnmpMgrOpen(StrPtr(strIPAddress), StrPtr(strCommunityString), 1000, 3)
    If lngSession <> 0 Then


        ' lngReturnCode = SnmpMgrRequest(  << This is where I got stuck >>  )


        Call SnmpMgrClose(lngSession)
    End If
End Function
Sub Main()
    Debug.Print GetSNMPData("10.229.182.17", "public", "1.3.6.1.2.1.1.1.0")
End Sub
Avatar of 3rsrichard
3rsrichard

I have a couple of suggestions;

First go to a site like
http://www.dart.com/
and get a trial of their software.  Even though you don't want to use it for
your final solution, it will help you to understand the construction and rules of SNMP messages.

Second, if you want an open-source example of an SNMP library you might start here;
http://www.ibr.cs.tu-bs.de/ietf/snmpv3/
you could also go to the Linux code storage website and get a Linux version, which
would also give you good examples.

I haven't used the MS SNMP functions, but there are some examples in the MSDN
library CD's.

A further comment;
You said
I have to get the value of an SNMP OID in a code only solution.

If you only have to get one value from a fixed IP, then you could consider using
a "canned" message.  An SNMP message is such partly because it is sent
in UDP to a certain port.  You can hard code a message in the correct form
(including the BER conversion) and send it out, and if it's up the agent will
answer.
For example, your debug request is for the "SystemId" which returns a string, ie.
1.3.6.1.2.1.1.1.0     HP ETHERNET MULTI-ENVIRONMENT,ROM A.05.03,JETDIRECT,JD24,EEPROM A.05.05

from a typical HP printer.

You might have to ask for 1.3.6.1.2.1.1.1.0.0 depending on the type of request executed.
Avatar of LadyVyxen

ASKER

I've trolled through the Dart PowerTCP control, and its too high-level to be useful. I really need a function that does GetSNMPData(IP, Community, OID) that doesn't use 3'rd party. The reason for not using 3rd party is that our process for testing 3rd party products would take far longer than timescales set for this project, and I don't personally have time to dig in-depth into the protocol proper to be able to code at the winsock level.
Then you're probably out of luck.  As far as I know I am the only person
using the E-E website who ever answers questions about SNMP, and I do
not know of a free SNMP library that is easy enough to use without some
understanding of SNMP.  And writing one would be considerably more than
however many points you have.

You may eventually get MGMTAPI to work, but I'm not sure it's happy under
NT (I used to have an NT machine, and thats when I decided to use dart.).
It is built into W2000 I think, but I don't know about WME.

You are welcome to reject this, but even a "you can't do that" is an answer.
 For 300 points, "You can't do that" is not an acceptable answer when I've gotten about 80% of the code working already and just needed help with a single dll call (SnmpMgrRequest).
  It may be that noone on the list can help, which is fine, and is probably true as noone else has attempted an answer. But I *know* it *can* be done - Ive seen it done elsewhere, and I'm not after 3rd party OCXs, so this question has not been answered and is still an open query.
Avatar of DanRollins
Hi LadyVyxen,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will suggest to:

    Refund points and save as a 0-pt PAQ.

EXPERTS: Post a comment if you are certain that an expert deserves credit.  Explain why.
==========
DanRollins -- EE database cleanup volunteer
Actually, Im still waiting for an answer...!
Hi LadyVyxen,
It's a sad fact, but if a question lies dormant for even one month, it will very seldom get an answer.  This question is OVER ONE YEAR OLD!  Time to swab the deck and blow the pipes.  Stick a fork in it Lady, this one is DONE :0)

Your best bet to get an answer is to post a new question and let this one close out (A Moderator will process the refund in seven days).  The Experts keep a hawkeye out for new 300- to 500-point questions, but they never bother to check these old ones.

-- Dan
You might also consider thanking 3rsrichard for the help -- by accepting one of his comments as an answer -- even if it did not answer your question -- there was certainly some significant effort put in there.
-- Dan
ASKER CERTIFIED SOLUTION
Avatar of Computer101
Computer101
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial