The below query will give all the currently monitored server names of both UNIX and WINDOWS server.
Execute the following query in the MSSQL query analyzer.
"Select name from object where typeid = '2' or typeid = '16'"
Wednesday, January 16, 2008
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***************************
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***************************
Thursday, May 24, 2007
FolderSize Monitoring
I've created a script that will monitor a Folder size for MOM 2005 if the file size is Greater then the specified threshold then an Event will be raised in MOM.
Parameters - Folder_name (need to specify the Path and the Folder Name), FolderSize_Threshold (Folder size in KB) and GenerateEvent (1 to Generate Success Event and 0 to Disable Success Event)
Create New Event Rule to Monitor the Event ID 4446 for Folder size is greater then the specified Threshold.
Create New Event Rule to Monitor the Event ID 4447 for Success Event.
Create New Event Rule to Monitor the Event ID 4442 for Folder Not found Error.
If you want to change the folder size to be smaller then Specified threshold then find the below line in the script "if foldersize > FolderSizeThreshold then" and change it to "if foldersize < FolderSizeThreshold then"
'********************************************************************************
Option Explicit
Dim foldersize, fs, folder, bGenerateEvent
Dim Foldername, FolderSizeThreshold
Dim objEvt, objParameters
Const EVENT_TYPE_SUCCESS = 0
Const EVENT_TYPE_ERROR = 1
Const EVENT_TYPE_WARNING = 2
Const EVENT_TYPE_INFORMATION = 4
Const EVENT_TYPE_AUDITSUCCESS = 8
Const EVENT_TYPE_AUDITFAILURE = 16
On Error Resume next
Set objParameters = ScriptContext.Parameters
Foldername = objParameters.get("Folder_name")
FolderSizeThreshold = objParameters.get("FolderSize_Threshold")
bGenerateEvent = objParameters.get("GenerateEvent")
Set fs=CreateObject("Scripting.FileSystemObject")
Set folder=fs.GetFolder(Foldername)
If Err.Number > 0 Then
Set objEvt = ScriptContext.CreateEvent
objEvt.Message = "Cannot find the folder " & Err.Number & " on the server " & objEvt.LoggingComputer
objEvt.EventSource = "FolderSizeMonitor"
objEvt.EventType = EVENT_TYPE_ERROR
objEvt.EventNumber = 4442
ScriptContext.Submit(objEvt)
ScriptContext.Quit
Else
foldersize = folder.Size / 1024
if foldersize > FolderSizeThreshold then
Set objEvt = ScriptContext.CreateEvent
objEvt.Message = "The Folder " & Foldername & " on " & objEvt.LoggingComputer & " is greater then the specified threshold (threshold =" & FolderSizeThreshold & ")"
objEvt.EventSource = "FolderSizeMonitor"
objEvt.EventType = EVENT_TYPE_ERROR
objEvt.EventNumber = 4446
ScriptContext.Submit(objEvt)
ScriptContext.Quit
Else
if bGenerateEvent = 1 then
Set objEvt = ScriptContext.CreateEvent
objEvt.Message = "The Folder " & Foldername & " on " & objEvt.LoggingComputer & " is less then the specified threshold (threshold =" & FolderSizeThreshold & ")"
objEvt.EventSource = "FolderSizeMonitor"
objEvt.EventType = EVENT_TYPE_SUCCESS
objEvt.EventNumber = 4447
ScriptContext.Submit(objEvt)
ScriptContext.Quit
End if
End If
End if
Parameters - Folder_name (need to specify the Path and the Folder Name), FolderSize_Threshold (Folder size in KB) and GenerateEvent (1 to Generate Success Event and 0 to Disable Success Event)
Create New Event Rule to Monitor the Event ID 4446 for Folder size is greater then the specified Threshold.
Create New Event Rule to Monitor the Event ID 4447 for Success Event.
Create New Event Rule to Monitor the Event ID 4442 for Folder Not found Error.
If you want to change the folder size to be smaller then Specified threshold then find the below line in the script "if foldersize > FolderSizeThreshold then" and change it to "if foldersize < FolderSizeThreshold then"
'********************************************************************************
Option Explicit
Dim foldersize, fs, folder, bGenerateEvent
Dim Foldername, FolderSizeThreshold
Dim objEvt, objParameters
Const EVENT_TYPE_SUCCESS = 0
Const EVENT_TYPE_ERROR = 1
Const EVENT_TYPE_WARNING = 2
Const EVENT_TYPE_INFORMATION = 4
Const EVENT_TYPE_AUDITSUCCESS = 8
Const EVENT_TYPE_AUDITFAILURE = 16
On Error Resume next
Set objParameters = ScriptContext.Parameters
Foldername = objParameters.get("Folder_name")
FolderSizeThreshold = objParameters.get("FolderSize_Threshold")
bGenerateEvent = objParameters.get("GenerateEvent")
Set fs=CreateObject("Scripting.FileSystemObject")
Set folder=fs.GetFolder(Foldername)
If Err.Number > 0 Then
Set objEvt = ScriptContext.CreateEvent
objEvt.Message = "Cannot find the folder " & Err.Number & " on the server " & objEvt.LoggingComputer
objEvt.EventSource = "FolderSizeMonitor"
objEvt.EventType = EVENT_TYPE_ERROR
objEvt.EventNumber = 4442
ScriptContext.Submit(objEvt)
ScriptContext.Quit
Else
foldersize = folder.Size / 1024
if foldersize > FolderSizeThreshold then
Set objEvt = ScriptContext.CreateEvent
objEvt.Message = "The Folder " & Foldername & " on " & objEvt.LoggingComputer & " is greater then the specified threshold (threshold =" & FolderSizeThreshold & ")"
objEvt.EventSource = "FolderSizeMonitor"
objEvt.EventType = EVENT_TYPE_ERROR
objEvt.EventNumber = 4446
ScriptContext.Submit(objEvt)
ScriptContext.Quit
Else
if bGenerateEvent = 1 then
Set objEvt = ScriptContext.CreateEvent
objEvt.Message = "The Folder " & Foldername & " on " & objEvt.LoggingComputer & " is less then the specified threshold (threshold =" & FolderSizeThreshold & ")"
objEvt.EventSource = "FolderSizeMonitor"
objEvt.EventType = EVENT_TYPE_SUCCESS
objEvt.EventNumber = 4447
ScriptContext.Submit(objEvt)
ScriptContext.Quit
End if
End If
End if
Recent MOM Alerts
I've created a SQL query to generate Recent MOM alerts in MOM.
Recent MOM Alerts
The below query need to be run against OnePoint database and you need specify the date, time and the server name.
This query will generate only alerts from warning and above and the alerts which are not resolved, you could also change the alert severity by the changing the AlertLevel value.
-******************************************************************************
-- Below is the Severity (AlertLevel) values for the MOM alerts in MOM 2005.
-- Severity Value:
-- SUCCESS ALERT = 10
-- INFORMATION ALERT= 20
-- WARNING ALERT = 30
-- ERROR ALERT = 40
-- CRITICAL ERROR ALERT= 50
-- SECURITY BREACH ALERT = 60
-- SERVICE UNAVAILABLE ALERT = 70
-- SQL Query:
--***************************
Declare @SDateTime DateTime
Declare @EDateTime DateTime
Declare @Server varchar(30)
Declare @ID Varchar(1000)
--***************************
SET @SDateTime = '10/05/2006 12:00:00 AM' -- Format MM/DD/YYYY 12:00:00 AM/PM
SET @EDateTime = '10/12/2006 12:00:00 AM' -- Format MM/DD/YYYY 12:00:00 AM/PM
SET @Server = 'your Server name'
select @ID = idComputer from computer where name = @server
Select Name, Description, Culprit, AlertLevel, ResolutionState, RepeatCount, TimeOffirstevent, TimeofLastevent from alert WHERE (TimeOfFirstEvent BETWEEN @SDateTime AND @EDateTime) And (TimeOfLastEvent BETWEEN @SDateTime AND @EDateTime) AND idComputer=@ID and AlertLevel > 20 and ResolutionState <> 255
Recent MOM Alerts
The below query need to be run against OnePoint database and you need specify the date, time and the server name.
This query will generate only alerts from warning and above and the alerts which are not resolved, you could also change the alert severity by the changing the AlertLevel value.
-******************************************************************************
-- Below is the Severity (AlertLevel) values for the MOM alerts in MOM 2005.
-- Severity Value:
-- SUCCESS ALERT = 10
-- INFORMATION ALERT= 20
-- WARNING ALERT = 30
-- ERROR ALERT = 40
-- CRITICAL ERROR ALERT= 50
-- SECURITY BREACH ALERT = 60
-- SERVICE UNAVAILABLE ALERT = 70
-- SQL Query:
--***************************
Declare @SDateTime DateTime
Declare @EDateTime DateTime
Declare @Server varchar(30)
Declare @ID Varchar(1000)
--***************************
SET @SDateTime = '10/05/2006 12:00:00 AM' -- Format MM/DD/YYYY 12:00:00 AM/PM
SET @EDateTime = '10/12/2006 12:00:00 AM' -- Format MM/DD/YYYY 12:00:00 AM/PM
SET @Server = 'your Server name'
select @ID = idComputer from computer where name = @server
Select Name, Description, Culprit, AlertLevel, ResolutionState, RepeatCount, TimeOffirstevent, TimeofLastevent from alert WHERE (TimeOfFirstEvent BETWEEN @SDateTime AND @EDateTime) And (TimeOfLastEvent BETWEEN @SDateTime AND @EDateTime) AND idComputer=@ID and AlertLevel > 20 and ResolutionState <> 255
Subscribe to:
Posts (Atom)