Solved

Reading an SNMP OID - Code Only Solution

Posted on 2001-06-27
12
1,421 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 

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
 

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

785 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