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

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

FileSize Monitoring for MOM 2005

I've created a script that will monitor a file size for MOM 2005 if the file size is less then the specified threshold it will generate and event in MOM.

NAME: FilesizeMonitor.vbs


Parameters - File_name (need to specify the Path and the file Name)and FileSize_Threshold (File size in KB)

Create New Event Rule to Monitor the Event ID 4444 for File Threshold Exceed and Event 4441 for File Not found Error.

'*****************************************************************
Option Explicit
Dim filesize, fs, file

Dim Filename, FileSizeThreshold
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
Filename = objParameters.get("File_name")
FileSizeThreshold = objParameters.get("FileSize_Threshold")

Set fs=CreateObject("Scripting.FileSystemObject")
Set file=fs.GetFile(Filename)

If Err.Number > 0 Then

Set objEvt = ScriptContext.CreateEvent
objEvt.Message = "Cannot find the file " & Filename & " on the server " & objEvt.LoggingComputer
objEvt.EventSource = "FileSizeMonitor"
objEvt.EventType = EVENT_TYPE_ERROR
objEvt.EventNumber = 4441
ScriptContext.Submit(objEvt)
ScriptContext.Quit
Else
filesize = file.Size / 1024
if filesize <>
Set objEvt = ScriptContext.CreateEvent
objEvt.Message = "The File " & Filename & " on " & objEvt.LoggingComputer & " is less then the specified threshold (threshold =" & FileSizeThreshold & ")"
objEvt.EventSource = "FileSizeMonitor"
objEvt.EventType = EVENT_TYPE_ERROR
objEvt.EventNumber = 4444
ScriptContext.Submit(objEvt)
ScriptContext.Quit
End If
End if