[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Accessing MIBs programatically using WMI

Posted on 2004-09-24
9
Medium Priority
?
890 Views
Last Modified: 2012-06-21
I found this example on technet and it works great.  If i open up the RFC1213 MIB and look around I can change the code to access different OIDs.  The question I have is how does one know what to put in script to access another MIB?  They use the string "SNMP_RFC1213_MIB_ifTable".  What if I want to use a different MIB?

strTargetSnmpDevice = "192.168.0.1"
Set objWmiLocator = CreateObject("WbemScripting.SWbemLocator")
Set objWmiServices = objWmiLocator.ConnectServer("", "root\snmp\localhost")
Set objWmiNamedValueSet = CreateObject("WbemScripting.SWbemNamedValueSet")
objWmiNamedValueSet.Add "AgentAddress", strTargetSnmpDevice
objWmiNamedValueSet.Add "AgentReadCommunityName", "public"
Set colIfTable = objWmiServices.InstancesOf("SNMP_RFC1213_MIB_ifTable", , _
                                            objWmiNamedValueSet)
For Each objInterface In colIfTable
    WScript.Echo "ifIndex [Key]:        " & objInterface.ifIndex  & vbCrLf & _
        "   ifAdminStatus:     " & objInterface.ifAdminStatus     & vbCrLf & _
        "   ifDescr:           " & objInterface.ifDescr           & vbCrLf & _
        "   ifInDiscards:      " & objInterface.ifInDiscards      & vbCrLf & _
        "   ifInErrors:        " & objInterface.ifInErrors        & vbCrLf & _
        "   ifInNUcastPkts:    " & objInterface.ifInNUcastPkts    & vbCrLf & _
        "   ifInOctets:        " & objInterface.ifInOctets        & vbCrLf & _
        "   ifInUcastPkts:     " & objInterface.ifInUcastPkts     & vbCrLf & _
        "   ifInUnknownProtos: " & objInterface.ifInUnknownProtos & vbCrLf & _
        "   ifLastChange:      " & objInterface.ifLastChange      & vbCrLf & _
        "   ifMtu:             " & objInterface.ifMtu             & vbCrLf & _
        "   ifOperStatus:      " & objInterface.ifOperStatus      & vbCrLf & _
        "   ifOutDiscards:     " & objInterface.ifOutDiscards     & vbCrLf & _
        "   ifOutErrors:       " & objInterface.ifOutErrors       & vbCrLf & _
        "   ifOutNUcastPkts:   " & objInterface.ifOutNUcastPkts   & vbCrLf & _
        "   ifOutOctets:       " & objInterface.ifOutOctets       & vbCrLf & _
        "   ifOutQLen:         " & objInterface.ifOutQLen         & vbCrLf & _
        "   ifOutUcastPkts:    " & objInterface.ifOutUcastPkts    & vbCrLf & _
        "   ifPhysAddress:     " & objInterface.ifPhysAddress     & vbCrLf & _
        "   ifSpecific:        " & objInterface.ifSpecific        & vbCrLf & _
        "   ifSpeed:           " & objInterface.ifSpeed           & vbCrLf & _
        "   ifType:            " & objInterface.ifType            & vbCrLf
Next
0
Comment
Question by:stealth188
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
9 Comments
 
LVL 41

Expert Comment

by:graye
ID: 12150589
I'd suggest that you use the WMI tools from microsoft to browse the SNMP namespaces
http://www.microsoft.com/downloads/details.aspx?FamilyId=6430F853-1120-48DB-8CC5-F2ABDC3ED314&displaylang=en
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 12157069
What is your requirement that makes you ask this question?  What information are you needing to access with WMI?

Bob
0
 
LVL 1

Author Comment

by:stealth188
ID: 12157533
I am trying to access the following OID.  A gentleman was kind enough to tell me where to find the data but now that I am trying to implement it i'm consfused about how to tell WMI what MIB to look at.

http://www.experts-exchange.com/Hardware/Routers/Q_21143208.html
0
 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

 
LVL 1

Author Comment

by:stealth188
ID: 12157721
I can't see where I can pass a community string when I am trying to connect to "root\snmp\localhost".  It just gives me an error saying that WMI is unavailable on that host.  Makes sense because it isn't a Windows device.  I'm sure i'm being dense but can you give me a hint as to how I can connect using the tools?
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 12159333
Here is the .NET way:

   Public Function SystemDriverList() As ArrayList

      Dim arrayDrivers As ArrayList = New ArrayList

      Try

         Dim searchDrivers As System.Management.ManagementObjectSearcher = _
            New System.Management.ManagementObjectSearcher( _
            "Select * FROM Win32_SystemDriver")

         Dim objectDriver As System.Management.ManagementObject

         For Each objectDriver In searchDrivers.Get()

            arrayDrivers.Add(objectDriver("Name").ToString)

         Next

      Catch ex As Exception

         MessageBox.Show(ex.Message)

      End Try

      Return arrayDrivers

   End Function

We would just need to find the Win32 WMI class that provides you the information that you need.

Bob
0
 
LVL 1

Author Comment

by:stealth188
ID: 12160866
.Net says that system.management.managementobjectsearcher is not a valid namespace.  Do I need to install something in order to access the namespace?
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 12160901
Yes, you need to add a reference to the System.Management.dll.

Bob
0
 
LVL 1

Author Comment

by:stealth188
ID: 12163697
That seems to return a list of services on my local PC.  How can I convince it to interrogate the router?

Thanks!
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 1500 total points
ID: 12163732
I am sorry for the confusion.  I was trying to say that this is only a starting example.  We need to find the right Win32 class and the properties for the device you are querying.  Here is a list of the Win32 classes:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/win32_classes.asp

Bob
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

649 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