' ' walktree - Walk a MIB subtree or leaf ' ' Usage : walktree ' ' Example : cscript walktree.vbs gwrouter1 ifTable ' cscript walktree.vbs gwrouter1 .1.3.6.1.4.155.6.1.1 ' ' The MIB you are walking must be loaded into Unbrowse ' The Agent must be defined in Unbrowse ' ' ----------------------------------------------------------------- ' -------------------------------------------------- ' Check usage & arguments ' -------------------------------------------------- Set Sout = WScript.StdOut if WScript.Arguments.Count <> 2 then Sout.WriteLine "Usage: walktree agent-name mib-name-or-oid" WScript.Quit end if AgentName = WScript.Arguments.Item(0) ' -------------------------------------------------- ' Simple way to figure out whether input is OID ' -------------------------------------------------- InpStr = WScript.Arguments.Item(1) InpOID = True If InStr(InpStr,".") Then InpOID = True Else InpOID = False End If ' -------------------------------------------------- ' Find the OID & Module corresponding to the supplied name ' -------------------------------------------------- Set RepMgr = CreateObject("UnbrowseSNMP.RepositoryManager") Set RepDB = RepMgr.LoadRepositoryReadOnly Dim NodeOID Dim NodeName Dim ModuleInfo Set OIDTable = RepDB.OIDIndexTable If Not InpOID Then Set OIDEntry = OIDTable.FindNameMatch (InpStr,0) Set ModuleInfo = OIDEntry.ModuleInfo NodeOID = OIDEntry.OID NodeName = InpStr Else Set OIDEntry = OIDTable.FindMatch (InpStr) Set ModuleInfo = OIDEntry.ModuleInfo NodeOID = InpStr NodeName = OIDEntry.Name End If Sout.WriteLine "Located node " & NodeName & " in " & ModuleInfo.ModuleName & " OID= " & NodeOID ' -------------------------------------------------- ' Load the MIB module and get the SMI node (to be passed to walker) ' -------------------------------------------------- Set MIBBrowser = CreateObject("UnbrowseSNMP.MIBBrowser") Set MIBModule = MIBBrowser.Open(ModuleInfo.PathURI) Set MIBNode = MIBModule.FindBestOIDMatch(NodeOID) ' -------------------------------------------------- ' Create a MIB walker object and set the MIB node and agent ' -------------------------------------------------- Set WalkMgr = CreateObject("UnbrowseSNMP.MIBWalker") WalkMgr.NewWalkSession Set Walker = WalkMgr.NewWalker() ' -------------------------------------------------- ' Find and set the agent to retrieve data from ' -------------------------------------------------- Set AgentMgr = CreateObject("UnbrowseSNMP.AgentManager") AgentMgr.InitReadOnly Set MyAgent = AgentMgr.FindAgent(AgentName) Walker.SetAgent(MyAgent) ' -------------------------------------------------- ' Add the SMI node located 3 steps earlier ' -------------------------------------------------- Walker.GetWalkTree.AddSmiNode MIBNode ' -------------------------------------------------- ' Do a walk - SNMP v1,v2c,v3 etc depends on agent ' -------------------------------------------------- Walker.DoWalk ' -------------------------------------------------- ' Print results of walk ' -------------------------------------------------- PrintWalkSess(Walker) Wscript.Quit ' -------------------------------------------------- ' Helper - demonstrates navigating result object ' and printing output ' -------------------------------------------------- Sub PrintWalkSess ( WalkSession ) Sout.WriteLine "Printing results " Set WalkResults = WalkSession.GetResults Set ResultsTree = WalkResults.GetWalkTree Sout.WriteLine "Result nodes = " & ResultsTree.ChildCount For J = 0 To ResultsTree.ChildCount - 1 Set WalkNode = ResultsTree.ChildByIdx(J) If WalkNode.WNodeType = 0 Then PrintScalarVarbind (WalkNode) End If If WalkNode.WNodeType = 2 Then PrintTableVarbind (WalkNode) End If Next End Sub ' -------------------------------------------------- ' Helper - print scalar object like sysUpTime ' -------------------------------------------------- Sub PrintScalarVarbind ( WalkNode ) If WalkNode.HasScalarVarbind Then Set Varb = WalkNode.ScalarVarbind Sout.WriteLine "OID = " & Varb.OID & " Val = " & Varb.Value End If End Sub ' -------------------------------------------------- ' Helper - print a table ' -------------------------------------------------- Sub PrintTableVarbind ( WalkNode ) Sout.WriteLine "Printing Table " & WalkNode.OIDName Sout.WriteLine "-------------------------------------------------------------------" Set TableEntry = WalkNode.FirstChild Sout.WriteLine "Table Entry " & TableEntry.OIDName For I = 0 To TableEntry.ChildCount-1 Set Leaf = TableEntry.ChildByIdx (I) For K = 0 To Leaf.TableVarbindCount-1 Set Varb = Leaf.TableVarbindByIdx (K) Sout.WriteLine "OID = " & Leaf.OID & "Index = " & Varb.OID & " Val = " & Varb.Value Next Next Sout.WriteLine "-------------------------------------------------------------------" End Sub