22 November 2007

Talking about MOM 2005 - Custom disk space

  I recently posted a custom disk monitoring script here:

MOM 2005 - Custom disk space

which worked fine, but it didn't quire meet our requirements. We have updated this script to have thresholds based on the total size of the disk, which looks like this:

________________________________________________

'*******************************************************************************
' Script Name - Custom - Check Disk Space
'
' Version     - 0.2 (22-nov-2007)
'
' Purpose     - Determines the % free space available on the logical disks
'               and logs an event if the threshold is breached.
'
' Events      - 1100 = "Disk space utilisation has breached warning threshold" (Warning)
'             - 1101 = "Disk space utilisation has breached critical threshold" (Critical)
'
'
'              
'*************************************************************************

' --- Define Constants ---
' Event types
Const Event_Type_Success = 0
Const Event_Type_Error = 1
Const Event_Type_Warning = 2
Const Event_Type_Info = 4
Const Event_Type_Audit_Success = 8
Const Event_Type_Audit_Failure = 16
' Strings
Dim strComputer, intThresholdSys, intThreshold, strMessage


Dim objEvent 
Dim objWMIService
Set objEvent = ScriptContext.Event

strComputer = "."

Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!//" & strComputer & "\root\cimv2")
set colItems = objWMIService.ExecQuery("Select DeviceID, FreeSpace, Size from Win32_LogicalDisk where DriveType = 3") 'Grab the name, the free space and total size for fixed drives

    For Each objItem In colItems
   
        TotalSize = FormatNumber((objItem.Size/1073741824), 2, -2, -1, 0)
        strDrive = objItem.DeviceID
        FreeSpace = FormatNumber((objItem.FreeSpace/1073741824), 2, -2, -1, 0)      
         
    if TotalSize <= 1 then
        intThresholdW = 0.244
        intThresholdC = 0.1
    elseif TotalSize >= 5 and TotalSize < 10 then 
        intThresholdW = 0.488
        intThresholdC = 0.244
    elseif TotalSize >= 10 and TotalSize < 50 then
       intThresholdW = 2
       intThresholdC = 1
    elseif TotalSize >= 50 and TotalSize < 100 then
        intThresholdW = 10
        intThresholdC = 5
    elseif TotalSize >= 100 and TotalSize < 200 then
        intThresholdW = 15
        intThresholdC = 10
    elseif TotalSize >= 200 then
        intThresholdW = 50
        intThresholdC = 25
    end if
   
    FreePerc = FormatNumber(100*(FreeSpace/TotalSize))
   
   
    if cInt(FreeSpace) < intThresholdW and cInt(FreeSpace) > intThresholdC then 
       
        strMessage = "Disk volume " & strDrive & " is low on free space. Free space available " & FreeSpace & "GB, which is "& FreePerc &"% free. This disk's total size is "& TotalSize &"GB and the threshold for this disk is " & intThresholdW &"GB."
        CreateEvent 1100, 1
       
    ElseIf cInt(FreeSpace) < intThresholdC then
   

        strMessage = "Disk volume " & strDrive & " is low on free space. Free space available " & FreeSpace & "GB, which is "& FreePerc &"% free. This disk's total size is "& TotalSize &"GB and the threshold for this disk is " & intThresholdC &"GB."
        CreateEvent 1101, 2
       
    ElseIf cInt(FreeSpace) > intThresholdC then
       
        strMessage = "Disk volume " & strDrive & " has " & FreeSpace & "GB available as free space, which is "& FreePerc &"% free. This disk's total size is "& TotalSize &"GB and the threshold for this disk is " & intThresholdW &"GB." 
        CreateEvent 1102, 4
          
    End if
   
    if strDrive = "C:" then
   
        strMessage = strMessage & " This is a system drive, and a low disk space condition may affect the overall performance of the system."
   
    end if
   
    next


' Sub         : CreateEvent
' Parameters  : None
' Description : Create and submit an event

Sub CreateEvent (ByVal StrEventID, strEventType)
    ' Create new event and submit event objects
    set objCE_NewEvent = ScriptContext.CreateEvent     ' Set event properties
    objCE_NewEvent.Message = strMessage
    objCE_NewEvent.EventNumber = StrEventID
    objCE_NewEvent.EventType = strEventType
    objCE_NewEvent.EventSource = "Custom Disk space monitor"
    ' Submit the event
    ScriptContext.Submit(objCE_NewEvent)
    set objCE_NewEvent = Nothing
End Sub

____________________________________________________

I still suck at commenting Wink

The script checks the total size of the disk, as well as the free space available, and then matches that up with the threshold specified. strThresholdW is the warning threshold and strThresholdC is the critical threshold. An event will be generated based on which threshold was breached. If neither thresholds have been breached, an info event will be logged.
If you configure this script in your MOM environment, you need to create a timed event rule to run the script, and then a rule for warning alerts (event id 1100) and a rule for critical (event id 1101).

No comments:

Related Posts with Thumbnails