Robokiller
asked on
Windows Server Environment Disk Usage monitoring solution?
Hi guys,
I have about 30 Win 2003/2008 servers which need to have Disk Capacity monitored, the snag is, heavy corporate IT policy governance towards third party applications.
Is there any bolt-on services/scripting I can use as a workaround? I basically need to create daily reports and perhaps alerts regarding capacity management, as some of our critical applications require space available across various volumes.
Thanks in advance.
Regards.
I have about 30 Win 2003/2008 servers which need to have Disk Capacity monitored, the snag is, heavy corporate IT policy governance towards third party applications.
Is there any bolt-on services/scripting I can use as a workaround? I basically need to create daily reports and perhaps alerts regarding capacity management, as some of our critical applications require space available across various volumes.
Thanks in advance.
Regards.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
i failed to mention that you should copy the code and save it on a file with an .hta extention using a notepad editor.
ASKER
Thank you very much for taking the time to help.
ASKER
@stergium How would I add more volumes? Currently it only scans "C" drive.
Thanks in advance, again.
Regards.
Thanks in advance, again.
Regards.
Hello again.
A not so smart solution would be to create functions like GetFreeSpace, GetTotalSpace with the corresponding driver letter.
i'm trying to create a loop though local logical drives.
A not so smart solution would be to create functions like GetFreeSpace, GetTotalSpace with the corresponding driver letter.
i'm trying to create a loop though local logical drives.
ASKER
@stergium, thanks, let me know if you make any progress with that, I'm fooling around iwth the script at the moment. Will give feedback.
from what i've tested (and actually had the chance to readjust the script for me also) this should give you all of the local hard disks.
please feedback.
<!--stergium Expert-Exchange 2012-->
<head>
<title>stergium Expert-Exchange 2012</title>
<HTA:APPLICATION
APPLICATIONNAME="Check Hard Drive Failure Events"
SCROLL="yes"
SINGLEINSTANCE="yes"
WINDOWSTATE="maximize"
>
</head>
<script language="VBScript">
Sub Window_onLoad
window.resizeTo 400,250
End Sub
sub CheckFromFile
dim strComputerList, objFSO, objFile, arrComputers, i
strComputerList=ComputerListFile.Value
redim arrComputers(0)
set objFSO=CreateObject("Scripting.FileSystemObject")
if strComputerList="" then
ShowStatus.InnerHTML="<p>Please select a file containing a list of computer names, one per line.</p>"
exit sub
end if
if not objFSO.FileExists(strComputerList) then
ShowStatus.InnerHTML="<p>File not found: " & strComputerList & "</p>"
exit sub
end if
set objFile=objFSO.OpenTextFile(strComputerList, 1)
i=0
while not objFile.AtEndOfStream
redim preserve arrComputers(i)
arrcomputers(i)=objFile.ReadLine
i=i+1
wend
objFile.Close
strHTML=CheckComputers(arrComputers)
ShowStatus.InnerHTML=""
Results.InnerHTML=strHTML
GetOptions.InnerHTML=""
end sub
function CheckComputers(arrList)
dim strResults, strComputer
dim i
strResults = "<table width='90%' border=1>"
strResults = strResults & VbCrLf & "<tr><th>Hostname</th><th>Status</th><th>IP Address</th><th>Logged On User</th><th>Total Space</th><th>%free Space</th><th>Total Mem</th></tr>"
' Read list of computers and get reports
for i=0 to ubound(arrList)
strComputer = arrList(i)
ShowStatus.InnerHTML="<p>Checking computer: " & strComputer & "</p>"
If strComputer <> "" Then
strResults = strResults & VbCrLf & "<tr><td>" & strComputer & "</td>"
If Ping(strComputer) = True Then
strResults = strResults & "<td><FONT COLOR=RED>" & CheckHardDriveEvents(strComputer) & "</FONT></td>"
strResults = strResults & "<td>" & GetIPAddress(strComputer) & "</td>"
strResults = strResults & "<td>" & GetLoggedOnUser(strComputer) & "</td>"
freespace=GetFreeSpace(strComputer)
strResults = strResults & "<td>" & GetTotalSpace(strComputer) & "GB"& "</td>"
strResults = strResults & "<td>" & GetFreeSpace(strComputer)& "GB" & "</td>"
strResults = strResults & "<td>" & GetTotalMem(strComputer) & "MB"& "</td>"
Else
strResults = strResults & "<td align='center' colspan=3>Offline</td>"
End If
strResults = strResults & "</tr>"
End If
next
strResults = strResults & VbCrLf & "</table>"
CheckComputers=strResults
end function
function CheckHardDriveEvents(Computer)
dim objWMIService, colLoggedEvents, strResult
'strResult="Event log check for computer: " & Computer
'strResult=strResult & vbcrlf & string(Len(strResult), "-") & vbCrLf
On Error Resume Next
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & Computer & "\root\cimv2")
If Err.Number = 0 Then
Set colLoggedEvents = objWMIService.ExecQuery("Select * from Win32_NTLogEvent Where Logfile = 'System' and EventCode = 7")
strResult=strResult & ReturnEventDetails(colLoggedEvents, "Disk")
Else
strResult=strResult & "WMI Error"
End If
Err.Clear
CheckHardDriveEvents = strResult
end function
function ReturnEventDetails(colLoggedEvents, RequiredSource)
dim objEvent, objSWbemDateTime, dicDupCount, dicEventDetails, k
dim strHTML, strEvent, strResult, intCount, i
set dicDupCount=CreateObject("Scripting.Dictionary")
set dicEventDetails=CreateObject("Scripting.Dictionary")
Set objSWbemDateTime = CreateObject("WbemScripting.SWbemDateTime")
For Each objEvent in colLoggedEvents
if objEvent.SourceName=RequiredSource then
if not dicDupCount.Exists(objEvent.EventCode & objEvent.SourceName) then
strEvent = vbCrLf & "Event Code: " & objEvent.EventCode
strEvent = strEvent & VbCrLf & "Source: " & objEvent.SourceName
strEvent = strEvent & VbCrLf & "Message: " & objEvent.Message
objSWbemDateTime.Value=objEvent.TimeWritten
strEvent = strEvent & "Time of first event: " & objSWbemDateTime.GetVarDate
strEvent = strEvent & VbCrLf & "Type: " & objEvent.Type
dicDupCount.Add objEvent.EventCode & objEvent.SourceName, "1"
dicEventDetails.Add objEvent.EventCode & objEvent.SourceName, strEvent
else
intCount=dicDupCount(objEvent.EventCode & objEvent.SourceName)+1
dicDupCount(objEvent.EventCode & objEvent.SourceName)=intCount
end if
end if
Next
' Now loop through dictionary and add to output
k=dicDupCount.Keys
for i=0 to dicDupCount.Count-1
strResult=strResult & dicEventDetails(k(i))
strResult=strResult & VbCrLf & "Event count: " & dicDupCount(k(i)) & vbCrLf & vbCrLf & vbCrLf
next
If strResult <> "" Then
ReturnEventDetails=strResult
Else
ReturnEventDetails= "OK" & VbCrLf & VbCrLf
End If
set dicDupCount=Nothing
set dicEventDetails=Nothing
end Function
Function Ping(strComputer)
Dim objShell, boolCode
Set objShell = CreateObject("WScript.Shell")
boolCode = objShell.Run("Ping -n 1 -w 300 " & strComputer, 0, True)
If boolCode = 0 Then
Ping = True
Else
Ping = False
End If
End Function
Function GetIPAddress(sComputer)
Dim colComputerIP, objWMIService, IPConfig, strIPAddress, intIPCount
On Error Resume Next
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & sComputer & "\root\cimv2")
If Err.Number = 0 Then
Set colComputerIP = objWMIService.ExecQuery _
("Select IPAddress from Win32_NetworkAdapterConfiguration")
strIPAddress = ""
For Each IPConfig in colComputerIP
If Not IsNull(IPConfig.IPAddress) Then
'strIPAddress = strIPAddress & IPConfig.Description & ": "
For intIPCount = LBound(IPConfig.IPAddress) To UBound(IPConfig.IPAddress)
'strIPAddress = strIPAddress & "IP Address: " & IPConfig.IPAddress(intIPCount) & "~"
If IPConfig.IPAddress(intIPCount) <> "0.0.0.0" Then
If strIPAddress = "" Then
strIPAddress = IPConfig.IPAddress(intIPCount)
Else
strIPAddress = strIPAddress & VbCrLf & IPConfig.IPAddress(intIPCount)
End If
End If
Next
End If
Next
Else
strIPAddress = "WMI Error"
End If
Err.Clear
GetIPAddress = strIPAddress
End Function
Function GetLoggedOnUser(sComputer)
Dim colComputer, objWMIService, objComputer, strUsername
On Error Resume Next
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & sComputer & "\root\cimv2")
If Err.Number = 0 Then
Set colComputer = objWMIService.ExecQuery _
("Select * from Win32_ComputerSystem")
strUsername = ""
For Each objComputer in colComputer
strUserName = objComputer.UserName
Next
Else
strUsername = "WMI Error"
End If
Err.Clear
GetLoggedOnUser = strUsername
End Function
Function GetFreeSpace(sComputer)
Dim colComputer, objWMIService, objLogicalDisk, strspace , strcaption , temp
On Error Resume Next
Set objWMIService = GetObject("winmgmts:"_
& "{impersonationLevel=impersonate}!\\" & sComputer & "\root\cimv2")
If Err.Number = 0 Then
Set colComputer = objWMIService.ExecQuery _
("Select * from Win32_LogicalDisk", "WQL", _
wbemFlagReturnImmediately + wbemFlagForwardOnly)
strspace = ""
For Each objLogicalDisk in colComputer
if objLogicalDisk.DriveType = 3 then
strcaption= " " & objLogicalDisk.Caption
strspace = objLogicalDisk.FreeSpace
strtotspace=objLogicalDisk.Size
temp = temp & strcaption & "=>" & int(strspace/1073741824)
end if
Next
Else
strspace = "WMI Error"
End If
Err.Clear
GetFreeSpace = temp
' GetFreeSpace = int(strspace/1073741824)
End Function
Function GetTotalSpace(sComputer)
Dim colComputer, objWMIService, objLogicalDisk, strspace , temp
On Error Resume Next
Set objWMIService = GetObject("winmgmts:"_
& "{impersonationLevel=impersonate}!\\" & sComputer & "\root\cimv2")
If Err.Number = 0 Then
Set colComputer = objWMIService.ExecQuery _
("Select * from Win32_LogicalDisk", "WQL", _
wbemFlagReturnImmediately + wbemFlagForwardOnly)
strspace = ""
For Each objLogicalDisk in colComputer
if objLogicalDisk.DriveType = 3 then
strtotspace=objLogicalDisk.Size
strcaption= " " & objLogicalDisk.Caption
temp = temp & strcaption & "=>" & int(strtotspace/1073741824)
end if
Next
Else
strtotspace = "WMI Error"
End If
Err.Clear
GetTotalSpace= temp
'GetTotalSpace= temp int(strtotspace/1073741824)
End Function
Function GetTotalMem(sComputer)
Dim colComputer, objWMIService, objmem, totmem , temp
On Error Resume Next
Set objWMIService = GetObject("winmgmts:"_
& "{impersonationLevel=impersonate}!\\" & sComputer & "\root\cimv2")
If Err.Number = 0 Then
Set colComputer = objWMIService.ExecQuery _
("Select * from Win32_ComputerSystem")
Set objmem = objWMIService.Get("Win32_ComputerSystem")
totmem = ""
For Each objmem in colComputer
totmem=objmem.TotalPhysicalMemory
Next
Else
totmem = "WMI Error"
End If
Err.Clear
GetTotalMem=int((totmem/1024)/1024)' /1073741824)
End Function
</script>
<body>
<span id = "GetOptions">
<input type="file" name="ComputerListFile">
<input type="button" value="Check computers" name="run_button" onClick="CheckFromFile">
</span>
<span id = "ShowStatus"></span>
<span id = "Results"></span>
</body>
</html>
i hope that is what you need. please feedback.
ASKER
@stergium, absolutely perfect, thank you very much stergium, also, extra thanks for helping me out after I have resolved the issue! Five stars.