| |
esnmb
Posts: 441
Score: 0
Joined: 1/11/2005
From: USA
Status: offline
|
This script will read a text file with a list of servers to monitor. It any physical disk has less then 25% an email will be sent out. '############################################## '# '# Monitors Disk Space for Computers Listed in '# DiskSpaceList.txt and Emails When Below 25%. '# '############################################## Const LOCAL_HARD_DISK = 3 ' 3 is all local drives. Const FOR_READING = 1 Const CONVERSION = 1073741824 ' This is total bytes in 1 GB. strLocal = "." Set objFSO = CreateObject("Scripting.FileSystemObject") Set objFile = objFSO.OpenTextFile("DiskSpaceList.txt", FOR_READING) Do Until objFile.AtEndOfStream strComputer = objFile.ReadLine Set objWMIService1 = GetObject("winmgmts:\\" & strLocal & "\root\cimv2") Set colPings = objWMIService1.ExecQuery _ ("Select * From Win32_PingStatus where Address = '" & strComputer & "'") ' Check if server is alive before getting info. For Each objStatus in colPings If IsNull(objStatus.StatusCode) or objStatus.StatusCode <> 0 Then Else Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colDisks = objWMIService.ExecQuery _ ("SELECT * FROM Win32_LogicalDisk WHERE DriveType = " & LOCAL_HARD_DISK & "") For Each objDisk In colDisks intPercentage = objDisk.FreeSpace / objDisk.Size intTotalSpace = Int(objDisk.Size) / CONVERSION intFreeSpace = Int(objDisk.FreeSpace) / CONVERSION intDivideBy = 25 ' Percent to divide total drive space by. If FormatPercent(IntPercentage,0) < FormatPercent(intDivideBy/100,0) Then strBody = Now & vbCrLf & UCase(strComputer) _ & " disk space is below the 25% threshold on " & objDisk.DeviceID & vbCrLf _ & vbCrLf & "Total Space: " & FormatNumber(intTotalSpace, 2, False, False, True) & " GB" & vbCrLf _ & "Free Space: " & FormatNumber(intFreeSpace, 2, False, False, True) & " GB" call MAILER(strComputer, strBody) End If Next End If Next Loop objFile.Close '##################### '# Sub To Send Email # '##################### Sub MAILER(Computer, Body) strLength = Len(Wscript.ScriptName) - 4 strFrom = Left(Wscript.ScriptName, strLength) Set objEmail = CreateObject("CDO.Message") objEmail.From = strFrom & "@domain.com" objEmail.To = "Admin@domain.com" objEmail.Subject = UCase(Computer) & " is Low on Disk Space" objEmail.TextBody = Body objEmail.Configuration.Fields.Item _ ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 objEmail.Configuration.Fields.Item _ ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "yourmailserver.com" objEmail.Configuration.Fields.Item _ ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 objEmail.Configuration.Fields.Update objEmail.Send End sub
|
|