In our environment, we have a number of machines that have SAN storage, etc, which makes it impossible to use the default disk monitoring script that comes with MOM. This means we have had to write our own script. I have been staring at these lines of code for days now, because it is just not behaving the way it should. I was hoping one of you clever people could help me.
This is the script:
Const Event_Type_Error = 1
Const Event_Type_Warning = 2
Const Event_Type_Info = 4
Set objEvent = ScriptContext.Event
strComputer = "."
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!//" & strComputer & "\root\cimv2")
set colItems = objWMIService.ExecQuery("Select DeviceID, FreeSpace, Size from Win32_LogicalDisk where DriveType = 3")
For Each objItem In colItems
TotalSize = FormatNumber((objItem.Size/1073741824), 2, -2, -1, 0)
strDrive = objItem.DeviceID
FreeSpace = FormatNumber((objItem.FreeSpace/1073741824), 2, -2, -1, 0)
if TotalSize <= 5 then
strThresholdW = 0.244
strThresholdC = 0.1
elseif TotalSize >= 5 and TotalSize < 10 then
strThresholdW = 0.488
strThresholdC = 0.244
elseif TotalSize >= 10 and TotalSize < 50 then
strThresholdW = 2
strThresholdC = 1
elseif TotalSize >= 50 and TotalSize < 100 then
strThresholdW = 10
strThresholdC = 5
elseif TotalSize >= 100 and TotalSize < 200 then
strThresholdW = 15
strThresholdC = 10
elseif TotalSize >= 200 then
strThresholdW = 50
strThresholdC = 25
end if
FreePerc = FormatNumber(100*(FreeSpace/TotalSize))
If FreeSpace < strThresholdW and FreeSpace > strThresholdC then
if strDrive = "C:" then
strMessage = "Disk volume " & strDrive & " is low on free space. Free space available " & FreeSpace & "GB, which is "& FreePerc &"% free. This is a system disk, and the overall performance of the system could be affected. This disk's total size is "& TotalSize &"GB and the threshold for this disk is " & strThresholdW &"GB."
else
strMessage = "Disk volume " & strDrive & " is low on free space. Free space available " & FreeSpace & "GB, which is "& FreePerc &"% free. This disk's total size is "& TotalSize &"GB and the threshold for this disk is " & strThresholdW &"GB."
end if
CreateEvent 1100, 1
ElseIf FreeSpace < strThresholdC then
if strDrive = "C:" then
strMessage = "Disk volume " & strDrive & " is low on free space. Free space available " & FreeSpace & "GB, which is "& FreePerc &"% free. This is a system disk, and the overall performance of the system could be affected. This disk's total size is "& TotalSize &"GB and the threshold for this disk is " & strThresholdC &"GB."
else
strMessage = "Disk volume " & strDrive & " is low on free space. Free space available " & FreeSpace & "GB, which is "& FreePerc &"% free. This disk's total size is "& TotalSize &"GB and the threshold for this disk is " & strThresholdC &"GB."
end if
CreateEvent 1101, 2
ElseIf Freespace > strThresholdC then
strMessage = "Disk volume " & strDrive & " has " & FreeSpace & "GB available as free space, which is "& FreePerc &"% free. This disk's total size is "& TotalSize &"GB and the threshold for this disk is " & strThresholdW &"GB."
CreateEvent 1102, 4
End if
Next
Sub CreateEvent (ByVal StrEventID, strEventType)
' Create new event and submit event objects
set objCE_NewEvent = ScriptContext.CreateEvent ' Set event properties
objCE_NewEvent.Message = strMessage
objCE_NewEvent.EventNumber = StrEventID
objCE_NewEvent.EventType = strEventType
objCE_NewEvent.EventSource = "Custom Disk space monitor"
' Submit the event
ScriptContext.Submit(objCE_NewEvent)
set objCE_NewEvent = Nothing
End Sub
----------------------------------------------
It is supposed to query the WMI logical disk instance, check the total partition size, check the free space, and then compare it to a threshold (which is based on the total size, due to the inconsistant configurations we have encountered).
In my lab environment, the script, as I have pasted it above, works perfectly. It logs the errors and warnings according to the thresholds, and the info events are displayed in the event log (I put those in as a sanity check).
However, when I take the script to my live environment, very few info events are logged, and the script seems to fail completely on the compare, logging errors for disks that have 90% free, etc.
The only difference between my lab and live is that the MOM server itself in the lab is running Win2k3 R2, while in live, the MOM server is Win2k3 rtm. All the other servers in the lab are Win2k3 rtm, while the live environment has a mixture of NT4, Win2k and Win2k3 servers. I am running MOM 2005 SP1.
What am I missing? I have reworked this script so many time, and each time I get the same result. Help, please, because I think I am going completely nuts
This is the script:
Const Event_Type_Error = 1
Const Event_Type_Warning = 2
Const Event_Type_Info = 4
Set objEvent = ScriptContext.Event
strComputer = "."
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!//" & strComputer & "\root\cimv2")
set colItems = objWMIService.ExecQuery("Select DeviceID, FreeSpace, Size from Win32_LogicalDisk where DriveType = 3")
For Each objItem In colItems
TotalSize = FormatNumber((objItem.Size/1073741824), 2, -2, -1, 0)
strDrive = objItem.DeviceID
FreeSpace = FormatNumber((objItem.FreeSpace/1073741824), 2, -2, -1, 0)
if TotalSize <= 5 then
strThresholdW = 0.244
strThresholdC = 0.1
elseif TotalSize >= 5 and TotalSize < 10 then
strThresholdW = 0.488
strThresholdC = 0.244
elseif TotalSize >= 10 and TotalSize < 50 then
strThresholdW = 2
strThresholdC = 1
elseif TotalSize >= 50 and TotalSize < 100 then
strThresholdW = 10
strThresholdC = 5
elseif TotalSize >= 100 and TotalSize < 200 then
strThresholdW = 15
strThresholdC = 10
elseif TotalSize >= 200 then
strThresholdW = 50
strThresholdC = 25
end if
FreePerc = FormatNumber(100*(FreeSpace/TotalSize))
If FreeSpace < strThresholdW and FreeSpace > strThresholdC then
if strDrive = "C:" then
strMessage = "Disk volume " & strDrive & " is low on free space. Free space available " & FreeSpace & "GB, which is "& FreePerc &"% free. This is a system disk, and the overall performance of the system could be affected. This disk's total size is "& TotalSize &"GB and the threshold for this disk is " & strThresholdW &"GB."
else
strMessage = "Disk volume " & strDrive & " is low on free space. Free space available " & FreeSpace & "GB, which is "& FreePerc &"% free. This disk's total size is "& TotalSize &"GB and the threshold for this disk is " & strThresholdW &"GB."
end if
CreateEvent 1100, 1
ElseIf FreeSpace < strThresholdC then
if strDrive = "C:" then
strMessage = "Disk volume " & strDrive & " is low on free space. Free space available " & FreeSpace & "GB, which is "& FreePerc &"% free. This is a system disk, and the overall performance of the system could be affected. This disk's total size is "& TotalSize &"GB and the threshold for this disk is " & strThresholdC &"GB."
else
strMessage = "Disk volume " & strDrive & " is low on free space. Free space available " & FreeSpace & "GB, which is "& FreePerc &"% free. This disk's total size is "& TotalSize &"GB and the threshold for this disk is " & strThresholdC &"GB."
end if
CreateEvent 1101, 2
ElseIf Freespace > strThresholdC then
strMessage = "Disk volume " & strDrive & " has " & FreeSpace & "GB available as free space, which is "& FreePerc &"% free. This disk's total size is "& TotalSize &"GB and the threshold for this disk is " & strThresholdW &"GB."
CreateEvent 1102, 4
End if
Next
Sub CreateEvent (ByVal StrEventID, strEventType)
' Create new event and submit event objects
set objCE_NewEvent = ScriptContext.CreateEvent ' Set event properties
objCE_NewEvent.Message = strMessage
objCE_NewEvent.EventNumber = StrEventID
objCE_NewEvent.EventType = strEventType
objCE_NewEvent.EventSource = "Custom Disk space monitor"
' Submit the event
ScriptContext.Submit(objCE_NewEvent)
set objCE_NewEvent = Nothing
End Sub
----------------------------------------------
It is supposed to query the WMI logical disk instance, check the total partition size, check the free space, and then compare it to a threshold (which is based on the total size, due to the inconsistant configurations we have encountered).
In my lab environment, the script, as I have pasted it above, works perfectly. It logs the errors and warnings according to the thresholds, and the info events are displayed in the event log (I put those in as a sanity check).
However, when I take the script to my live environment, very few info events are logged, and the script seems to fail completely on the compare, logging errors for disks that have 90% free, etc.
The only difference between my lab and live is that the MOM server itself in the lab is running Win2k3 R2, while in live, the MOM server is Win2k3 rtm. All the other servers in the lab are Win2k3 rtm, while the live environment has a mixture of NT4, Win2k and Win2k3 servers. I am running MOM 2005 SP1.
What am I missing? I have reworked this script so many time, and each time I get the same result. Help, please, because I think I am going completely nuts