BLOG     |     FORUM
Code Samples

Unbrowse SNMP Scripting - Sample Code

You can use these samples as a starting point for your own powerful scripts

Instructions

  1. Click on the sample code link. The code will open in a new window.
  2. Save the script to a file on your computer.
  3. For VBScript code, type in "CSCRIPT <filename.vbs> <parameters>"
  4. For Ruby code, you need to download and install Ruby from http://rubyinstaller.org/

Samples

Sample 1 : PRTRAP.VBS
Prints out details of all traps in a trap database (VOTRP) file.
VBScript (prtrap.vbs)
Sample 2 : CTRLTRAP.VBS
Start the trap receiver, process a number of traps in real time (as they arrive), then close the trap receiver.
VBScript (ctrltrap.vbs)
Sample 3 : PRWALKER.VBS
Print out contents of a MIB walk database.
VBScript (prwalker.vbs)
Sample 4 : OIDTRANS.VBS
Lookup the OID of any given SNMP node. Illustrates the use of the MIB Repository object.
VBScript (oidtrans.vbs)
Sample 5 : PRNODE.VBS
Print the complete description of any SNMP node. Illustrates the use of the MIB Repository and MIB Browser scripting objects.
VBScript (prnode.vbs)
Sample 6 : DCRIMPORT.VBS
Import SNMP agents from Cisco Works DCRv3 format. See blog entry for more details.
VBScript (dcrimport.vbs)
Sample 7 : PRTPROF.VBS
Prints all the trap profiles defined by the user.
VBScript (prtprof.vbs)

Sample 8 : POLLER.VBS/RUBY

Polls value of sysUpTime every 1 second

VBScript (snpoll.vbs)

Ruby (snpoll.rb)

Sample 9 : T2MAIL RUBY

Sends email to your account when a SNMP trap arrives. You can customize this to suit your needs.

Ruby (t2mail.rb)
Sample 10 : T2SQL (VBS and RUBY)
Save incoming traps into a SQL Database. VBS version works with ODBC, RB version directly inserts into MySQL.

VBScript (t2sql.vbs)

Ruby (t2sql.rb)

Sample 11 : T2SQLUDP.VBS
Saves incoming traps to SQL, demonstrates how to receive traps from UDP socket instead of Winpcap
VBScript (t2sqludp.vbs

Sample 12 : T2SQLBUFFERED.VBS


Demonstrates use of "buffered mode". In this mode, the trap receiver buffers traps and your scripts reads from the buffer. Once you have done processing a trap, you can call DeleteTrapByIdx to free it up. Since the trap server is a high performance C++ server your scripts can process thousands of traps per second.

Use this if you want the trap receiver to be up and running forever under load.

VBScript (t2sql_buffered.vbs)

Sample 13 : WALKTREE.VBS


Demonstrates retrieving entire MIB trees  (tables) from an agent.  Also contains code for mapping an OID to a MIB object and searching the MIB repository for a matching name.

Usage

cscript walktree.vbs  myrouter1  hrStorage

 

VBScript

(walktree.vbs)

Sample 14 : TRAPCMD.RB

Continuously monitor SNMP trap activity and execute an external command when a trap is containing specific information is received.

In this sample, a WAV file is played when a specific OID inside a trap contains the string "trouble".

Usage

ruby trapcmd.rb

C:\>ruby trapcmd.rb
Loaded the Unbrowse SNMP Trap Server
Starting ..
Listening for traps ... (Ctrl+C) to stop

Ruby

(trapcmd.rb)

Sample 15 : TRAPFILTER-AGENT.VBS
Automatically create a trap filter that only accepts traps from agents you have defined in Unbrowse.

Usage

cscript trapfilter-agent.vbs 

VBScript

(trapfilter-agent.vbs)

Sample 16 : PTRAPINFO.VBS
Prints all details about TRAPS defined in a MIB Module. Useful if you want to export trap definitions into Excel or other formats.

Usage

cscript ptrapinfo.vbs <Module-Name>

Example

cscript ptrapinfo.vbs CISCO-ENVMON-MIB
You need to compile your MIBs into Unbrowse and then use the Module Names from the tree view.

VBScript

(ptrapinfo.vbs)

Sample 17: POIDINFO.VBS

 

Dead simple sample shows how can you can print details of every object stored in the Unbrowse Repository

VBScript

(poidtable.vbs)