'Created 15/08/2006 'Author: Justin Hannan ' 'Description: Disk space check for less than a specified amount of disk space. Uses device credentials so it can be deployed easily 'across numerous domains for MSP environments 'Sending log message to the WhatsUp Event Viewer Context.LogMessage "Checking Address=" & Context.GetProperty("Address") 'Set the result code of the check (0=Success, 1=Error) Context.SetResult 0, "No error" 'Get server credentials and server address to use in WMI authentication sWinUser = Context.GetProperty("CredWindows:DomainAndUserid") sWinPass = Context.GetProperty("CredWindows:Password") Address = Context.GetProperty("Address") Const CONVERSION_FACTOR = 1048576 'Threshold is MB free, change this value to alter the threshold for alerting Const WARNING_THRESHOLD = 100 On Error Resume Next ' Connect to target machine via WMI and query Set objSWbemLocator = CreateObject("WbemScripting.SWbemLocator") Set objWMIService = objSWbemLocator.ConnectServer(Address,"root\cimv2",sWinUser, sWinPass) Set objDiskDrives = objWMIService.ExecQuery ("SELECT * FROM Win32_LogicalDisk where DriveType=3") For Each objDrive in objDiskDrives FreeMegaBytes = objDrive.FreeSpace / CONVERSION_FACTOR If FreeMegaBytes > WARNING_THRESHOLD Then Context.LogMessage "Drive " & objDrive.deviceID & " is OK (" & INT(objDrive.FreeSpace / CONVERSION_FACTOR) & " MB Free)" End If If FreeMegaBytes < WARNING_THRESHOLD Then Context.SetResult 1, "Drive " & objDrive.deviceID & " has less than "&WARNING_THRESHOLD&" MB free space" End If Next