Disk Space Server 2003?

To the Ipswitch web site

Ipswitch Forums
Home      Members   Calendar   Who's On
Welcome Guest ( Login | Register )
      


12»»

Disk Space Server 2003?Expand / Collapse
Author
Message
Posted 8/26/2008 4:10:27 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: Forum Members
Last Login: 9/2/2008 3:29:04 AM
Posts: 2, Visits: 12
Hello,

I've been looking for a VBS script to monitor disk space on a Windows 2003 Server. I've found some of them but none of them worked.

I wanna monitor a disk by drive letter.. Who can provide me this script?

Thanks

Post #46566
Posted 8/27/2008 7:59:03 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: Forum Members
Last Login: 9/2/2008 3:29:04 AM
Posts: 2, Visits: 12
Anyone?
Post #46597
Posted 8/27/2008 2:24:31 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: Forum Members
Last Login: 10/6/2008 4:01:36 PM
Posts: 6, Visits: 33
This VBScript:

' %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
' %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
' This script is a merge of 2 scripts. Credits go to :
' - XXXXX's , which use the performance monitors values to test the disk space, and most code for this script.
' - YYYYYY's, which retrieve the thresholds from a specified attribute
' I added the feature that, if the given attribute is not set, you can use a default value for all disks.
' Also, specifying a threshold of 0 disables the check on that disk.  You must always specify the unit (%, G or M), even when disabling the check.
' Format for the thresholds are something like this : 'C:\=10%;D:\=5G;E:\=650M;G:\=0%'
' THE DRIVE NAME IN THE ATTRIBUTE MUST BE THE SAME AS THE ONE RETURNED BY THE DISK PERF MONITOR. (e.g. for Windows : C:\, D:\, and so on...)
' You can see see the name of each drive by using the Test button and scanning the result.
' %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
' %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

' Name of the attribute which will contain the specific thresholds
THRESHOLDS_ATTRIBUTE = "Disk_Space_Thresholds"

' Name of the attribute which will contain the result of the check. Automatically created.
RESULT_ATTRIBUTE = "Disk_Space_Results"

' If the threshold attribute is not found, should the monitor report as DOWN ?
' If set to False, it will use the default value for all disks.
DOWN_NO_ATTRIBUTE = true

' If there are no recent performance entries for at least one device, should the monitor report as DOWN ?  - NOT IMPLEMENTED
DOWN_ON_AGED_VALUES = true

' MAX_AGE value specify the maximum age for entries, in seconds - NOT IMPLEMENTED
MAX_ENTRIES_AGE = 3600

' Default value to be used, in percentage. We monitor the FREE SPACE, which must not go below the threshold.
' 1- when the attribute doesn't specify the threshold for a given disk
' 2- for all disks if there is no attribute AND DOWN_NO_ATTRIBUTE = True
' If set to 0, not specified disks will not be checked.
DEFAULT_THRESHOLD = 10

' Unit of default threshold - THIS IS NOT A DEFAULT UNIT FOR SPECIFIED THRESHOLDS
' "%" = percentage
' "G" = gigabyte
' "M" = megabyte
DEFAULT_THRESHOLD_UNIT = "%"

' %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


' Set the result code of the check (0=Success, 1=Error)
Context.SetResult 0, "No error"
bAlarm = false

' Retrieve DB object

Set oDb = Context.GetDB

If IsNull(oDb) Then
 Context.SetResult 1, "Could not create DB object"
Else

 ' Fetch deviceID
 nDeviceID = Context.GetProperty ("DeviceID")

 ' Get the attribute which contains the specific value.
 sqlGetDS = "select sValue from DeviceAttribute where (nDeviceID = " & nDeviceID & ") and (sName = '" & THRESHOLDS_ATTRIBUTE & "')"
 Set oRs1 = oDb.Execute(sqlGetDS)

 ' We report a DOWN if no attribute and script is configured as such.
 If DOWN_NO_ATTRIBUTE and oRs1.EOF Then
  Context.SetResult 1, "This monitor needs a attribute named " & THRESHOLDS_ATTRIBUTE & " to work."
 Else
  drvMonitors = null
  If Not oRs1.EOF Then
   oRs1.moveFirst
   drvMonitors = split(oRs1("sValue"),";")
  End If
  
  ' SQL request. We ask SQL to compute the value we want itself : it return the remaining percentage, megabytes and gigabytes on each disk.
  sSql = "SELECT     SDI.sDescription, SD.dPollTime, D.sDisplayName, (1 - SD.nUsed_Avg / SD.nSize) * 100 AS perc, (SD.nSize - SD.nUsed_Avg) / 1073741824 AS giga, (SD.nSize - SD.nUsed_Avg) / 1048576 AS mega FROM Device AS D INNER  JOIN PivotStatisticalMonitorTypeToDevice AS PSM ON PSM.nDeviceID = D.nDeviceID INNER  JOIN StatisticalDiskIdentification AS SDI ON SDI.nPivotStatisticalMonitorTypeToDeviceID = PSM.nPivotStatisticalMonitorTypeToDeviceID INNER  JOIN StatisticalDisk AS SD ON SD.nStatisticalDiskIdentificationID = SDI.nStatisticalDiskIdentificationID WHERE D.nDeviceID = '" & nDeviceID & "' AND SD.dPollTime = (SELECT top 1 SD.dPollTime FROM Device AS D INNER  JOIN PivotStatisticalMonitorTypeToDevice AS PSM ON PSM.nDeviceID = D.nDeviceID INNER  JOIN StatisticalDiskIdentification AS SDI ON SDI.nPivotStatisticalMonitorTypeToDeviceID = PSM.nPivotStatisticalMonitorTypeToDeviceID INNER  JOIN StatisticalDisk AS SD ON SD.nStatisticalDiskIdentificationID = SDI.nStatisticalDiskIdentificationID WHERE D.nDeviceID = '" & nDeviceID & "' ORDER BY SD.dPollTime DESC) ORDER BY SDI.sDescription"

  Set oRs2 = oDb.Execute(sSql)
  oRs2.moveFirst

  While Not oRs2.EOF
  
   ' First we check if the last polled value is a recent one, if that check is enabled
   ' TODO
   
   displayName = oRs2("sDisplayName")
   description = ucase(oRs2("sDescription"))
   
   'Default value
   drvMonitorLimit = DEFAULT_THRESHOLD
   drvMonitorUnit = DEFAULT_THRESHOLD_UNIT
   
   ' We retrieve the threshold from the attribute, if it exists.
   If Not IsNull(drvMonitors) Then
    For each drvMonitor in drvMonitors
     'Is it a matching threshold ?
     tokens = split(drvMonitor, "=")
     If tokens(0) = description Then
      ' We then retrieve the threshold value AND the unit. The unit MUST be specified.
      ' Correct format is "100M", "10%", "4G" for example.
      drvMonitorUnit = ucase(Right(tokens(1),1))
      drvMonitorLimit = int(Left(tokens(1),len(tokens(1))-1))
      Exit For
     End If
    Next
   End If

   Select Case drvMonitorUnit
    Case "%"
     value = int(oRs2("perc"))
    Case "G"
     value = int(oRs2("giga"))
    Case "M"
     value = int(oRs2("mega"))
    Case Else
     ' Invalid unit, we will report a Down.
     value = -1
   End Select
   
   ' If unit is invalid, it' a down.
   If value = -1 Then
    bAlarm = true
    oChecksResult = oChecksResult & "Disk " & description & " : threshold unit is invalid (" & drvMonitorUnit & "). You MUST specify %, G or M as a threshold unit (example : C=10%;D=5G;E=650M)" & vbCrLf
   Else
    ' If unit is valid, but threshold is zero, we don't check.
    If drvMonitorLimit = 0 Then
     oChecksResult = oChecksResult & "Disk " & description & " : " & Round(value) & drvMonitorUnit & _
         " remaining space - not checked because threshold is zero." & vbCrLf
    Else
     ' Else we check.
     If value < drvMonitorLimit Then
      bAlarm = true
      oChecksResult = oChecksResult & "Disk " & description & " : " & Round(value) & drvMonitorUnit & _
          " remaining space is below threshold (" & drvMonitorLimit & drvMonitorUnit & ") - DOWN !!" & vbCrLf
     Else
      oChecksResult = oChecksResult & "Disk " & description & " : " & Round(value) & drvMonitorUnit & _
          " remaining space is above threshold (" & drvMonitorLimit & drvMonitorUnit & ") - UP" & vbCrLf
     End If
    End If
   End If
   oRs2.moveNext
  Wend

  ' Store the result in an attribute. Allows to access details even on a Device-configured action by using the  %Device.Attribute.* variable.
  
  ' Formatting it to a SQL compatible format.
  if (Right(oChecksResult,1) = vbCrLf) Then
   oChecksResultSQL = Replace(Left(oChecksResult,len(oChecksResult)-1), vbCrLf, "' + CHAR(10) + N'")
  Else
   oChecksResultSQL = Replace(oChecksResult, vbCrLf, "' + CHAR(10) + N'")
  End If
  
  ' Checking if  the attribute already exists. If not we create one, if yes we simply update it.
  sqlCheck = "SELECT nDeviceAttributeID FROM DeviceAttribute WHERE (nDeviceID = " & nDeviceID & ") AND (sName = N'" & RESULT_ATTRIBUTE & "')"
  Set oRs1 = oDb.Execute(sqlCheck)
  
  ' Storing it in DB as needed.
  If oRs1.EOF Then
   sqlStoreResult = "INSERT INTO DeviceAttribute (nDeviceID, sName, sValue) VALUES (" & _
        nDeviceID & ", N'" & RESULT_ATTRIBUTE & "', N'" & oChecksResultSQL & "')"
  Else
   sqlStoreResult = "UPDATE DeviceAttribute SET sValue = N'" & oChecksResultSQL & _
       "' WHERE (nDeviceID = " & nDeviceID & ") AND (sName = N'" & RESULT_ATTRIBUTE & "')"
  End If
  oDb.Execute(sqlStoreResult)
  
  
  ' Set the result of the monitor.
  If bAlarm Then
   oChecksResult = oChecksResult & vbCrLf & "Monitor is DOWN"
   Context.SetResult 1, oChecksResult
  Else
   oChecksResult = oChecksResult & vbCrLf & "Monitor is UP"
   Context.SetResult 0, oChecksResult
  End If
 End If
End If

' Cleanup code
Set oDb = Nothing
Set oRs2 = Nothing
Set oRs1 = Nothing

Plus this entry in the Attribute section (feel free to add more drive letters with corresponding values)

******************************
Attribute Name: Disk_Space_Thresholds
Attribute Value: 'C:\=10%;D:\=1g;'
******************************

It works for most of my servers. I'm just having problems with ones where there is no sample data.

Any reference to this script can be found in here: http://forums.ipswitch.com/Topic40728-14-1.aspx#bm40800

Post #46607
Posted 10/6/2008 12:31:43 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: Forum Members
Last Login: 10/8/2008 3:34:03 PM
Posts: 5, Visits: 17
Does anyone know if there is a way using this script or a similar one where you
can configure the down e-mail from the action policy to include the particular drive letter that is running low?

Thanks in advance for any help!
Post #47521
Posted 10/6/2008 1:28:29 PM


Time Traveler

Time TravelerTime TravelerTime TravelerTime TravelerTime TravelerTime TravelerTime TravelerTime Traveler

Group: WhatsUp Gold Expert
Last Login: Today @ 1:49:13 PM
Posts: 1,513, Visits: 5,018
Just attach an action policy to that specific monitor. Action policies that are global to a device can NOT report on which specific monitor goes down, while monitor-specific ones can, through the relevant %variables you will find in the online help.

Reading, writing and arithmetic - If you need to choose, please take option 1.
Post #47522
Posted 10/6/2008 1:56:49 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: Forum Members
Last Login: 10/8/2008 3:34:03 PM
Posts: 5, Visits: 17
Thanks for the reply. That's what I'm having trouble finding, is the variable for the drive letter. If I knew what that was, I could just include it in the message that is sent via e-mail.
Post #47524
Posted 10/7/2008 5:34:59 AM


Time Traveler

Time TravelerTime TravelerTime TravelerTime TravelerTime TravelerTime TravelerTime TravelerTime Traveler

Group: WhatsUp Gold Expert
Last Login: Today @ 1:49:13 PM
Posts: 1,513, Visits: 5,018
Hrm, ok, a bit more complicated for you. Usually I just define a WMI monitor called "Free C:", "Free D:" and so on; so the %activemonitordownnames (or something like that) %variable is just fine for me.

In your case, because you decided to use a custom script, it will be more complicated... You will somehow need to use a script to alert also, and this script will have to retrieve some info from the db (for instance, a custom attribute of the device that your script would set).

Why don't you use a built-in monitor instead of making it so hard for you ?

Reading, writing and arithmetic - If you need to choose, please take option 1.

Post #47537
Posted 10/7/2008 6:20:57 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: Forum Members
Last Login: 10/8/2008 3:34:03 PM
Posts: 5, Visits: 17
Because the WMI monitors slow down the server massively.
Post #47573