Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Disk Space Monitor with Email

 
Logged in as: Guest
arrSession:exec spGetSession 2,16,35387
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> Post a VBScript >> Disk Space Monitor with Email
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Disk Space Monitor with Email - 6/13/2006 7:16:48 AM   
  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
 
 
Post #: 1
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> Post a VBScript >> Disk Space Monitor with Email Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts