Friday, December 28, 2007

Sending Custom SNMP Trap from MOM 2005

After a long time I have written a script for MOM 2005, someone from my company requested if we could send a custom SNMP trap in MOM 2005, below is a VB script which sends a Custom SNMP trap in MOM 2005.

The script below uses Trapgen.exe which is freely available from www.ncomtech.com

You can download the trapgen.exe from http://ncomtech.com/downloads/windows/trapgen28.zip


The VBscript below need to run as a response to an Event rule which generates an alert, whenever an alert is raised the script gets the Description, Domain and Machine Name, and the Severity of the alert and then passes it as a parameter to trapgen.exe

Note: Need to specify the path for the trapgen.exe in the VBscript below and also you can add your own Alert field/object in the script for more information on available Alert fields/object, please check the Microsoft Operations Manager SDK help file.



'**********************Custom SNMP Trap VBScript*********************


Option Explicit

Dim objAlert
Dim strComputer, strDesc, stralertsource, strRuleName, Stralertlevel
Dim c1,c2,c3,c0
Dim c4,c5,c6
Dim c7,c8,c9
Dim c10,c11,c12,c13,C14, c15
Dim strCmdLine, wshShell

'Collecting the Alert details

If (ScriptContext.IsAlert()) Then

Set objAlert = ScriptContext.Alert

if objAlert.AlertLevel = 50 then

Stralertlevel = "Critical Error"

elseif objAlert.AlertLevel = 60 then

Stralertlevel = "Security Issue"

elseif objAlert.AlertLevel = 70 then

Stralertlevel = "Service Unavailable"

end if





set wshShell = CreateObject ("WSCript.shell")

'This is a test SNMP trap, obvious you need to provide the path below for trapgen.exe.

C1 = "e:\trapgen.exe"
C2 = "-d"
c3 = "127.0.0.1"
c4 = "-c"
c5 = "public"
c8 = "-o"
c9 = "1.3.6.1.4.1.2349"
c10 = "-v"
c11 = "1.3.6.1.4.1.2349.2.2.2.3"
C6 = "1.3.6.1.4.1.2349.2.2.2.4"
C7 = "1.3.6.1.4.1.2349.2.2.2.7"
c12 = "STRING"
C13 = chr(34) & objAlert.Description & chr(34)
C14 = chr(34) & objAlert.ComputerDomain & "\" & objAlert.Computer & chr(34)
C15 = chr(34) & Stralertlevel & chr(34)






strCmdLine = C1 & " " & C2 & " " & c3 & " " & c4 & " " & c5 & " " & c8 & " " & c9 & " " & c10 & " " & c11 & " " & c12 & " " & c15 & " " & c10 & " " & c6 & " " & c12 & " " & c14 & " " & c10 & " " & c7 & " " & c12 & " " & c13

wshShell.Run strCmdLine,1,True

set wshshell = nothing


End If

'*********************************End of Script***************************

2 comments:

Anonymous said...

Can anyone recommend the well-priced Network Monitoring utility for a small IT service company like mine? Does anyone use Kaseya.com or GFI.com? How do they compare to these guys I found recently: N-able N-central network security software
? What is your best take in cost vs performance among those three? I need a good advice please... Thanks in advance!

Anonymous said...

Can anyone recommend the top Network Monitoring tool for a small IT service company like mine? Does anyone use Kaseya.com or GFI.com? How do they compare to these guys I found recently: N-able N-central security management
? What is your best take in cost vs performance among those three? I need a good advice please... Thanks in advance!