locked
How to exclude E-drive monitoring from run storage group state monitoring in windows 2003 Base OS system for few servers. RRS feed

  • Question

  • Hi,

    We are using MOM 2005 server.We want to know how to exclude E-drive monitoring from Run Storage State Monitoring in windows 2003 base os system.because E-drive is containing the page file.Most of the server E drive free space is less than 2%.If we change the script for NOn system drive, it will affect other non system drives also.

    How to achieve this requirement to creating new rule and exclude only E-drive for few Servers.

    Your help is very much appriciated.Awtaiting your valuable feed back.

    Best Regards
    Vijay
    • Moved by Rob Kuehfus Tuesday, December 8, 2009 9:18 PM You will get more help in the MP area on tuning. (From:Deployment)
    • Moved by Arie de Haan Wednesday, December 16, 2009 8:49 PM Now really moved to MP :) (From:Reporting)
    Thursday, December 3, 2009 11:02 AM

Answers

  • Here's the adjusted script i've made (this is running for 2 years on 4000 servers)

    All you would need to do is create a multiregstring called excludeddrives in hklm\SOFTWARE\eca\MOM\thresholds\baseos_freediskspace and filled it with logical disks you don't want to monitor (e.g. e:).

    or just rewrite the ecaCompareReg function with a hardcoded e:.+

    Do a search on "ECA edit" to see the changed parts of the script.

    [code]
    '-------------------------------------------------------------------
    ' <company>Microsoft Corporation</company>
    ' <copyright>Copyright (c) Microsoft Corporation. All rights reserved.</copyright>
    ' <summary>
    '   Monitors attributes of Logical Disk on computers that are managed by MOM (Status Monitoring).
    ' </summary>
    ' Edit by Rob Korving:
    'included registry check. If a disk is specified in a key, this disk will be skipped.
    ' multistring value excludeddrives in hklm\SOFTWARE\eca\MOM\thresholds\baseos_freediskspace
    '-------------------------------------------------------------------
    Option Explicit

    '
    ' Problem States
    '
    Const PROBLEMSTATE_NOTSET = 0
    Const PROBLEMSTATE_GREEN = 1
    Const PROBLEMSTATE_YELLOW = 3 ' Yellow = Red+(Warning|Error)
    Const PROBLEMSTATE_RED = 3

    '
    ' Alert levels.
    '
    Const ALERT_SUCCESS = 10
    Const ALERT_INFORMATION = 20
    Const ALERT_WARNING = 30
    Const ALERT_ERROR = 40
    Const ALERT_CRITICAL_ERROR = 50
    Const ALERT_SECURITY_BREACH = 60
    Const ALERT_SERVICE_UNAVAILABLE = 70

    '
    ' Other Constants
    '
    Const BYTES_IN_MB = 1048576 '=2^20
    Const LOCAL = 3

    'ECA Edit: Constants needed for reading registry
    Const HKEY_LOCAL_MACHINE         = &H80000002
    Const STR_KEY                    = "SOFTWARE\eca\MOM\thresholds\baseos_freediskspace"
    Const STR_MULTISZ                = "excludeddrives"
    'ECA Edit end


    Sub Main()
     ScriptContext.Echo "Storage State Monitor (" & CStr(Time) & ")"

     MonitorDiskFreeSpace()

     ScriptContext.Echo "Complete (" & CStr(Time) & ")"
    End Sub

    Sub MonitorDiskFreeSpace()

     Dim THRESHOLD_PCT_RED
     Dim THRESHOLD_PCT_YELLOW
     Dim THRESHOLD_SYSTEM_PCT_RED
     Dim THRESHOLD_SYSTEM_PCT_YELLOW 
     Dim THRESHOLD_MB_RED
     Dim THRESHOLD_MB_YELLOW
     Dim THRESHOLD_SYSTEM_MB_RED
     Dim THRESHOLD_SYSTEM_MB_YELLOW

     THRESHOLD_SYSTEM_PCT_RED = GetParam("SystemDriveFreespacePercentageRedState")
     THRESHOLD_SYSTEM_PCT_YELLOW = GetParam("SystemDriveFreespacePercentageYellowState")
     THRESHOLD_PCT_RED = GetParam("NonSystemDriveFreespacePercentageRedState")
     THRESHOLD_PCT_YELLOW = GetParam("NonSystemDriveFreespacePercentageYellowState") 
     THRESHOLD_SYSTEM_MB_RED = GetParam("SystemDriveFreespaceMegaByteRedState")
     THRESHOLD_SYSTEM_MB_YELLOW = GetParam("SystemDriveFreespaceMegaByteYellowState")
     THRESHOLD_MB_RED = GetParam("NonSystemDriveFreespaceMegaByteRedState")
     THRESHOLD_MB_YELLOW = GetParam("NonSystemDriveFreespaceMegaByteYellowState") 

     Dim IsVolumeInfoSupported : IsVolumeInfoSupported = Is_Win32_Volume_Supported()

     Dim oWmiDiskSet, oWmiDisk
     
     If IsVolumeInfoSupported Then
      Set oWmiDiskSet = WMIGetInstance("winmgmts:\\" + ScriptContext.TargetComputer & "\root\cimv2", "Win32_Volume")
     Else
      Set oWmiDiskSet = WMIGetInstance("winmgmts:\\" + ScriptContext.TargetComputer & "\root\cimv2", "Win32_LogicalDisk")
     End If

     If IsObject(oWmiDiskSet) Then
     
      For Each oWmiDisk in oWmiDiskSet

              If oWmiDisk.DriveType = LOCAL Then
        Dim sDriveLetter, nFreeSpace, nMaxSize, nPctFree, nMBFree

        nFreeSpace = oWmiDisk.FreeSpace
        If IsNull(nFreeSpace) Then _
         nFreeSpace = 0

        If IsVolumeInfoSupported Then
         sDriveLetter = oWmiDisk.DriveLetter
         nMaxSize = oWmiDisk.Capacity
         If IsNull(sDriveLetter) Then
          sDriveLetter  = oWmiDisk.Name
          sDriveLetter = Left(sDriveLetter, Len(sDriveLetter)-1)
         End If
        Else
         sDriveLetter = oWmiDisk.DeviceId

         nMaxSize = oWmiDisk.Size
        End If 

        ' ECA Edit: drive checking. Drive is skipped if it is found here.
                    If ecaCompareReg(sDriveLetter) = false then
        'ECA Edit end
        
            If Not IsNull(nMaxSize) And nMaxSize > 0 Then
        '
            ' Drive is formatted - if we dont get a maxsize, dont report on drive
        '
             nPctFree = Round(nFreeSpace / nMaxSize * 100, 0)

             nMBFree = Round(nFreeSpace / BYTES_IN_MB, 0) 
           
             ScriptContext.Echo " * " & sDriveLetter
             ScriptContext.Echo "  + Percentage : " & nPctFree & " (" & nFreeSpace & " / " & nMaxSize & " * 100)"
             ScriptContext.Echo "  + GigaBytes : " & nMBFree & " (" & nFreeSpace & " / " & BYTES_IN_MB & ")"

             Dim oAlertHandle
             Set oAlertHandle = ScriptContext.CreateAlert()
             oAlertHandle.Name = "Low disk space detected on volume " & sDriveLetter
             oAlertHandle.Description = "Disk volume '" & sDriveLetter & "' is low or out of free space." & vbCrLf & vbCrLf & _
               "Percent Free Space: " & nPctFree & "%" & vbCrLf & _
               "Capacity: " & ConvertByteToGB(nMaxSize) & " GB" & vbCrLf & _
               "Used Space: " & ConvertByteToGB(nMaxSize - nFreeSpace) & " GB" & vbCrLf & _
               "Free Space: " & ConvertByteToGB(nFreeSpace) & " GB" & vbCrLf & _
               "Compressed: " & WMIBoolToString(oWmiDisk.Compressed) & vbCrLf & _
               "File System: " & ConvertToString(oWmiDisk.FileSystem)
             oAlertHandle.ServerRole = "Disk"
             oAlertHandle.ServerRoleInstance = sDriveLetter
             oAlertHandle.Component = "Free Space"
             oAlertHandle.ProblemState = PROBLEMSTATE_GREEN
             oAlertHandle.AlertLevel = ALERT_SUCCESS

              If nPctFree < CInt(THRESHOLD_SYSTEM_PCT_RED) And nMBFree < CLng(THRESHOLD_SYSTEM_MB_RED) And Is_System_Drive(sDriveLetter) Then
              ScriptContext.Echo "  + System Drive Red % Exceeded"

              oAlertHandle.ProblemState = PROBLEMSTATE_RED
              oAlertHandle.AlertLevel = ALERT_CRITICAL_ERROR
     
             ElseIf nPctFree < CInt(THRESHOLD_SYSTEM_PCT_YELLOW) And nMBFree < CLng(THRESHOLD_SYSTEM_MB_YELLOW) And Is_System_Drive(sDriveLetter) Then
              ScriptContext.Echo "  + System Drive Yellow % Exceeded"

              oAlertHandle.ProblemState = PROBLEMSTATE_YELLOW
              oAlertHandle.AlertLevel = ALERT_WARNING

             ElseIf nPctFree < CInt(THRESHOLD_PCT_RED) And nMBFree < CLng(THRESHOLD_MB_RED) And Not Is_System_Drive(sDriveLetter) Then
              ScriptContext.Echo "  + Nonsystem Drive Red % Exceeded"

              oAlertHandle.ProblemState = PROBLEMSTATE_RED
              oAlertHandle.AlertLevel = ALERT_CRITICAL_ERROR

             ElseIf nPctFree < CInt(THRESHOLD_PCT_YELLOW) And nMBFree < CLng(THRESHOLD_MB_Yellow) And Not Is_System_Drive(sDriveLetter) Then
              ScriptContext.Echo "  + Nonsystem Drive Yellow % Exceeded"

              oAlertHandle.ProblemState = PROBLEMSTATE_YELLOW
              oAlertHandle.AlertLevel = ALERT_WARNING

             Else
              ScriptContext.Echo "  + Drive Ok"
         
              oAlertHandle.Description = "There are no freespace problems with this disk.  Everything is within allowable tolerances."

             End If

             ScriptContext.Echo "  + Submitted Alert (" & oAlertHandle.ProblemState & ", " & oAlertHandle.AlertLevel & ")"
             ScriptContext.Submit oAlertHandle
            Else
            '
            ' If the MaxSize is 0 or less, then the drive is unformatted.
            ' Do not report on unformatted drives
            '
         
             ScriptContext.Echo " * " & sDriveLetter
             ScriptContext.Echo "  + Drive not formatted."

            End If
                   
        'ECA Edit: No action when the drive has been excluded
        End if
        'ECA Edit end
       End If
      Next

     End If

    End Sub


    Function ConvertByteToGB(sByteCount)
     If IsNull(sByteCount) Then
      ConvertByteToGB = "Not Available"
      Exit Function
     End If 

     ConvertByteToGB = sByteCount / 1073741824.0
     ConvertByteToGB = CStr( Round(ConvertByteToGB, 3) )
    End Function 


    Function ConvertToString(sString)
     If IsNull(sString) Then
      ConvertToString = ""
      Exit Function
     End If
     
     ConvertToString = CStr(sString)
    End Function 

     

    Function WMIBoolToString(bValue)
     Dim sTmpValue
     If bValue = 1 then
      WMIBoolToString = "True"
     Else
      WMIBoolToString = "False"
     End If
    End Function 

    Function GetParam(sParam)

     GetParam = ScriptContext.Parameters.Get(sParam)

     If IsEmpty(GetParam) Then
      ScriptContext.Echo "Script parameter '" & sParam & "' not provided."
      'Throw Script Error Event
     End If
    End Function

    Function Is_Win32_Volume_Supported()
     Dim objWMISet, objWMIOS, blnRet

     blnRet = False
     Set objWMISet = WMIGetInstance("winmgmts:\\" & ScriptContext.TargetComputer & "\root\cimv2", "Win32_OperatingSystem")
     For each objWMIOS in objWMISet
      If CLng(objWMIOS.BuildNumber) >= 3624 Then blnRet = True
     Next
     Is_Win32_Volume_Supported = blnRet
    End Function

    Function Is_System_Drive(sDriveLetter)
     Dim objWMISet, objWMIOS
     Is_System_Drive = False

     Set objWMISet = WMIGetInstance("winmgmts:\\" & ScriptContext.TargetComputer & "\root\cimv2", "Win32_OperatingSystem")
     For each objWMIOS in objWMISet
      Dim sSystemDrive
      sSystemDrive = Left(objWMIOS.SystemDirectory, 2)
      If sSystemDrive = sDriveLetter Then
       Is_System_Drive = True
      End If
     Next
    End Function

     

     

     

     

    Function WMIGetInstance(sNamespace, sInstance)
    '
    ' WMIGetInstance :: Returns WMI Instance requested.
    '
    '
     Dim oWMI, oInstance, nInstanceCount

     On Error Resume Next
     Set oWMI = GetObject(sNamespace)
     If IsEmpty(oWMI) Then
      ThrowScriptError "Unable to open WMI Namespace '" & sNamespace & "'.  Check to see if the WMI service is enabled and running, and ensure this WMI namespace exists.", Err
     End If

     Set oInstance = oWMI.InstancesOf(sInstance)
     If IsEmpty(oInstance) Or Err.Number <> 0 Then
      ThrowScriptError "The class name '" & sInstance & "' returned no instances.  Please check to see if this is a valid WMI class name.", Err
     End If

     'Determine if we queried a valid WMI class - Count will return 0 or empty

     nInstanceCount = oInstance.Count
     If Err.Number <> 0 Then
      ThrowScriptError "The class name '" & sInstance & "' did not return any valid instances.  Please check to see if this is a valid WMI class name.", Err
     End If
     On Error Goto 0

     Set WMIGetInstance = oInstance

     Set oInstance = Nothing
     Set oWMI = Nothing

    End Function
      

    Function ThrowScriptError(sMessage, oErr)
    '
    ' ThrowScriptError :: Creates an event and sends it back to the mom server
    '
    '
     On Error Resume Next

     Dim oScriptErrorEvent

     Set oScriptErrorEvent = ScriptContext.CreateEvent()
     With oScriptErrorEvent
      .EventNumber = 40000
      .EventType = 1 'EventLogEntryType Enumeration
      .Message = sMessage
      .SetEventParameter "Microsoft Windows Servers Base Operating System"
      .SetEventParameter sMessage
      .SetEventParameter oErr.Description
      .SetEventParameter oErr.Number
     End With
     ScriptContext.Submit oScriptErrorEvent

     ScriptContext.Echo "ThrowScriptError('" & sMessage & "')"

     ScriptContext.Quit()

    End Function
    ' VBScript source code


    'ECA Edit: Reads registry for excluded drives.
    ' Returns True whenever the checked drive matches a drive in the exclusion key.
    function ecaCompareReg(strInputDrive)

        Dim bMatch
        Dim objReg
        Dim intResult
        Dim arrDrives
        Dim strDrive

        bMatch = false

        set objReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")
        intResult    = objReg.GetMultiStringValue(HKEY_LOCAL_MACHINE, STR_KEY, STR_MULTISZ, arrDrives)
       
        ' If a key is found, check if the current drive being checked shouldn't be skipped (returns true if a value in the registry matches the current drive)
        If (intResult = 0) then
            For each strDrive in arrDrives
                If UCase(strInputDrive) = UCase(strDrive) then
                    bMatch = true
                end if
            next
        End if

        ecaCompareReg = bMatch

    End function
    'ECA Edit end
    [code]


    Rob Korving
    http://jama00.wordpress.com/
    • Marked as answer by StuartR Monday, February 8, 2010 7:18 PM
    Tuesday, December 8, 2009 1:06 PM

All replies

  • What i've done is rewriting the script checking disk. As it maybe configurable for a few servers, but with a lot of servers disks ranging from small to very large it's not as helpful.

    In your case you can hack into the script (create a new rule and new script) where they start to check whether a logical disk needs an alert add an exclusion for e:. it would require some scripting skills tho.

    I've actually gone a bit further and let the script check a regkey value on the monitored server for instances which should be skipped. Which gave me (well actually others) the possibility to exclude any disk from monitoring without having rights in mom. I'll ask if i'm allowed to post it here, as this is almost a legacy app for us :)


    Rob Korving
    http://jama00.wordpress.com/
    Thursday, December 3, 2009 3:41 PM
  • Hi Vijay,

    This is a problem that a few mom 2005 users experienced. If you're willing there is a possibility to do this with a modified script that's beenoffered by the community. Look at this post at myitforum and follow the links, there you will have a replacement for the storage monitoring script prodived by microsoft.

    http://myitforum.com/cs2/blogs/smoss/archive/2008/02/16/mom-2005-script-microsoft-windows-storage-state-monitoring-script-version-3.aspx

    Greetz,

    Arie de Haan
    MVP SCOM
    This posting is provide "AS IS" with no guarantees, warranties, rigths etc.
    Sunday, December 6, 2009 10:50 AM
  • Create a group with the disks you want to ignore as explicit members of the group.
    Create an override of the Logical Disk monitor for free space that disables the monitor for your group.

    "Fear disturbs your concentration"
    Monday, December 7, 2009 9:02 PM
  • will not be possible, because it is not SCOM 2007. This is a MOM 2005 related question which only allows creating computergroups and you cannot create an override in MOM2005 for this rule based on a disk group
    Greetz,

    Arie de Haan
    MVP SCOM
    This posting is provide "AS IS" with no guarantees, warranties, rigths etc.
    Tuesday, December 8, 2009 8:43 AM
  • Here's the adjusted script i've made (this is running for 2 years on 4000 servers)

    All you would need to do is create a multiregstring called excludeddrives in hklm\SOFTWARE\eca\MOM\thresholds\baseos_freediskspace and filled it with logical disks you don't want to monitor (e.g. e:).

    or just rewrite the ecaCompareReg function with a hardcoded e:.+

    Do a search on "ECA edit" to see the changed parts of the script.

    [code]
    '-------------------------------------------------------------------
    ' <company>Microsoft Corporation</company>
    ' <copyright>Copyright (c) Microsoft Corporation. All rights reserved.</copyright>
    ' <summary>
    '   Monitors attributes of Logical Disk on computers that are managed by MOM (Status Monitoring).
    ' </summary>
    ' Edit by Rob Korving:
    'included registry check. If a disk is specified in a key, this disk will be skipped.
    ' multistring value excludeddrives in hklm\SOFTWARE\eca\MOM\thresholds\baseos_freediskspace
    '-------------------------------------------------------------------
    Option Explicit

    '
    ' Problem States
    '
    Const PROBLEMSTATE_NOTSET = 0
    Const PROBLEMSTATE_GREEN = 1
    Const PROBLEMSTATE_YELLOW = 3 ' Yellow = Red+(Warning|Error)
    Const PROBLEMSTATE_RED = 3

    '
    ' Alert levels.
    '
    Const ALERT_SUCCESS = 10
    Const ALERT_INFORMATION = 20
    Const ALERT_WARNING = 30
    Const ALERT_ERROR = 40
    Const ALERT_CRITICAL_ERROR = 50
    Const ALERT_SECURITY_BREACH = 60
    Const ALERT_SERVICE_UNAVAILABLE = 70

    '
    ' Other Constants
    '
    Const BYTES_IN_MB = 1048576 '=2^20
    Const LOCAL = 3

    'ECA Edit: Constants needed for reading registry
    Const HKEY_LOCAL_MACHINE         = &H80000002
    Const STR_KEY                    = "SOFTWARE\eca\MOM\thresholds\baseos_freediskspace"
    Const STR_MULTISZ                = "excludeddrives"
    'ECA Edit end


    Sub Main()
     ScriptContext.Echo "Storage State Monitor (" & CStr(Time) & ")"

     MonitorDiskFreeSpace()

     ScriptContext.Echo "Complete (" & CStr(Time) & ")"
    End Sub

    Sub MonitorDiskFreeSpace()

     Dim THRESHOLD_PCT_RED
     Dim THRESHOLD_PCT_YELLOW
     Dim THRESHOLD_SYSTEM_PCT_RED
     Dim THRESHOLD_SYSTEM_PCT_YELLOW 
     Dim THRESHOLD_MB_RED
     Dim THRESHOLD_MB_YELLOW
     Dim THRESHOLD_SYSTEM_MB_RED
     Dim THRESHOLD_SYSTEM_MB_YELLOW

     THRESHOLD_SYSTEM_PCT_RED = GetParam("SystemDriveFreespacePercentageRedState")
     THRESHOLD_SYSTEM_PCT_YELLOW = GetParam("SystemDriveFreespacePercentageYellowState")
     THRESHOLD_PCT_RED = GetParam("NonSystemDriveFreespacePercentageRedState")
     THRESHOLD_PCT_YELLOW = GetParam("NonSystemDriveFreespacePercentageYellowState") 
     THRESHOLD_SYSTEM_MB_RED = GetParam("SystemDriveFreespaceMegaByteRedState")
     THRESHOLD_SYSTEM_MB_YELLOW = GetParam("SystemDriveFreespaceMegaByteYellowState")
     THRESHOLD_MB_RED = GetParam("NonSystemDriveFreespaceMegaByteRedState")
     THRESHOLD_MB_YELLOW = GetParam("NonSystemDriveFreespaceMegaByteYellowState") 

     Dim IsVolumeInfoSupported : IsVolumeInfoSupported = Is_Win32_Volume_Supported()

     Dim oWmiDiskSet, oWmiDisk
     
     If IsVolumeInfoSupported Then
      Set oWmiDiskSet = WMIGetInstance("winmgmts:\\" + ScriptContext.TargetComputer & "\root\cimv2", "Win32_Volume")
     Else
      Set oWmiDiskSet = WMIGetInstance("winmgmts:\\" + ScriptContext.TargetComputer & "\root\cimv2", "Win32_LogicalDisk")
     End If

     If IsObject(oWmiDiskSet) Then
     
      For Each oWmiDisk in oWmiDiskSet

              If oWmiDisk.DriveType = LOCAL Then
        Dim sDriveLetter, nFreeSpace, nMaxSize, nPctFree, nMBFree

        nFreeSpace = oWmiDisk.FreeSpace
        If IsNull(nFreeSpace) Then _
         nFreeSpace = 0

        If IsVolumeInfoSupported Then
         sDriveLetter = oWmiDisk.DriveLetter
         nMaxSize = oWmiDisk.Capacity
         If IsNull(sDriveLetter) Then
          sDriveLetter  = oWmiDisk.Name
          sDriveLetter = Left(sDriveLetter, Len(sDriveLetter)-1)
         End If
        Else
         sDriveLetter = oWmiDisk.DeviceId

         nMaxSize = oWmiDisk.Size
        End If 

        ' ECA Edit: drive checking. Drive is skipped if it is found here.
                    If ecaCompareReg(sDriveLetter) = false then
        'ECA Edit end
        
            If Not IsNull(nMaxSize) And nMaxSize > 0 Then
        '
            ' Drive is formatted - if we dont get a maxsize, dont report on drive
        '
             nPctFree = Round(nFreeSpace / nMaxSize * 100, 0)

             nMBFree = Round(nFreeSpace / BYTES_IN_MB, 0) 
           
             ScriptContext.Echo " * " & sDriveLetter
             ScriptContext.Echo "  + Percentage : " & nPctFree & " (" & nFreeSpace & " / " & nMaxSize & " * 100)"
             ScriptContext.Echo "  + GigaBytes : " & nMBFree & " (" & nFreeSpace & " / " & BYTES_IN_MB & ")"

             Dim oAlertHandle
             Set oAlertHandle = ScriptContext.CreateAlert()
             oAlertHandle.Name = "Low disk space detected on volume " & sDriveLetter
             oAlertHandle.Description = "Disk volume '" & sDriveLetter & "' is low or out of free space." & vbCrLf & vbCrLf & _
               "Percent Free Space: " & nPctFree & "%" & vbCrLf & _
               "Capacity: " & ConvertByteToGB(nMaxSize) & " GB" & vbCrLf & _
               "Used Space: " & ConvertByteToGB(nMaxSize - nFreeSpace) & " GB" & vbCrLf & _
               "Free Space: " & ConvertByteToGB(nFreeSpace) & " GB" & vbCrLf & _
               "Compressed: " & WMIBoolToString(oWmiDisk.Compressed) & vbCrLf & _
               "File System: " & ConvertToString(oWmiDisk.FileSystem)
             oAlertHandle.ServerRole = "Disk"
             oAlertHandle.ServerRoleInstance = sDriveLetter
             oAlertHandle.Component = "Free Space"
             oAlertHandle.ProblemState = PROBLEMSTATE_GREEN
             oAlertHandle.AlertLevel = ALERT_SUCCESS

              If nPctFree < CInt(THRESHOLD_SYSTEM_PCT_RED) And nMBFree < CLng(THRESHOLD_SYSTEM_MB_RED) And Is_System_Drive(sDriveLetter) Then
              ScriptContext.Echo "  + System Drive Red % Exceeded"

              oAlertHandle.ProblemState = PROBLEMSTATE_RED
              oAlertHandle.AlertLevel = ALERT_CRITICAL_ERROR
     
             ElseIf nPctFree < CInt(THRESHOLD_SYSTEM_PCT_YELLOW) And nMBFree < CLng(THRESHOLD_SYSTEM_MB_YELLOW) And Is_System_Drive(sDriveLetter) Then
              ScriptContext.Echo "  + System Drive Yellow % Exceeded"

              oAlertHandle.ProblemState = PROBLEMSTATE_YELLOW
              oAlertHandle.AlertLevel = ALERT_WARNING

             ElseIf nPctFree < CInt(THRESHOLD_PCT_RED) And nMBFree < CLng(THRESHOLD_MB_RED) And Not Is_System_Drive(sDriveLetter) Then
              ScriptContext.Echo "  + Nonsystem Drive Red % Exceeded"

              oAlertHandle.ProblemState = PROBLEMSTATE_RED
              oAlertHandle.AlertLevel = ALERT_CRITICAL_ERROR

             ElseIf nPctFree < CInt(THRESHOLD_PCT_YELLOW) And nMBFree < CLng(THRESHOLD_MB_Yellow) And Not Is_System_Drive(sDriveLetter) Then
              ScriptContext.Echo "  + Nonsystem Drive Yellow % Exceeded"

              oAlertHandle.ProblemState = PROBLEMSTATE_YELLOW
              oAlertHandle.AlertLevel = ALERT_WARNING

             Else
              ScriptContext.Echo "  + Drive Ok"
         
              oAlertHandle.Description = "There are no freespace problems with this disk.  Everything is within allowable tolerances."

             End If

             ScriptContext.Echo "  + Submitted Alert (" & oAlertHandle.ProblemState & ", " & oAlertHandle.AlertLevel & ")"
             ScriptContext.Submit oAlertHandle
            Else
            '
            ' If the MaxSize is 0 or less, then the drive is unformatted.
            ' Do not report on unformatted drives
            '
         
             ScriptContext.Echo " * " & sDriveLetter
             ScriptContext.Echo "  + Drive not formatted."

            End If
                   
        'ECA Edit: No action when the drive has been excluded
        End if
        'ECA Edit end
       End If
      Next

     End If

    End Sub


    Function ConvertByteToGB(sByteCount)
     If IsNull(sByteCount) Then
      ConvertByteToGB = "Not Available"
      Exit Function
     End If 

     ConvertByteToGB = sByteCount / 1073741824.0
     ConvertByteToGB = CStr( Round(ConvertByteToGB, 3) )
    End Function 


    Function ConvertToString(sString)
     If IsNull(sString) Then
      ConvertToString = ""
      Exit Function
     End If
     
     ConvertToString = CStr(sString)
    End Function 

     

    Function WMIBoolToString(bValue)
     Dim sTmpValue
     If bValue = 1 then
      WMIBoolToString = "True"
     Else
      WMIBoolToString = "False"
     End If
    End Function 

    Function GetParam(sParam)

     GetParam = ScriptContext.Parameters.Get(sParam)

     If IsEmpty(GetParam) Then
      ScriptContext.Echo "Script parameter '" & sParam & "' not provided."
      'Throw Script Error Event
     End If
    End Function

    Function Is_Win32_Volume_Supported()
     Dim objWMISet, objWMIOS, blnRet

     blnRet = False
     Set objWMISet = WMIGetInstance("winmgmts:\\" & ScriptContext.TargetComputer & "\root\cimv2", "Win32_OperatingSystem")
     For each objWMIOS in objWMISet
      If CLng(objWMIOS.BuildNumber) >= 3624 Then blnRet = True
     Next
     Is_Win32_Volume_Supported = blnRet
    End Function

    Function Is_System_Drive(sDriveLetter)
     Dim objWMISet, objWMIOS
     Is_System_Drive = False

     Set objWMISet = WMIGetInstance("winmgmts:\\" & ScriptContext.TargetComputer & "\root\cimv2", "Win32_OperatingSystem")
     For each objWMIOS in objWMISet
      Dim sSystemDrive
      sSystemDrive = Left(objWMIOS.SystemDirectory, 2)
      If sSystemDrive = sDriveLetter Then
       Is_System_Drive = True
      End If
     Next
    End Function

     

     

     

     

    Function WMIGetInstance(sNamespace, sInstance)
    '
    ' WMIGetInstance :: Returns WMI Instance requested.
    '
    '
     Dim oWMI, oInstance, nInstanceCount

     On Error Resume Next
     Set oWMI = GetObject(sNamespace)
     If IsEmpty(oWMI) Then
      ThrowScriptError "Unable to open WMI Namespace '" & sNamespace & "'.  Check to see if the WMI service is enabled and running, and ensure this WMI namespace exists.", Err
     End If

     Set oInstance = oWMI.InstancesOf(sInstance)
     If IsEmpty(oInstance) Or Err.Number <> 0 Then
      ThrowScriptError "The class name '" & sInstance & "' returned no instances.  Please check to see if this is a valid WMI class name.", Err
     End If

     'Determine if we queried a valid WMI class - Count will return 0 or empty

     nInstanceCount = oInstance.Count
     If Err.Number <> 0 Then
      ThrowScriptError "The class name '" & sInstance & "' did not return any valid instances.  Please check to see if this is a valid WMI class name.", Err
     End If
     On Error Goto 0

     Set WMIGetInstance = oInstance

     Set oInstance = Nothing
     Set oWMI = Nothing

    End Function
      

    Function ThrowScriptError(sMessage, oErr)
    '
    ' ThrowScriptError :: Creates an event and sends it back to the mom server
    '
    '
     On Error Resume Next

     Dim oScriptErrorEvent

     Set oScriptErrorEvent = ScriptContext.CreateEvent()
     With oScriptErrorEvent
      .EventNumber = 40000
      .EventType = 1 'EventLogEntryType Enumeration
      .Message = sMessage
      .SetEventParameter "Microsoft Windows Servers Base Operating System"
      .SetEventParameter sMessage
      .SetEventParameter oErr.Description
      .SetEventParameter oErr.Number
     End With
     ScriptContext.Submit oScriptErrorEvent

     ScriptContext.Echo "ThrowScriptError('" & sMessage & "')"

     ScriptContext.Quit()

    End Function
    ' VBScript source code


    'ECA Edit: Reads registry for excluded drives.
    ' Returns True whenever the checked drive matches a drive in the exclusion key.
    function ecaCompareReg(strInputDrive)

        Dim bMatch
        Dim objReg
        Dim intResult
        Dim arrDrives
        Dim strDrive

        bMatch = false

        set objReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")
        intResult    = objReg.GetMultiStringValue(HKEY_LOCAL_MACHINE, STR_KEY, STR_MULTISZ, arrDrives)
       
        ' If a key is found, check if the current drive being checked shouldn't be skipped (returns true if a value in the registry matches the current drive)
        If (intResult = 0) then
            For each strDrive in arrDrives
                If UCase(strInputDrive) = UCase(strDrive) then
                    bMatch = true
                end if
            next
        End if

        ecaCompareReg = bMatch

    End function
    'ECA Edit end
    [code]


    Rob Korving
    http://jama00.wordpress.com/
    • Marked as answer by StuartR Monday, February 8, 2010 7:18 PM
    Tuesday, December 8, 2009 1:06 PM
  • Hurrr...missed that. I'm thinking SCOM so much nowadays that I forget that not everyone is on SCOM and sharing our pain!

    "Fear disturbs your concentration"
    Tuesday, December 8, 2009 5:13 PM