Solved

Reading an SNMP OID - Code Only Solution

Posted on 2001-06-27
12
1,410 Views
Last Modified: 2012-08-13
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
0
Comment
Question by:LadyVyxen
  • 5
  • 3
  • 3
  • +1
12 Comments
 
LVL 3

Expert Comment

by:3rsrichard
ID: 6231216
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.

0
 
LVL 3

Expert Comment

by:3rsrichard
ID: 6231652
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.
0
 
LVL 3

Expert Comment

by:3rsrichard
ID: 6232465
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.
0
 

Author Comment

by:LadyVyxen
ID: 6234115
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.
0
 
LVL 3

Expert Comment

by:3rsrichard
ID: 6234874
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.

0
 
LVL 3

Expert Comment

by:3rsrichard
ID: 6253428
You are welcome to reject this, but even a "you can't do that" is an answer.
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:LadyVyxen
ID: 6254512
 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.
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 7139866
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
0
 

Author Comment

by:LadyVyxen
ID: 7140061
Actually, Im still waiting for an answer...!
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 7140129
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
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 7140141
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
0
 
LVL 1

Accepted Solution

by:
Computer101 earned 0 total points
ID: 7178869
Placed in PAQ

Computer101
E-E Moderator
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now