Monitoring Disk Free Space Percentage of Windows Volume Mount Point Fixed Disk drives on SNMP Nodes

Version 1

    Monitoring Disk Free Space Percentage of Windows Volume Mount Point Fixed Disk drives on SNMP Nodes

     

    If you have SAM/APM prior to version 5.5 (or if you have v5.5 or higher and do not want to change from SNMP to WMI Nodes), you can monitor the free space percentage of the Volume Mount Points via a Windows Script Monitor with a VBScript.  We use this at my company and it works great. 

     

    Below is the Monitor Description and the VBScript we use and the Script Arguments.

     

    Pre-Requisite:  You will have to manually edit the WarningThreshold and CriticalThreshold variable values before running on the nodes.  You will also have to identify which nodes have Volume Mount Points and you would then assign this SAM Template to those nodes.  You also may want to set up an Advanced Alert if you need to notify others of the disk space issue.

     

    Windows Script Monitor Component Description:  This monitor is required only on nodes with Sub-Directory Mount Points.  We are using the out-of-the-box SolarWinds Volume Monitoring instead for regular root level drive monitoring (e.g. C:\).  Logical Disk free space percentage check for Sub-Directory Mount Points (where the DriveLetter IS NULL).  If Statistic has a value of 2 then one or more Sub-Directory Mount Point drives are in Warning status and no Sub-Directory Mount nPoint drives in Critical Status (reports on all Sub-Directory Mount Point drives in Warning status).  If Statistic has a value of 3 then one or more Sub-Directory Mount Point  drives are in Critical status (reports on all Sub-Directory Mount Point drives in both Waring or Critical status).  Reports on all Logical Volumes in WMI Win32_Volume object where the DriveLetter IS NULL (designating it as a Sub-Directory Mount Point) AND the DriveType = 3 (Local Disk)

     

    Script Arguments:  ${IP}

     

    Script Engine:  vbscript

     

    ------------start VBScript----------------

    'Option Explicit

    On Error Resume Next

     

    ' Set Thesholds for this component

     

    'Set Warning Threshold for all drives

    Const WarningThreshold = 10

     

    ' Set Critical Threshold for all drives

    Const CriticalThreshold = 5

     

    ' Required for WMI Query

    Const wbemFlagReturnImmediately = &h10

    Const wbemFlagForwardOnly = &h20

     

    ' Define Variables

    Dim WshShell, objArgs, strIP, objWMIService, LogicalVolumes

    Dim objItem, strDriveName, IntCapacity, IntFree, DiskFreePct

    Dim strIgnoreFlag

    Dim strMessage, IntStatistic

     

    ' Analyze Arguments (one argument is expected which is the IP Address of the Node to monitor

    set objArgs = WScript.Arguments

    If objArgs.Count > 0 Then

        strIP= objArgs(0)

    End If

     

    ' Set the initial Statistic value to 0 which is all drives normal

    IntStatistic = 0

     

    ' Set strIgnoreFlag = "No"

    '

    ' If IntStatistic stays at 0 then all Sub-Directory Mount Point drives (DriveLetter IS NULL) are normal

    '

    ' If IntStatistic has a value of 2 then one or more Sub-Directory Mount Point drives are in Warning status and no drives in Critical Status (reports on all drives in Warning status)

    '

    ' If IntStatistic has a value of 3 then one or more Sub-Directory Mount Point drives are in Critical status (reports on all drives in both Waring or Critical status)

     

    'Set the initial Message to blank

    strMessage = ""

     

    Set WshShell = CreateObject("WScript.Shell")

     

    Set objWMIService = GetObject("winmgmts:\\" & strIP & "\root\CIMV2")

    If Err <> 0 Then

      WScript.Echo "Message: Error Could not connect to  WMI root CIMV2 Namespace on IP " & strIP & ".  The Error Number was: " & Err.Number & ".  The Error Description was: " & Err.Description & "."

      Wscript.echo "Statistic: 1"

      Err.Clear

      Wscript.quit(1)

    Else

     

      Set LogicalVolumes = objWMIService.ExecQuery("SELECT * FROM Win32_Volume where DriveType = '3' AND DriveLetter IS NULL", "WQL", wbemFlagReturnImmediately + wbemFlagForwardOnly)

      If Err <> 0 Then

      WScript.Echo "Message: Error Could not connect to  WMI Win32_Volume on IP " & strIP & ".  The Error Number was: " & Err.Number & ".  The Error Description was: " & Err.Description & "."

      Wscript.echo "Statistic: 1"

      Err.Clear

      Wscript.quit(1)

      Else

     

      For Each objItem In LogicalVolumes

         If ( objItem.DriveType = 3 ) Then

      strDriveName = objItem.Name

    'Checking Drivename for the patterns HarddiskVolume, LiveBackups, MAGLIB, and MagLib, and if found, skips to next drive in loop (zero means the pattern is not found)

      If strDriveName <> "" AND (InStr(1,strDriveName, "HarddiskVolume", 1) = 0) AND (InStr(1,strDriveName, "Livebackups", 1) = 0) AND (InStr(1,strDriveName, "MAGLIB", 1) = 0) AND (InStr(1,strDriveName, "MagLib", 1) = 0) Then

     

    ' strMessage = strMessage & " Logical Volume Name: " & strDriveName

     

      IntFree = objItem.FreeSpace

    ' strMessage = strMessage & "  Free Space: " & IntFree & " bytes"

     

      IntCapacity = objItem.Capacity

    ' strMessage = strMessage & "  Capacity: " & IntCapacity & " bytes"

     

      DiskFreePct = ((IntFree/IntCapacity)*100.00)

      DiskFreePct = Round(DiskFreePct, 2)

    ' strMessage = strMessage & "  Disk_Free_Pct: " & DiskFreePct

     

      If ( DiskFreePct <= WarningThreshold ) Then

    '    strMessage = strMessage & "  WarningThreshold LOOP Entered."

         If DiskFreePct <= CriticalThreshold Then

    ' strMessage = strMessage & "  CriticalThreshold LOOP Entered."

      IntStatistic = 3

      strMessage = strMessage & "  ---  " & strDriveName & " Critical " & DiskFreePct & "% <=" & CriticalThreshold & "%."

         Else

      If IntStatistic <= 2 Then

      IntStatistic = 2

    ' strMessage = strMessage & "  Setting IntStatistic to 2.  Warning Threshold exceeded on " & strDriveName & "."

      strMessage = strMessage & "  --- " & strDriveName & " Warning " & DiskFreePct & "% <=" & WarningThreshold & "%."

     

      Else

    ' strMessage = strMessage & "  Warning Threshold exceeded on " & strDriveName & "."

      strMessage = strMessage & "  ---  " & strDriveName & " Warning " & DiskFreePct & "% <=" & WarningThreshold & "%."

     

      End If

         End If

      End If

             Else

      strIgnoreFlag = "Yes"

      strMessage = strMessage & "  LogicalDriveName: " & strDriveName & "  has been ignored due to either a blank Drive Name or due to one of the following patterns being in the Drive Name: HarddiskVolume LiveBackups MAGLIB MagLib."

             End If

         End If

      Next

     

      If IntStatistic = 0 Then

        If strIgnoreFlag = "Yes" Then

          strMessage = "The Disk Free Space for all Sub-Directory Mount Point drives is Normal." & strMessage

        Else

          strMessage = "The Disk Free Space for all Sub-Directory Mount Point drives is Normal."

        End If

      End If

     

      WScript.Echo "Message: " & Date & " " & Time & " " & strMessage & "  Statistic Value is: " & IntStatistic

      WScript.Echo "Statistic: " & IntStatistic

      WScript.Quit(IntStatistic)

      End If

    End If

    WScript.Quit(0)

    ------------end VBScript-----------------