' Unbrowse SNMP Scripting Interface Demo ' ' t2sqlbuffered - demonstrates how to use the buffered mode ' using NewBufferDatabase and DeleteTrapByIdx ' ' This server buffers incoming traps and this script drains the ' buffer. As traps are succesfully stored we call DeleteTrapByIdx ' to free up memory. ' ' ' Usage: cscript t2sql_buffered.vbs ' trapdatabase = The VOTRP file where traps will be stored ' ' Licensing ' You can use this in any way you please. No warranties. ' --------------------------------------------------------------- On Error Resume Next ' -------------------------------------------------- ' Check usage & arguments ' -------------------------------------------------- Set Sout = WScript.StdOut If WScript.Arguments.Count <> 1 Then Sout.WriteLine "Usage: t2sql " WScript.Quit End If DSNName = WScript.Arguments.Item(0) Stopping = False Set RepMgr = CreateObject("UnbrowseSNMP.RepositoryManager") Set RepDB = RepMgr.LoadRepositoryReadOnly ' -------------------------------------------------- ' Create the trap server ' -------------------------------------------------- Set TrapMgr = WScript.CreateObject("UnbrowseSNMP.TrapReceiver") Sout.WriteLine "Loaded the Unbrowse SNMP Trap Server" TrapMgr.UDPServerMode=True TrapMgr.UDPServerPort=162 ' -------------------------------------------------- ' Open in Buffered Mode - use this for long running ' -------------------------------------------------- TrapMgr.NewBufferDatabase ' -------------------------------------------------- ' Start the passive trap receiver ' -------------------------------------------------- Sout.WriteLine "Starting .." Stopping=False TrapMgr.SetTrapFilter "","ggsn-.1.3.6.1.4.1.9.9.498.2.0.4" TrapMgr.Start Sout.WriteLine "Listening for traps .." LastTrapID = 0 While True EndId = TrapMgr.TrapCount Sout.WriteLine "End Id ." & EndId For Id = LastTrapID To EndId - 1 Sout.WriteLine "Processing .....ID:" & Id Set Trp = TrapMgr.GetTrapByIdx(Id) PrintTrap(Trp) ' Delete the previous trap, we are done with it TrapMgr.DeleteTrapByIdx(Id-1) Next LastTrapID = EndId WScript.Sleep 100 Wend ' -------------------------------------------------- ' Stop the trap receiver ' -------------------------------------------------- Sout.WriteLine "Stopping the trap receiver" ' Wait for script to catch up with server WScript.Sleep 3000 TrapMgr.Stop ' -------------------------------------------------- ' Save contents into the database given by user ' -------------------------------------------------- Sout.WriteLine "Closing trap receiver" TrapMgr.Close TrapMgr = Nil Sout.WriteLine "Done" WScript.Quit 0 ' --------------------------------------------------- ' PrintTrap : Subroutine ' Dumps almost all trap information onto screen ' --------------------------------------------------- Sub PrintTrap (OneTrap) ' -------------------------- ' Print all trap information ' -------------------------- Sout.WriteLine " ------------------------------------------" Sout.WriteLine " Trap ID : " & OneTrap.ID Sout.WriteLine " OID : " & OneTrap.EffectiveTrapOID Sout.WriteLine " From Agent : " & OneTrap.AgentAddress Sout.WriteLine " To Manager : " & OneTrap.DestinationAddress Sout.WriteLine " Timestamp : " & OneTrap.TimestampLocal Sout.WriteLine " OID : " & OneTrap.EffectiveTrapOID Sout.WriteLine " User/Comm : " & OneTrap.UserCommunity Sout.WriteLine " Varbinds : " & OneTrap.VarbindCount ' -------------------------- ' Print all varbinds in trap ' -------------------------- Sout.WriteLine " --------- Varbind list ----------" For I = 0 To OneTrap.VarbindCount - 1 Set OneVar = OneTrap.GetVarbindByIdx(I) Sout.WriteLine vbTab & " " & I+1 & " ) " & OneVar.OID & " = " & OneVar.Value Next Sout.WriteLine vbCrLf End Sub ' --------------------------------------------------- ' PrintTrap2 : Subroutine ' Dummy simply translates OID ' --------------------------------------------------- Sub PrintTrap2 (OneTrap) Sout.WriteLine " OID : " & OneTrap.EffectiveTrapOID Sout.WriteLine " OID : " & RepDB.OIDToNamePrefix(OneTrap.EffectiveTrapOID) Sout.WriteLine "----------------------------------------------------" Sout.WriteLine vbCrLf End Sub