Monitorar espaço em disco.

Publicado: outubro 25, 2013 em Windows

Esse script podemos criar uma Task Schedule colocando de tempo em tempo para ser executado com isso possibilitando
saber o espaço em disco dos servidores críticos da sua rede. Para aquelas empresas que não tem como colocar um MOM, SCOM, Nagios ele funciona muito bem.

 

On Error Resume Next
Const HARD_DISK = 3
hostnames = “C:\hostnames.txt”
Const ForWriting = 2
Const ForReading = 1
Const ForAppending = 8
Set objFSO = CreateObject(“Scripting.FileSystemObject”)
Set objInputFile = objFSO.OpenTextFile(hostnames, ForReading, True)

lin = 2
strBody = “<html> ” & ” <head>”
strBody = strBody & “<Title>”
strBody = strBody & “Squaliti Report”
strBody = strBody & “</title>”
strBody = strBody & “</head>”
strBody = strBody & “<body>”
strBody = strBody & “<table Width=100% border=1 bordercolor=#000000>”
strBody = strBody & “<tr>”
strBody = strBody & “<td width=25%><center> Hostname </center></td><td width=15%><center> Driver </center></td><td width=15%><center> Total Disco GB </center></td><td width=15%><center> Total Utilizado GB </center></td><td width=15%><center> Espaco Livre GB </center></td><td width=15%><center> % </center></td>”
strBody = strBody & “</tr>”
Do Until objInputFile.atEndofStream
strComputer = objInputFile.ReadLine
Set objWMIService = GetObject(“winmgmts:” _
& “{impersonationLevel=impersonate}!\\” & strComputer & “\root\cimv2”)

Set colDisks = objWMIService.ExecQuery _
(“Select * from Win32_LogicalDisk Where DriveType = ” & HARD_DISK & “”)

For Each objDisk In colDisks
If Int(Int(objDisk.FreeSpace / 1024 / 1024 / 1024) / Int(objDisk.Size / 1024 / 1024 / 1024) * 100) <= 10 And Int(objDisk.Size / 1024 / 1024 / 1024) – Int(objDisk.FreeSpace / 1024 / 1024 / 1024) > 0 Then
strBody = strBody & “<tr>”
strBody = strBody & “<td width=25% bgcolor=#FF0000><center><font color=#FFFFFF><B>” & strComputer & ” </B></font> </center></td>”
strBody = strBody & “<td width=15% bgcolor=#FF0000><center><font color=#FFFFFF><B>” & objDisk.DeviceID & ” </B></font> </center></td>”
strBody = strBody & “<td width=15% bgcolor=#FF0000><center><font color=#FFFFFF><B>” & Int(objDisk.Size / 1024 / 1024 / 1024) & ” </B></font> </center></td>”
strBody = strBody & “<td width=15% bgcolor=#FF0000><center><font color=#FFFFFF><B>” & Int(objDisk.Size / 1024 / 1024 / 1024) – Int(objDisk.FreeSpace / 1024 / 1024 / 1024) & ” </B></font> </center></td>”
strBody = strBody & “<td width=15% bgcolor=#FF0000><center><font color=#FFFFFF><B>” & (objDisk.FreeSpace / 1024 / 1024 / 1024) & ” </B></font> </center></td>”
strBody = strBody & “<td width=15% bgcolor=#FF0000><center><font color=#FFFFFF><B>” & Int(Int(objDisk.FreeSpace / 1024 / 1024 / 1024) / Int(objDisk.Size / 1024 / 1024 / 1024) * 100) & ” </B></font> </center></td>”
strBody = strBody & “</tr>”
strinf = 1
lin = lin + 1
End If
Next
Loop
If strinf <> 0 Then
objInputFile.Close
‘Começa a ser enviado o e-mail

Set objMessage = CreateObject(“CDO.Message”)
objMessage.Subject = “Espaço em disco server Threshold 10%”
objMessage.From = “suporte@alguem.com.br”
objMessage.To = “responsavel@alguem.com.br”
objMessage.HTMLBody = strBody
‘==This section provides the configuration information for the remote SMTP server.
‘==Normally you will only change the server name or IP.

objMessage.Configuration.Fields.Item _
(“http://schemas.microsoft.com/cdo/configuration/sendusing&#8221;) = 2

‘Name or IP of Remote SMTP Server
objMessage.Configuration.Fields.Item _
(“http://schemas.microsoft.com/cdo/configuration/smtpserver&#8221;) = “teste”

‘Server port (typically 25)
objMessage.Configuration.Fields.Item _
(“http://schemas.microsoft.com/cdo/configuration/smtpserverport&#8221;) = 25

objMessage.Configuration.Fields.Update

‘==End remote SMTP server configuration section==

objMessage.Send
End If

Deixe um comentário