| You can use VBscript to pull SNMP information about devices. I've created a script that checks disc-space on devices/disks and uses the device attributes to set individual treshholds for Warning and for critical. Warning is 80% by default and Critical is 90%. My script requires 2 scripts. First script gathers what drives the device have (or mount points if a unix), and writes the information to the device attributes. After it has run once and gathered this information, its not needed untill you add or remove a drive/mount point. Note about SNMP and drives: In the SNMP tree, drives are assigned to instances, and these are not always the same from device to device. IE; C:\ might be instance 1, but also instance 2. This is why the first script is needed, to gather this information. Without it, the SNMP requests will not work. Script creates 2 attributes: Critical:<Drive/MountPoint>_DiskCritical_<instanceID> Value: 90 Warning:<Drive/MountPoint>_DiskWarning_<instanceID> Value: 80 The value is the treshhold for which the script reacts and sends email if its above. The second script is the script that should be always activated as an Active Monitor. The script uses SNMP to get used disc space and compares it to the total drive space. it formats it to % and check it against the value in the attribute on the device. If the percentage used is above the treshhold for the drive, it creates a file locally on the WUG server named <Device displayname>_inst_<instanceID>_<warn/crit>_<File Version> First file it creates has file version = 1. If next polling is still above treshhold, the file vill change to a "2" at the end instead. Next poll it will be 3. Why? Because I dont want bogus weird alarms that sometimes happens. When the file changes from 3 to 4, it will send an email to whatever is specified in the script. While the file is in version 4, no new mail is sent if disk useage is at "warning" level, but will send every 4th hour in "critical" state. (This can be changed ofc) The file are deleted once the drive goes under the treshhold. Note: Files are kept for 24 hours in warning state and 15 minutes in critical state after creation. This is to prevent loads of mail if device goes just above and under during short period of times The script requires that the device has SNMP credentials applied to the device. You need to create "C:\DiskAlarms" on the WUG server (or whatever folder you change the oFolder to) Tested on WUG 15 and 14. Tested on Unix, Linux, Windows and some other devices (we monitor alot of different companies). Its VBscript, not jScript. |
54 Replies
The Active Monitor that checks disk space and sends email
This requires the script posted in my next reply to be run once successfully.
''''''''''''''''''''''''''''''''''
'Static values etc'''''
''''''''''''''''''''''''''''''''''
CONVERSION_FACTOR = 1073741824
Set objDB = Context.GetDB
Set oRS = CreateObject("ADODB.Recordset")
AMName = Context.GetProperty("ActiveMonitorTypeName")
sysDeviceID = Context.GetProperty("DeviceID")
Set objSNMPRqst = CreateObject("CoreAsp.SnmpRqst")
Set objSNMPResult = objSNMPRqst.Initialize(sysDeviceID)
''''''''''''''''''''''''''''''''''
'''' Folder to save text files on local WUG server
''''''''''''''''''''''''''''''''''
sFolder = "C:\DiskAlarms\"
Set oFS = CreateObject( "Scripting.FileSystemObject" )
''''''''''''''''''''''''''''''''''
''''' Mail settings. Remember to check the script to which you want to use. You can also rename these if you change in the script
''''''''''''''''''''''''''''''''''
EmailFrom = MailFrom@domain.dom
EmailTo = MailTo@domain.dom
'Can add or remove these if you want more mail addresses in different scenarions
EmailToLime = MailTo2th@domain.dom
SmtpServer = "Your.SNMP.Server"
LarmTid = Now() 'Used to get the current time to send in mail
sqlGetDisplayName = "SELECT sDisplayName,sNote FROM Device WHERE nDeviceID = '" & sysDeviceID &"'"
oRS.Open sqlGetDisplayName, objDB, 3
DisplayName = oRS("sDisplayName")
devNote = oRS("sNote")
oRS.Close
On Error Resume Next
DevAttrNameStd = "%DiskCritical_%"
sqlGetAttrLabelAndInstanceID = "select sName,sValue from DeviceAttribute where (nDeviceID = '" & sysDeviceID & " ') and (sName like '" & DevAttrNameStd & "')"
oRS.Open sqlGetAttrLabelAndInstanceID, objDB, 3
''' Check Critical '''
Do Until oRS.EOF
DevAttrNameFromSql = oRS("sName")
DevAttrTresholdFromSql = ors("sValue")
GetInstanceID = Right(DevAttrNameFromSql, 2)
If isNumeric(GetInstanceID) then
DevInstanceID = GetInstanceID
StaticName = 16
else
DevInstanceID = Right(DevAttrNameFromSql, 1)
StaticName = 15
End If
DevAttrNameLen = Len(DevAttrNameFromSql) - StaticName
DevLabelName = Left(DevAttrNameFromSql, DevAttrNameLen)
Context.LogMessage "DevInstanceID = " & DevInstanceID
Context.LogMessage DevLabelName & " DevLabelName"
oFile1 = sFolder & DisplayName & "_inst_" & DevInstanceID & "-Crit-1.txt"
oFile2 = sFolder & DisplayName & "_inst_" & DevInstanceID & "-Crit-2.txt"
oFile3 = sFolder & DisplayName & "_inst_" & DevInstanceID & "-Crit-3.txt"
oFile4 = sFolder & DisplayName & "_inst_" & DevInstanceID & "-Crit-4.txt"
hrStorageSizeOID = "1.3.6.1.2.1.25.2.3.1.5." & DevInstanceID
hrStorageUsedOID = "1.3.6.1.2.1.25.2.3.1.6." & DevInstanceID
hrStorageAllocationUnitsOID = "1.3.6.1.2.1.25.2.3.1.4." & DevInstanceID
'Get disk information and calculate
Set objSNMPResult = objSNMPRqst.Get(hrStorageAllocationUnitsOID)
devDiskAllocResult = objSNMPResult.GetPayload
Set objSNMPREsult = objSNMPRqst.Get(hrStorageSizeOID)
devDiskSizeResult = objSNMPResult.GetPayload
devDiskSizeGB = FormatNumber(((devDiskSizeResult * devDiskAllocResult) / CONVERSION_FACTOR), 1)
Set objSNMPREsult = objSNMPRqst.Get(hrStorageUsedOID)
devDiskUsedResult = objSNMPResult.GetPayload
if devDiskUsedResult > 2000 then
devDiskUsedGB = FormatNumber(((devDiskUsedResult * devDiskAllocResult) / CONVERSION_FACTOR), 1)
devUsedPercentMath = ((devDiskUsedGB / devDiskSizeGB) * 100)
drvUsedPercentFinal = FormatNumber(devUsedPercentMath, 2)
Context.LogMessage drvUsedPercentFinal & "% used disk out of total GB: " & devDiskSizeGB
Else
drvUsedPercentFinal = 1
End if
'Reaction to disk size CRITICAL
''''''''''''''''''''''''''''''
''' This is output text for critical. Change if you want to. Warning outputtext further down in warning part of script
''''''''''''''''''''''''''''''
OutputText = "Disk " & DevLabelName & " has " & drvUsedPercentFinal & "%" & " used Diskspace (" & devDiskUsedGB & "GB out" & " of " & devDiskSizeGB & "GB" & "), Alarm threshold is " & DevAttrTresholdFromSql & "%" & vbCrLf & vbCrLf & "Alarm sent on: " & LarmTid
if int(drvUsedPercentFinal) < int(DevAttrTresholdFromSql) Then
set DateFile4 = oFS.GetFile(oFile4)
If oFS.FileExists(oFile4) Then
Context.LogMessage DateDiff("M", DateFile4.DateLastModified, Now())
If DateDiff( "n", DateFile4.DateLastModified, Now()) =< 20 Then
On Error Resume Next
Context.LogMessage "Procent under 90%. Fil 4 under 5 min gammel. Avvaktar"
oFS.DeleteFile oFile3
oFS.DeleteFile oFile2
oFS.DeleteFile oFile1
Context.SetResult 0, "Procent under 90%. Fil 4 under 5 min gammel. Avvaktar"
Else
On Error Resume Next
Context.LogMessage "Procent under 90%. Raderar filer 1-4"
oFS.DeleteFile oFile4
oFS.DeleteFile oFile3
oFS.DeleteFile oFile2
oFS.DeleteFile oFile1
Context.SetResult 0, "Procent under 90%. Raderar filer 1-4"
End if
else
On Error Resume Next
Context.LogMessage "Procent under 90%. Raderar filer 1-4"
oFS.DeleteFile oFile4
oFS.DeleteFile oFile3
oFS.DeleteFile oFile2
oFS.DeleteFile oFile1
Context.SetResult 0, "Procent under 90%. Raderar filer 1-4"
End IF
Else
If oFS.FileExists(oFile4) Then
Context.LogMessage "Fil 4 finns, disk over 90%, kollar ålder på fil 4"
On Error Resume Next
set DateFile4 = oFS.GetFile(oFile4)
oFS.DeleteFile oFile3
oFS.DeleteFile oFile2
oFS.DeleteFile oFile1
''''''''''''''''''''''''''''''''''
'''Change value here to say how often it should send mail while disk useage is in critical state
'''If this feature is unwanted, delete below if statement
''''''''''''''''''''''''''''''''''
If DateDiff( "n", DateFile4.DateLastModified, Now() ) >= 240 Then
Context.LogMessage "Skickar mail för fil4 har passerat 4 timmer. ÅTGÄRDA"
Set objEmail = CreateObject("CDO.Message")
objEmail.From = EmailFrom
objEmail.To = EmailTo
objEmail.Subject = "DiskUtilization Critical on " & DisplayName
objEmail.Textbody = DisplayName & vbCrLf & vbCr & OutputText & vbCrLf & vbCrLf & devNote
objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 1
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = SmtpServer
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objEmail.Configuration.Fields.Update
objEmail.Send
oFS.DeleteFile oFile4
oFS.CreateTextfile(oFile4)
Context.LogMessage "Skapar om fil 4 för att resette tid"
Context.SetResult 0, OutputText
else
Context.SetResult 0, OutputText
end if
Else
If oFS.FileExists(oFile3) Then
Context.LogMessage "Fil3 finns, disk over 90%, kollar ålder på fil 3 "
set DateFile3 = oFS.GetFile(oFile3)
If DateDiff( "n", DateFile3.DateLastModified, Now() ) > 6 Then
Context.LogMessage "Ålder skillnad över 6m, raderar filar och skapar ny fil"
On Error Resume Next
oFS.DeleteFile oFile3
oFS.DeleteFile oFile2
oFS.DeleteFile oFile1
oFS.CreateTextfile(oFile1)
else
Context.LogMessage "Ålder skillnad under 5m, Mailar samt flyttar fil till 4"
Set objEmail = CreateObject("CDO.Message")
objEmail.From = EmailFrom
objEmail.To = EmailTo
objEmail.Subject = "DiskUtilization Critical on " & DisplayName
objEmail.Textbody = "DiskUtilization Critical on " & DisplayName & vbCrLf & vbCr & OutputText & vbCrLf & vbCrLf & "Notes from Device:" & vbCrLf & devNote
objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 1
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = SmtpServer
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objEmail.Configuration.Fields.Update
objEmail.Send
oFS.MoveFile oFile3, oFile4
end if
else
If oFS.FileExists(oFile2) Then
Context.LogMessage "Fil finns, disk over 90%, kollar ålder på fil 2 "
set DateFile2 = oFS.GetFile(oFile2)
If DateDiff( "n", DateFile2.DateLastModified, Now() ) > 5 Then
Context.LogMessage "Ålder skillnad över 4m, raderar filar och skapar ny fil"
On Error Resume Next
oFS.DeleteFile oFile2
oFS.DeleteFile oFile1
oFS.CreateTextfile(oFile1)
else
Context.LogMessage "Ålder skillnad under 3m, flyttar fil från 2 till 3"
oFS.MoveFile oFile2, oFile3
end if
else
If oFS.FileExists(oFile1) Then
Context.LogMessage "Fil finns, disk over 90%, kollar ålder på fil 1 "
set DateFile1 = oFS.GetFile(oFile1)
If DateDiff( "n", DateFile1.DateLastModified, Now() ) > 4 Then
Context.LogMessage "Ålder skillnad över 4m, raderar filar och skapar ny fil"
On Error Resume Next
oFS.DeleteFile oFile1
oFS.CreateTextfile(oFile1)
else
Context.LogMessage "Ålder skillnad under 3m, flyttar fil 1 till 2 "
oFS.MoveFile oFile1, oFile2
end if
else
Context.Logmessage "skapar fil då ingen fans"
oFS.CreateTextfile(oFile1)
end if
end If
END if
EnD if
End if
oRS.MoveNext
Loop
oRs.Close
'''' Check warning ''''
DevAttrNameWarn = "%DiskWarning_%"
sqlGetAttrLabelAndInstanceID = "select sName,sValue from DeviceAttribute where (nDeviceID = '" & sysDeviceID & " ') and (sName like '" & DevAttrNameWarn & "')"
oRS.Open sqlGetAttrLabelAndInstanceID, objDB, 3
Do Until oRS.EOF
DevAttrNameFromSql = oRS("sName")
DevAttrTresholdFromSql = ors("sValue")
GetInstanceID = Right(DevAttrNameFromSql, 2)
If isNumeric(GetInstanceID) then
DevInstanceID = GetInstanceID
StaticName = 16
else
DevInstanceID = Right(DevAttrNameFromSql, 1)
StaticName = 15
End If
DevAttrNameLen = Len(DevAttrNameFromSql) - StaticName
DevLabelName = Left(DevAttrNameFromSql, DevAttrNameLen)
Context.LogMessage "DevInstanceID = " & DevInstanceID
Context.LogMessage DevLabelName & " DevLabelName"
oFile1 = sFolder & DisplayName & "_inst_" & DevInstanceID & "-Warn-1.txt"
oFile2 = sFolder & DisplayName & "_inst_" & DevInstanceID & "-Warn-2.txt"
oFile3 = sFolder & DisplayName & "_inst_" & DevInstanceID & "-Warn-3.txt"
oFile4 = sFolder & DisplayName & "_inst_" & DevInstanceID & "-Warn-4.txt"
oFileCritExist = sFolder & DisplayName & "_inst_" & DevInstanceID & "-Crit-4.txt"
hrStorageSizeOID = "1.3.6.1.2.1.25.2.3.1.5." & DevInstanceID
hrStorageUsedOID = "1.3.6.1.2.1.25.2.3.1.6." & DevInstanceID
hrStorageAllocationUnitsOID = "1.3.6.1.2.1.25.2.3.1.4." & DevInstanceID
'Get disk information and calculate
Set objSNMPResult = objSNMPRqst.Get(hrStorageAllocationUnitsOID)
devDiskAllocResult = objSNMPResult.GetPayload
Set objSNMPREsult = objSNMPRqst.Get(hrStorageSizeOID)
devDiskSizeResult = objSNMPResult.GetPayload
devDiskSizeGB = FormatNumber(((devDiskSizeResult * devDiskAllocResult) / CONVERSION_FACTOR), 1)
Set objSNMPREsult = objSNMPRqst.Get(hrStorageUsedOID)
devDiskUsedResult = objSNMPResult.GetPayload
if devDiskUsedResult > 2000 then
devDiskUsedGB = FormatNumber(((devDiskUsedResult * devDiskAllocResult) / CONVERSION_FACTOR), 1)
devUsedPercentMath = ((devDiskUsedGB / devDiskSizeGB) * 100)
drvUsedPercentFinal = FormatNumber(devUsedPercentMath, 2)
Context.LogMessage drvUsedPercentFinal & "% used disk out of total GB: " & devDiskSizeGB
else
drvUsedPercentFinal = 1
End if
''''''''''''''''''''''''''''''
''' This is output text for Warning. Change if you want to. Critical text further up in critical part
''''''''''''''''''''''''''''''
OutputText = "Disk " & DevLabelName & " has " & drvUsedPercentFinal & "%" & " used Diskspace (" & devDiskUsedGB & "GB out" & " of " & devDiskSizeGB & "GB" & "), Alarm threshold is " & DevAttrTresholdFromSql & "%" & vbCrLf & vbCrLf & "Alarm sent on: " & LarmTid
if oFS.FileExists(oFileCritExist) then
Context.Logmessage "Critical larm finns, ignorerar warning filhantering"
On Error Resume Next
oFS.DeleteFile oFile4
oFS.DeleteFile oFile3
oFS.DeleteFile oFile2
oFS.DeleteFile oFile1
Else
'Reaction to disk size Warning
if int(drvUsedPercentFinal) < int(DevAttrTresholdFromSql) Then
set DateFile4 = oFS.GetFile(oFile4)
If oFS.FileExists(oFile4) Then
Context.LogMessage DateDiff( "H", DateFile3.DateLastModified, Now()) & " Datediff värde"
If DateDiff( "H", DateFile4.DateLastModified, Now() ) =< 72 Then
On Error Resume Next
Context.LogMessage "Procent under 80%. Fil 4 under 24 timmar gammel. Avvaktar"
oFS.DeleteFile oFile3
oFS.DeleteFile oFile2
oFS.DeleteFile oFile1
Context.SetResult 0, "Procent under 80%. Fil 4 under 5 min gammel. Avvaktar"
Else
On Error Resume Next
Context.LogMessage "Procent under 80%. WarnFil4 över 24 timmar. Raderar filer 1-4"
oFS.DeleteFile oFile4
oFS.DeleteFile oFile3
oFS.DeleteFile oFile2
oFS.DeleteFile oFile1
Context.SetResult 0, "Procent under 80%. Raderar filer 1-4"
End if
else
On Error Resume Next
Context.LogMessage "Procent under 80%. Raderar filer 1-4"
oFS.DeleteFile oFile3
oFS.DeleteFile oFile2
oFS.DeleteFile oFile1
Context.SetResult 0, "Procent under 80%. Raderar filer 1-4"
End IF
Else
If oFS.FileExists(oFile4) Then
Context.LogMessage "Fil 4 finns, disk over 80%. Låter fil 4 vara kvar då larm har skickats"
Context.SetResult 0, OutputText
Else
If oFS.FileExists(oFile3) Then
Context.LogMessage "Fil3 finns, disk over 80%, kollar ålder på fil 3 "
set DateFile3 = oFS.GetFile(oFile3)
''''''''''''''''''''''''''''''''''
'''You can change value in next line to represent how long disk should stay over treshold before sending mail
''''''''''''''''''''''''''''''''''
If DateDiff( "n", DateFile3.DateLastModified, Now() ) >=180 Then
Context.LogMessage "Warning fil över 3 Timmar, skickar mail samt skapar warning fil 4"
Set objEmail = CreateObject("CDO.Message")
objEmail.From = EmailFrom
objEmail.To = EmailToLime
objEmail.Subject = "DiskUtilization Warning on " & DisplayName
objEmail.Textbody = vbCrLf & OutputText & vbCrLf & vbCrLf & "Notes from Device:" & vbCrLf & devNote
objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 1
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = SmtpServer
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objEmail.Configuration.Fields.Update
objEmail.Send
oFS.MoveFile oFile3, oFile4
Context.SetResult 0, OutputText
else
Context.LogMessage "Disk över warning level, fil mindre än 3 timmar, avvaktar"
Context.SetResult 0, OutPutText
end if
else
If oFS.FileExists(oFile2) Then
set DateFile2 = oFS.GetFile(oFile2)
If DateDiff( "n", DateFile2.DateLastModified, Now() ) > 4 Then
Context.LogMessage "Ålder skillnad över 4m, raderar filar och skapar ny fil"
On Error Resume Next
oFS.DeleteFile oFile2
oFS.DeleteFile oFile1
oFS.CreateTextfile(oFile1)
else
Context.LogMessage "Ålder skillnad under 3m, flyttar fil från 2 till 3"
oFS.MoveFile oFile2, oFile3
end if
else
If oFS.FileExists(oFile1) Then
set DateFile1 = oFS.GetFile(oFile1)
If DateDiff( "M", DateFile1.DateLastModified, Now() ) > 4 Then
Context.LogMessage "Ålder skillnad över 4m, raderar filar och skapar ny fil"
On Error Resume Next
oFS.DeleteFile oFile1
oFS.CreateTextfile(oFile1)
else
Context.LogMessage "Ålder skillnad under 3m, flyttar fil 1 till 2 "
oFS.MoveFile oFile1, oFile2
end if
else
Context.Logmessage "skapar fil då ingen fans"
oFS.CreateTextfile(oFile1)
end if
end If
END if
EnD if
End if
End if
oRS.MoveNext
Loop
oRs.Close
oRS.Close
objDB.Close
Set oRS = Nothing
Set objDB = Nothing
Set DateFile1 = Nothing
Set DateFile2 = Nothing
Set DateFile3 = Nothing
Set DateFile4 = Nothing
Context.SetREsult 0, "Script klar!"
This is the Active Monitor that needs to be run first to gather info about drives/mount points on the device. It should be run successfully once and then removed to avoid uncessecarly polling. Reapply if drives/mount points changes on device.
Set objDB = Context.GetDB
Set oRS = CreateObject("ADODB.Recordset")
sysDeviceID = Context.GetProperty("DeviceID")
Set objSNMPRqst = CreateObject("CoreAsp.SnmpRqst")
Set objSNMPResult = objSNMPRqst.Initialize(sysDeviceID)
For Count = 1 to 100
A = B + 1
B = A
DiskLabelInstanceOID = "1.3.6.1.2.1.25.2.3.1.3." & A
DiskStorageTypeOID = "1.3.6.1.2.1.25.2.3.1.2." & A
DiskStorageSizeOID = "1.3.6.1.2.1.25.2.3.1.5." & A
Set objSNMPREsult = objSNMPRqst.Get(DiskLabelInstanceOID)
DevLabel = objSNMPResult.GetPayload
If Left(Devlabel,1) = "/" then
LabelResultInst = DevLabel
Else
LabelResultInst = Left(Devlabel,1) & ":\"
End If
LabelAttrCrit = LabelResultInst & "_DiskCritical_"
LabelAttrWarn = LabelResultInst & "_DiskWarning__"
LabelinstCrit = LabelResultInst & "_DiskCritical_" & A
LabelInstWarn = LabelResultInst & "_DiskWarning__" & A
Set objSNMPREsult = objSNMPRqst.Get(DiskStorageTypeOID)
DiskTypeResult = objSNMPResult.GetPayload
Context.LogMessage DiskTypeResult & "DiskTypeREsult"
If DiskTypeResult = "1.3.6.1.2.1.25.2.1.4" then
Set objSNMPREsult = objSNMPRqst.Get(DiskStorageSizeOID)
devDiskSize = objSNMPResult.GetPayload
if devDiskSize > 1000000 then 'Kollar disken som vanlig
AttrExistCrit = LabelAttrCrit & "%"
AttrExistWarn = LabelAttrWarn & "%"
devAttrExistCheck = "select sName from DeviceAttribute where (nDeviceID = '" & sysDeviceID & " ') and (sName like '" & AttrExistCrit & "')"
Context.LogMessage "SQL query för att kolla om fil fins: " & devAttrexistCheck
oRS.Open devAttrexistCheck, objDB, 3
devAttrExistsCheckResult = oRS.EOF
oRS.Close
Context.Logmessage devAttrExistsCheckResult & " oRS.EOF-resultat"
'SKapa crit attr
If devAttrExistsCheckResult = True then
Context.Logmessage "Attribut finns ej, skapar " & LabelinstCrit
InsAttrCrit = "INSERT INTO DeviceAttribute (nDeviceID, sName, sValue) VALUES ("& _
sysDeviceID & ",'" & LabelInstCrit & "','" & "90" & "')"
objDB.Execute(InsAttrCrit)
else
Context.Logmessage LabelInstCrit & " attributet finns, uppdaterar"
UpdAttrCritDB = "UPDATE DeviceAttribute SET sName = '" & LabelInstCrit & _
"' WHERE (nDeviceID = " & sysDeviceID & ") AND (sName like '" & AttrExistCrit & "')"
objDB.Execute(UpdAttrCritDB)
End if
'Skapa Warn Attr
devAttrExistCheckWarn = "select sName from DeviceAttribute where (nDeviceID = '" & sysDeviceID & " ') and (sName like '" & AttrExistWarn & "')"
Context.LogMessage "SQL query för att kolla om fil fins: " & devAttrexistCheckWarn
oRS.Open devAttrexistCheckWarn, objDB, 3
devAttrExistsCheckResult = oRS.EOF
oRS.Close
Context.Logmessage devAttrExistsCheckResult & " oRS.EOF-resultat"
If devAttrExistsCheckResult = True then
Context.Logmessage "Attribut finns ej, skapar " & LabelinstWarn
InsAttrWarn = "INSERT INTO DeviceAttribute (nDeviceID, sName, sValue) VALUES ("& _
sysDeviceID & ",'" & LabelInstWarn & "','" & "80" & "')"
objDB.Execute(InsAttrWarn)
else
Context.Logmessage LabelInstWarn & " attributet finns, uppdaterar"
UpdAttrWarnDB = "UPDATE DeviceAttribute SET sName = '" & LabelInstWarn & _
"' WHERE (nDeviceID = " & sysDeviceID & ") AND (sName like '" & AttrExistWarn & "')"
objDB.Execute(UpdAttrWarnDB)
End if
else
Context.LogMessage "Diskstorlek under 1000000"
End if
Else
Context.LogMessage "Ingen diskar fanns på instans " & A
Context.SetResult 0, "Ingen diskar fanns på instans " & A
End if
Context.LogMessage "Börjar om på nästa instans"
Next
Context.SetResult 0, "Script Klar"
''''''''''''''''''''''''''''''''''''
''' OIDs from SNMP. Its good to have available somewhere
''' The OID is from a widely used mib. Havent seen any Os not use it yet
'''''''''''''''''''''''''''''''''''
'hrStorageOther hrStorageOther 1.3.6.1.2.1.25.2.1.1
'hrStorageRam hrStorageRam 1.3.6.1.2.1.25.2.1.2
'hrStorageVirtualMemory hrStorageVirtualMemory 1.3.6.1.2.1.25.2.1.3
'hrStorageFixedDisk hrStorageFixedDisk 1.3.6.1.2.1.25.2.1.4
'hrStorageRemovableDisk hrStorageRemovableDisk 1.3.6.1.2.1.25.2.1.5
'hrStorageFloppyDisk hrStorageFloppyDisk 1.3.6.1.2.1.25.2.1.6
'hrStorageCompactDisc hrStorageCompactDisc 1.3.6.1.2.1.25.2.1.7
'hrStorageRamDisk hrStorageRamDisk 1.3.6.1.2.1.25.2.1.8
'hrStorageIndex hrStorageIndex 1.3.6.1.2.1.25.2.3.1.1
'hrStorageType hrStorageType 1.3.6.1.2.1.25.2.3.1.2
'hrStorageDescr hrStorageDescr 1.3.6.1.2.1.25.2.3.1.3
'hrStorageAllocationUnits hrStorageAllocationUnits 1.3.6.1.2.1.25.2.3.1.4
'hrStorageSize hrStorageSize 1.3.6.1.2.1.25.2.3.1.5
'hrStorageUsed hrStorageUsed 1.3.6.1.2.1.25.2.3.1.6
'hrStorageAllocationFailures hrStorageAllocationFailures 1.3.6.1.2.1.25.2.3.1.7
Hi Robin,
I have tested your script and it works great. I'm trying to find a script that will allow me to set different thresholds for each drive letter. We have a handful of servers with very large drives so we would like a default alert set at 90% and then for the larger drives 95 or 97%, is it possible to integrate this as a configurable option in your script.
Apologies, I have little to no scripting experience so I'm struggling to get this configured. If you know of any other scripts that already do this please do point me in the right direction.
You help would be appreciated.
G
That's easy to fix :) Do you want 2 alarms? 1 for warning and 1 for critical? Or you just want critical?
At what levels do you want the different thresholds?
Hi Robin, thanks for your responce, just critical as we find the warnings just get ignored. default to be set at 90%, then specific drive letters to beconfigurable.
Also although I said I got your scripts working fine, it seem they are not sending the emails. For a test win2k3 server I have 3 files in the DiskAlarms folder called "testio.hiscox.com_inst_2-Crit-4.txt", "testio.hiscox.com_inst_4-Crit-4.txt" & testio.hiscox.com_inst_6-Crit-4.txt"
The mail settings I am using are these.. Not sure what EmailToLime is for?
EmailFrom = "WUGAlerts@domain.com"
EmailTo = "!Service-Alert-WUGTest@domain.com"
'Can add or remove these if you want more mail addresses in different scenarions
EmailToLime = "!Service-Alert-WUGTest@domain.com"
SmtpServer = "relay1.domain.com"
Thanks for all your help
Ye.. I didnt really clean up my script example. Some posts where in it from the beginning but taken outof the script but I didnt remove it all.
"EmailTo" are just names that can be anything. They are called on in this part: (In the "objEmail.To =" part)
Set objEmail = CreateObject("CDO.Message")
objEmail.From = EmailFrom
objEmail.To = EmailTo
objEmail.Subject = "DiskUtilization Warning on " & DisplayName
objEmail.Textbody = vbCrLf & OutputText & vbCrLf & vbCrLf & "Notes from Device:" & vbCrLf & devNote
objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 1
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = SmtpServer
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objEmail.Configuration.Fields.Update
objEmail.Send
In this part you can even modify the mail subject and text :)
As long as your "SmtpServer" is set to your relay server, it should work. We use our WUG server as SMTP relay, so we got our WUG server IP adress defined. have you made sure your email server defined are allowing the WUG server to relay?
You can also do this to test:
Remove the .txt files and the script from the device. Go into active monitor library. Choose your script and choose "test". Point to the device with attributes (you can set warning and critical to 1 in the attributes). Now, you will get a little more output text on whats happening.
Also: Did you want any automation in the critical threshold values? e.g. > 500GB = 95%, > 250 = 93%, rest 100GB?
Thanks Robin, we have smtp alerts working for WUG for other built in active monitors, I have double checked all the settings and run the test but still not recieving any emails, so not sure what could be broken here. I have also checked the WUG server can speak to the smtp relay on port 25.
This is the the test output
DevInstanceID = 2
C:\ DevLabelName
92.50% used disk out of total GB: 12.0
skapar fil då ingen fans
DevInstanceID = 4
E:\ DevLabelName
99.20% used disk out of total GB: 50.0
skapar fil då ingen fans
DevInstanceID = 5
L:\ DevLabelName
20.00% used disk out of total GB: 1.0
Procent under 90%. Raderar filer 1-4
DevInstanceID = 6
P:\ DevLabelName
97.50% used disk out of total GB: 4.0
skapar fil då ingen fans
DevInstanceID = 2
C:\ DevLabelName
92.50% used disk out of total GB: 12.0
skapar fil då ingen fans
DevInstanceID = 4
E:\ DevLabelName
99.20% used disk out of total GB: 50.0
skapar fil då ingen fans
DevInstanceID = 5
L:\ DevLabelName
20.00% used disk out of total GB: 1.0
Procent under 80%. Raderar filer 1-4
DevInstanceID = 6
P:\ DevLabelName
97.50% used disk out of total GB: 4.0
skapar fil då ingen fans
Script klar!
Yes some automation would be great so that we didn't have to manually set this up for indervidule servers, but also with the ability to override these for sertain drives if required.
For example these can be the automated threshholds.
<500GB = 90%, =>500GB = 95%, =>1024GB = 97%
But also to have the ability to override these, i.e. if I wanted to set the E drive to 80% or even exclude it from alerting all together. We use all drive letters in our environment so it get a little messy, appologies if this make things complicated.
I'll fix a version that only uses critical (no warning part) and with those values you've provided.
Yes, it will work in the same way it does now. My script will only update the values if there is no current attribute. So if you add a disk, the infogather script will add an attribute with value defined in the script. It will not change/override existing attributes.
For the test output: Use test again untill you get the "Ålder skillnad under 5m, mailar samt flyttar fil till 4" and post result here :)
//Robin
I've kept re-running the the but can not get that out put. This is the latest.
DevInstanceID = 2
C:\ DevLabelName
92.50% used disk out of total GB: 12.0
Fil 4 finns, disk over 90%, kollar ålder på fil 4
DevInstanceID = 4
E:\ DevLabelName
99.20% used disk out of total GB: 50.0
Fil 4 finns, disk over 90%, kollar ålder på fil 4
DevInstanceID = 5
L:\ DevLabelName
20.00% used disk out of total GB: 1.0
Procent under 90%. Raderar filer 1-4
DevInstanceID = 6
P:\ DevLabelName
97.50% used disk out of total GB: 4.0
Fil 4 finns, disk over 90%, kollar ålder på fil 4
DevInstanceID = 2
C:\ DevLabelName
92.50% used disk out of total GB: 12.0
Critical larm finns, ignorerar warning filhantering
DevInstanceID = 4
E:\ DevLabelName
99.20% used disk out of total GB: 50.0
Critical larm finns, ignorerar warning filhantering
DevInstanceID = 5
L:\ DevLabelName
20.00% used disk out of total GB: 1.0
Procent under 80%. Raderar filer 1-4
DevInstanceID = 6
P:\ DevLabelName
97.50% used disk out of total GB: 4.0
Critical larm finns, ignorerar warning filhantering
Script klar!
Just in case something is wrong with my script I have copied it below.
''''''''''''''''''''''''''''''''''
'Static values etc'''''
''''''''''''''''''''''''''''''''''
CONVERSION_FACTOR = 1073741824
Set objDB = Context.GetDB
Set oRS = CreateObject("ADODB.Recordset")
AMName = Context.GetProperty("ActiveMonitorTypeName")
sysDeviceID = Context.GetProperty("DeviceID")
Set objSNMPRqst = CreateObject("CoreAsp.SnmpRqst")
Set objSNMPResult = objSNMPRqst.Initialize(sysDeviceID)
''''''''''''''''''''''''''''''''''
'''' Folder to save text files on local WUG server
''''''''''''''''''''''''''''''''''
sFolder = "C:\DiskAlarms\"
Set oFS = CreateObject( "Scripting.FileSystemObject" )
''''''''''''''''''''''''''''''''''
''''' Mail settings. Remember to check the script to which you want to use. You can also rename these if you change in the script
''''''''''''''''''''''''''''''''''
EmailFrom = "testing123@hiscox.com"
EmailTo = "graeme.orrin@hiscox.com"
'Can add or remove these if you want more mail addresses in different scenarions
SmtpServer = "relay1.hiscox.com"
LarmTid = Now() 'Used to get the current time to send in mail
sqlGetDisplayName = "SELECT sDisplayName,sNote FROM Device WHERE nDeviceID = '" & sysDeviceID &"'"
oRS.Open sqlGetDisplayName, objDB, 3
DisplayName = oRS("sDisplayName")
devNote = oRS("sNote")
oRS.Close
On Error Resume Next
DevAttrNameStd = "%DiskCritical_%"
sqlGetAttrLabelAndInstanceID = "select sName,sValue from DeviceAttribute where (nDeviceID = '" & sysDeviceID & " ') and (sName like '" & DevAttrNameStd & "')"
oRS.Open sqlGetAttrLabelAndInstanceID, objDB, 3
''' Check Critical '''
Do Until oRS.EOF
DevAttrNameFromSql = oRS("sName")
DevAttrTresholdFromSql = ors("sValue")
GetInstanceID = Right(DevAttrNameFromSql, 2)
If isNumeric(GetInstanceID) then
DevInstanceID = GetInstanceID
StaticName = 16
else
DevInstanceID = Right(DevAttrNameFromSql, 1)
StaticName = 15
End If
DevAttrNameLen = Len(DevAttrNameFromSql) - StaticName
DevLabelName = Left(DevAttrNameFromSql, DevAttrNameLen)
Context.LogMessage "DevInstanceID = " & DevInstanceID
Context.LogMessage DevLabelName & " DevLabelName"
oFile1 = sFolder & DisplayName & "_inst_" & DevInstanceID & "-Crit-1.txt"
oFile2 = sFolder & DisplayName & "_inst_" & DevInstanceID & "-Crit-2.txt"
oFile3 = sFolder & DisplayName & "_inst_" & DevInstanceID & "-Crit-3.txt"
oFile4 = sFolder & DisplayName & "_inst_" & DevInstanceID & "-Crit-4.txt"
hrStorageSizeOID = "1.3.6.1.2.1.25.2.3.1.5." & DevInstanceID
hrStorageUsedOID = "1.3.6.1.2.1.25.2.3.1.6." & DevInstanceID
hrStorageAllocationUnitsOID = "1.3.6.1.2.1.25.2.3.1.4." & DevInstanceID
'Get disk information and calculate
Set objSNMPResult = objSNMPRqst.Get(hrStorageAllocationUnitsOID)
devDiskAllocResult = objSNMPResult.GetPayload
Set objSNMPREsult = objSNMPRqst.Get(hrStorageSizeOID)
devDiskSizeResult = objSNMPResult.GetPayload
devDiskSizeGB = FormatNumber(((devDiskSizeResult * devDiskAllocResult) / CONVERSION_FACTOR), 1)
Set objSNMPREsult = objSNMPRqst.Get(hrStorageUsedOID)
devDiskUsedResult = objSNMPResult.GetPayload
if devDiskUsedResult > 2000 then
devDiskUsedGB = FormatNumber(((devDiskUsedResult * devDiskAllocResult) / CONVERSION_FACTOR), 1)
devUsedPercentMath = ((devDiskUsedGB / devDiskSizeGB) * 100)
drvUsedPercentFinal = FormatNumber(devUsedPercentMath, 2)
Context.LogMessage drvUsedPercentFinal & "% used disk out of total GB: " & devDiskSizeGB
Else
drvUsedPercentFinal = 1
End if
'Reaction to disk size CRITICAL
''''''''''''''''''''''''''''''
''' This is output text for critical. Change if you want to. Warning outputtext further down in warning part of script
''''''''''''''''''''''''''''''
OutputText = "Disk " & DevLabelName & " has " & drvUsedPercentFinal & "%" & " used Diskspace (" & devDiskUsedGB & "GB out" & " of " & devDiskSizeGB & "GB" & "), Alarm threshold is " & DevAttrTresholdFromSql & "%" & vbCrLf & vbCrLf & "Alarm sent on: " & LarmTid
if int(drvUsedPercentFinal) < int(DevAttrTresholdFromSql) Then
set DateFile4 = oFS.GetFile(oFile4)
If oFS.FileExists(oFile4) Then
Context.LogMessage DateDiff("M", DateFile4.DateLastModified, Now())
If DateDiff( "n", DateFile4.DateLastModified, Now()) =< 20 Then
On Error Resume Next
Context.LogMessage "Procent under 90%. Fil 4 under 5 min gammel. Avvaktar"
oFS.DeleteFile oFile3
oFS.DeleteFile oFile2
oFS.DeleteFile oFile1
Context.SetResult 0, "Procent under 90%. Fil 4 under 5 min gammel. Avvaktar"
Else
On Error Resume Next
Context.LogMessage "Procent under 90%. Raderar filer 1-4"
oFS.DeleteFile oFile4
oFS.DeleteFile oFile3
oFS.DeleteFile oFile2
oFS.DeleteFile oFile1
Context.SetResult 0, "Procent under 90%. Raderar filer 1-4"
End if
else
On Error Resume Next
Context.LogMessage "Procent under 90%. Raderar filer 1-4"
oFS.DeleteFile oFile4
oFS.DeleteFile oFile3
oFS.DeleteFile oFile2
oFS.DeleteFile oFile1
Context.SetResult 0, "Procent under 90%. Raderar filer 1-4"
End IF
Else
If oFS.FileExists(oFile4) Then
Context.LogMessage "Fil 4 finns, disk over 90%, kollar ålder på fil 4"
On Error Resume Next
set DateFile4 = oFS.GetFile(oFile4)
oFS.DeleteFile oFile3
oFS.DeleteFile oFile2
oFS.DeleteFile oFile1
'''''''''''''''''''''''''''''''''
'''Change value here to say how often it should send mail while disk useage is in critical state
'''If this feature is unwanted, delete below if statement
''''''''''''''''''''''''''''''''''
If DateDiff( "n", DateFile4.DateLastModified, Now() ) >= 1 Then
Context.LogMessage "Skickar mail för fil4 har passerat 4 timmer. ÅTGÄRDA"
Set objEmail = CreateObject("CDO.Message")
objEmail.From = EmailFrom
objEmail.To = EmailTo
objEmail.Subject = "DiskUtilization Critical on " & DisplayName
objEmail.Textbody = DisplayName & vbCrLf & vbCr & OutputText & vbCrLf & vbCrLf & devNote
objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 1
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = SmtpServer
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objEmail.Configuration.Fields.Update
objEmail.Send
oFS.DeleteFile oFile4
oFS.CreateTextfile(oFile4)
Context.LogMessage "Skapar om fil 4 för att resette tid"
Context.SetResult 0, OutputText
else
Context.SetResult 0, OutputText
end if
Else
If oFS.FileExists(oFile3) Then
Context.LogMessage "Fil3 finns, disk over 90%, kollar ålder på fil 3 "
set DateFile3 = oFS.GetFile(oFile3)
If DateDiff( "n", DateFile3.DateLastModified, Now() ) > 6 Then
Context.LogMessage "Ålder skillnad över 6m, raderar filar och skapar ny fil"
On Error Resume Next
oFS.DeleteFile oFile3
oFS.DeleteFile oFile2
oFS.DeleteFile oFile1
oFS.CreateTextfile(oFile1)
else
Context.LogMessage "Ålder skillnad under 5m, Mailar samt flyttar fil till 4"
Set objEmail = CreateObject("CDO.Message")
objEmail.From = EmailFrom
objEmail.To = EmailTo
objEmail.Subject = "DiskUtilization Critical on " & DisplayName
objEmail.Textbody = "DiskUtilization Critical on " & DisplayName & vbCrLf & vbCr & OutputText & vbCrLf & vbCrLf & "Notes from Device:" & vbCrLf & devNote
objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 1
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = SmtpServer
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objEmail.Configuration.Fields.Update
objEmail.Send
oFS.MoveFile oFile3, oFile4
end if
else
If oFS.FileExists(oFile2) Then
Context.LogMessage "Fil finns, disk over 90%, kollar ålder på fil 2 "
set DateFile2 = oFS.GetFile(oFile2)
If DateDiff( "n", DateFile2.DateLastModified, Now() ) > 5 Then
Context.LogMessage "Ålder skillnad över 4m, raderar filar och skapar ny fil"
On Error Resume Next
oFS.DeleteFile oFile2
oFS.DeleteFile oFile1
oFS.CreateTextfile(oFile1)
else
Context.LogMessage "Ålder skillnad under 3m, flyttar fil från 2 till 3"
oFS.MoveFile oFile2, oFile3
end if
else
If oFS.FileExists(oFile1) Then
Context.LogMessage "Fil finns, disk over 90%, kollar ålder på fil 1 "
set DateFile1 = oFS.GetFile(oFile1)
If DateDiff( "n", DateFile1.DateLastModified, Now() ) > 4 Then
Context.LogMessage "Ålder skillnad över 4m, raderar filar och skapar ny fil"
On Error Resume Next
oFS.DeleteFile oFile1
oFS.CreateTextfile(oFile1)
else
Context.LogMessage "Ålder skillnad under 3m, flyttar fil 1 till 2 "
oFS.MoveFile oFile1, oFile2
end if
else
Context.Logmessage "skapar fil då ingen fans"
oFS.CreateTextfile(oFile1)
end if
end If
END if
EnD if
End if
oRS.MoveNext
Loop
oRs.Close
'''' Check warning ''''
DevAttrNameWarn = "%DiskWarning_%"
sqlGetAttrLabelAndInstanceID = "select sName,sValue from DeviceAttribute where (nDeviceID = '" & sysDeviceID & " ') and (sName like '" & DevAttrNameWarn & "')"
oRS.Open sqlGetAttrLabelAndInstanceID, objDB, 3
Do Until oRS.EOF
DevAttrNameFromSql = oRS("sName")
DevAttrTresholdFromSql = ors("sValue")
GetInstanceID = Right(DevAttrNameFromSql, 2)
If isNumeric(GetInstanceID) then
DevInstanceID = GetInstanceID
StaticName = 16
else
DevInstanceID = Right(DevAttrNameFromSql, 1)
StaticName = 15
End If
DevAttrNameLen = Len(DevAttrNameFromSql) - StaticName
DevLabelName = Left(DevAttrNameFromSql, DevAttrNameLen)
Context.LogMessage "DevInstanceID = " & DevInstanceID
Context.LogMessage DevLabelName & " DevLabelName"
oFile1 = sFolder & DisplayName & "_inst_" & DevInstanceID & "-Warn-1.txt"
oFile2 = sFolder & DisplayName & "_inst_" & DevInstanceID & "-Warn-2.txt"
oFile3 = sFolder & DisplayName & "_inst_" & DevInstanceID & "-Warn-3.txt"
oFile4 = sFolder & DisplayName & "_inst_" & DevInstanceID & "-Warn-4.txt"
oFileCritExist = sFolder & DisplayName & "_inst_" & DevInstanceID & "-Crit-4.txt"
hrStorageSizeOID = "1.3.6.1.2.1.25.2.3.1.5." & DevInstanceID
hrStorageUsedOID = "1.3.6.1.2.1.25.2.3.1.6." & DevInstanceID
hrStorageAllocationUnitsOID = "1.3.6.1.2.1.25.2.3.1.4." & DevInstanceID
'Get disk information and calculate
Set objSNMPResult = objSNMPRqst.Get(hrStorageAllocationUnitsOID)
devDiskAllocResult = objSNMPResult.GetPayload
Set objSNMPREsult = objSNMPRqst.Get(hrStorageSizeOID)
devDiskSizeResult = objSNMPResult.GetPayload
devDiskSizeGB = FormatNumber(((devDiskSizeResult * devDiskAllocResult) / CONVERSION_FACTOR), 1)
Set objSNMPREsult = objSNMPRqst.Get(hrStorageUsedOID)
devDiskUsedResult = objSNMPResult.GetPayload
if devDiskUsedResult > 2000 then
devDiskUsedGB = FormatNumber(((devDiskUsedResult * devDiskAllocResult) / CONVERSION_FACTOR), 1)
devUsedPercentMath = ((devDiskUsedGB / devDiskSizeGB) * 100)
drvUsedPercentFinal = FormatNumber(devUsedPercentMath, 2)
Context.LogMessage drvUsedPercentFinal & "% used disk out of total GB: " & devDiskSizeGB
else
drvUsedPercentFinal = 1
End if
''''''''''''''''''''''''''''''
''' This is output text for Warning. Change if you want to. Critical text further up in critical part
''''''''''''''''''''''''''''''
OutputText = "Disk " & DevLabelName & " has " & drvUsedPercentFinal & "%" & " used Diskspace (" & devDiskUsedGB & "GB out" & " of " & devDiskSizeGB & "GB" & "), Alarm threshold is " & DevAttrTresholdFromSql & "%" & vbCrLf & vbCrLf & "Alarm sent on: " & LarmTid
if oFS.FileExists(oFileCritExist) then
Context.Logmessage "Critical larm finns, ignorerar warning filhantering"
On Error Resume Next
oFS.DeleteFile oFile4
oFS.DeleteFile oFile3
oFS.DeleteFile oFile2
oFS.DeleteFile oFile1
Else
'Reaction to disk size Warning
if int(drvUsedPercentFinal) < int(DevAttrTresholdFromSql) Then
set DateFile4 = oFS.GetFile(oFile4)
If oFS.FileExists(oFile4) Then
Context.LogMessage DateDiff( "H", DateFile3.DateLastModified, Now()) & " Datediff värde"
If DateDiff( "H", DateFile4.DateLastModified, Now() ) =< 72 Then
On Error Resume Next
Context.LogMessage "Procent under 80%. Fil 4 under 24 timmar gammel. Avvaktar"
oFS.DeleteFile oFile3
oFS.DeleteFile oFile2
oFS.DeleteFile oFile1
Context.SetResult 0, "Procent under 80%. Fil 4 under 5 min gammel. Avvaktar"
Else
On Error Resume Next
Context.LogMessage "Procent under 80%. WarnFil4 över 24 timmar. Raderar filer 1-4"
oFS.DeleteFile oFile4
oFS.DeleteFile oFile3
oFS.DeleteFile oFile2
oFS.DeleteFile oFile1
Context.SetResult 0, "Procent under 80%. Raderar filer 1-4"
End if
else
On Error Resume Next
Context.LogMessage "Procent under 80%. Raderar filer 1-4"
oFS.DeleteFile oFile3
oFS.DeleteFile oFile2
oFS.DeleteFile oFile1
Context.SetResult 0, "Procent under 80%. Raderar filer 1-4"
End IF
Else
If oFS.FileExists(oFile4) Then
Context.LogMessage "Fil 4 finns, disk over 80%. Låter fil 4 vara kvar då larm har skickats"
Context.SetResult 0, OutputText
Else
If oFS.FileExists(oFile3) Then
Context.LogMessage "Fil3 finns, disk over 80%, kollar ålder på fil 3 "
set DateFile3 = oFS.GetFile(oFile3)
''''''''''''''''''''''''''''''''''
'''You can change value in next line to represent how long disk should stay over treshold before sending mail
''''''''''''''''''''''''''''''''''
If DateDiff( "n", DateFile3.DateLastModified, Now() ) >=1 Then
Context.LogMessage "Warning fil över 3 Timmar, skickar mail samt skapar warning fil 4"
Set objEmail = CreateObject("CDO.Message")
objEmail.From = EmailFrom
objEmail.To = EmailToLime
objEmail.Subject = "DiskUtilization Warning on " & DisplayName
objEmail.Textbody = vbCrLf & OutputText & vbCrLf & vbCrLf & "Notes from Device:" & vbCrLf & devNote
objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 1
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = SmtpServer
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objEmail.Configuration.Fields.Update
objEmail.Send
oFS.MoveFile oFile3, oFile4
Context.SetResult 0, OutputText
else
Context.LogMessage "Disk över warning level, fil mindre än 3 timmar, avvaktar"
Context.SetResult 0, OutPutText
end if
else
If oFS.FileExists(oFile2) Then
set DateFile2 = oFS.GetFile(oFile2)
If DateDiff( "n", DateFile2.DateLastModified, Now() ) > 4 Then
Context.LogMessage "Ålder skillnad över 4m, raderar filar och skapar ny fil"
On Error Resume Next
oFS.DeleteFile oFile2
oFS.DeleteFile oFile1
oFS.CreateTextfile(oFile1)
else
Context.LogMessage "Ålder skillnad under 3m, flyttar fil från 2 till 3"
oFS.MoveFile oFile2, oFile3
end if
else
If oFS.FileExists(oFile1) Then
set DateFile1 = oFS.GetFile(oFile1)
If DateDiff( "M", DateFile1.DateLastModified, Now() ) > 4 Then
Context.LogMessage "Ålder skillnad över 4m, raderar filar och skapar ny fil"
On Error Resume Next
oFS.DeleteFile oFile1
oFS.CreateTextfile(oFile1)
else
Context.LogMessage "Ålder skillnad under 3m, flyttar fil 1 till 2 "
oFS.MoveFile oFile1, oFile2
end if
else
Context.Logmessage "skapar fil då ingen fans"
oFS.CreateTextfile(oFile1)
end if
end If
END if
EnD if
End if
End if
oRS.MoveNext
Loop
oRs.Close
oRS.Close
objDB.Close
Set oRS = Nothing
Set objDB = Nothing
Set DateFile1 = Nothing
Set DateFile2 = Nothing
Set DateFile3 = Nothing
Set DateFile4 = Nothing
Context.SetREsult 0, "Script klar!"
Allrighty. I've checked it up.
Your not using your local server as SMTP are you? You are using an external relay.
In that case, this has to be edited:
objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 1
1 = local
2 = port
3 = exchange. Try changin to 2 in all fields (3 places) then try to change to 3 if it still doesnt email out!
Btw: Do you want a low threshold limit aswell? currently there is a check that excludes disk under 1-4GB (depending on block size, I didnt make it into GB size.. Beeing lazy always bites back..)
//Robin (still gonna fix the other script, will see if I get time today!)
= 2 works a treat! All emails now working.
No need for a low threshold limit, if you could provide some basic intructions too for if I needed to change the limits that would be great!
Hi Robin, the main requirment I have is to set custom thresholds for indervidual device drives. The more I think about how we need it the more it makes sence to be able to set a percentage threshold for drive letters and an option to exclude certain drives from alerts altogether. Default thresholds can also be set as stated below but if not, it is more imprtant for us to set custom thresholds on specific drives. (C=90%, E=95%, F=Exclude)
Default thresholds
<500GB = 90%, =>500GB = 95%, =>1024GB = 97%
Custom thresholds for individual device drives will still be available (same conecpt: 1 attribute for each drive on each device)
To exclude a drive from alertinging, just make the number above (e.g. change attribute value to: (180 - alert of")
I can fix so you only get 1 attribute per drive per device (critical) in 20 minutes. The default value will be 90% and you can change it afterwards without problems (or even take away alerting all together for specific drives)
To make it automatically set initial threshold based on disk size, it'd take me about 1 hour more (maybe less if I hit the nail on the head the first time).
Which you want me to do?
Thanks Robin, appriciate your time on this, custom thresholds for individual device drives is the priority with a default critical of 90%. Im not 100% sure how to customize and exclude indervidul drive thresholds as you have explaned but I'm sure it will all make sence once I can see the script. If you can provide an idiots guide that would be great.
Thanks again
Allrighty, script is ready!
InfoGatherCritOnly = Add to device as an active monitor. call it "DiskInfoGather" (example only). Add it to desired device(s) When attributes are added (see below), remove the active monitor.
Add another active monitor with the content of "CheckCritOnly". Call it "DiskCheck". Add the active monitor to your device(s) Now your are monitoring your device with default value of 90% per drive.
Now, to change value, or exclude a drive from alerting on a device:
Just change the values on the device attribute!
In the below attached image, I've turned alarms off from C: by changing the value to above 100. I like to add "1" infront as I still have my original value after it. I add text so others can see its not a typo.
My D:\ is default 90% warning. By changing the value to 95, it will not send email before 95%
PS: Dont forget to change the SendUsing to "2" again. I had 1 in my scenario so I didnt change because of testing purpose.
Also: This mail will continue to send mail every 240 minute (4 hours) while its above critical value. to change this, change the part:

If DateDiff( "n", DateFile4.DateLastModified, Now() ) >= 240 Then
to another value. Ie, 120 for 2 hours.
Attachments
You are a star, it works a treat, I owe you one.....
One question, how long out of threshold does it wait before alerting or is it instantaneous?
Aprox 4 minutes if you got a default polling on 1 minute.
First poll: File#1 created. Second poll file#2, third poll File#3, fourth poll File#4 and email is sent.
There is a check on the file age. If age is above 5 or 6 minutes it will start over from file#1. So from first poll, you have to get 4 successfull polls in 6 minutes to get an alarm.
Hey Robin, Hope your well.
I'm having an issue where I'm getting "Disk Utilisation Alert is Down on Device" and then "up" again within a minute. These happen randomly, for example over l;ast night I propably had 100 or so emails. We have over 1000 devices.
I have tried uping the default polling interval from 60 but hasn't done anything, just delays the device up alert
Whats the best way to stop these? May be I;ve not used the best practice for the alerts.
I have used the a global action policy under "actions" for each device. is that the best way to do it?
Oh ye.. You should increase the timeout for the script. The default is 10 seconds. I have mine on 55 seconds (This script aint meant to monitor up/down). This applies to both the infogather and the check part (remember to take away the diskinfo script as its uneccesary polling once its collected disk info)
I'm using device action policy aswell. When I changed from 10 sec to 55 I dont get down on this particular moniitor :)
From experience I dont like email alarm at 1 down. We require 2 min down on most devices (few exceptions) before it causes alarms.
That has done the trick, no more alerts for this active monitor. Thanks again.
Hey Guys,
Great work on this script !
One quick question, it it possible to have this script either just mark the device as down ? or send an snmp trap ?
In my case, the support group will not take emails for alerts.
Thanks !
Its easy to get it marked as down. I'll leave a warning for that though:
When the device is down because of disk space, it will not trigger a down because of ping, snmp, or any other monitor.
I dont know how to send SNMP trap (Dont even know if its possible!).
You still want the device to go down if disk alarm goes above value? Do you want it to stayd own X minutes only and then up if its a disk alarm, or you want it ti stay down untill problem is solved?
Hey Robin,
thanks so much for your help !
I would say it should stay down till the problem is resolved
Cheers
Jon.
hi jon!
I've not forgotten you, just have had loads to do.
How you want the script? You just want able to set the device to "down" if its exceeds a custom set threshold for a drive on a device?
Hello Jon!
Better late than never...
same applies to earlier posts, only thing different: When the drive % is higher than the value in the attribute, the active monitor will stay down untill resolved.
This is script part2.
You need this part:
InfoGatherCritOnly.txt - 2.3 KB (a few posts higher up)
Hope its still needed!
CONVERSION_FACTOR = 1073741824
Set objDB = Context.GetDB
Set oRS = CreateObject("ADODB.Recordset")
sFolder = "C:\DiskAlarms\"
Set oFS = CreateObject( "Scripting.FileSystemObject" )
AMName = Context.GetProperty("ActiveMonitorTypeName")
sysDeviceID = Context.GetProperty("DeviceID")
Set objSNMPRqst = CreateObject("CoreAsp.SnmpRqst")
Set objSNMPResult = objSNMPRqst.Initialize(sysDeviceID)
EmailFrom = "from@domain.se"
EmailTo = "to@domain.se"
SmtpServer = "smtpserver.domain.se"
LarmTid = Now()
sqlGetDisplayName = "SELECT sDisplayName,sNote FROM Device WHERE nDeviceID = '" & sysDeviceID &"'"
oRS.Open sqlGetDisplayName, objDB, 3
DisplayName = oRS("sDisplayName")
devNote = oRS("sNote")
oRS.Close
On Error Resume Next
DevAttrNameStd = "%DiskCritical_%"
sqlGetAttrLabelAndInstanceID = "select sName,sValue from DeviceAttribute where (nDeviceID = '" & sysDeviceID & " ') and (sName like '" & DevAttrNameStd & "')"
oRS.Open sqlGetAttrLabelAndInstanceID, objDB, 3
''' Check Critical '''
Do Until oRS.EOF
DevAttrNameFromSql = oRS("sName")
DevAttrTresholdFromSql = ors("sValue")
GetInstanceID = Right(DevAttrNameFromSql, 2)
If isNumeric(GetInstanceID) then
DevInstanceID = GetInstanceID
StaticName = 16
else
DevInstanceID = Right(DevAttrNameFromSql, 1)
StaticName = 15
End If
DevAttrNameLen = Len(DevAttrNameFromSql) - StaticName
DevLabelName = Left(DevAttrNameFromSql, DevAttrNameLen)
Context.LogMessage "DevInstanceID = " & DevInstanceID
Context.LogMessage DevLabelName & " DevLabelName"
oFile1 = sFolder & DisplayName & "_inst_" & DevInstanceID & "-Crit-1.txt"
oFile2 = sFolder & DisplayName & "_inst_" & DevInstanceID & "-Crit-2.txt"
oFile3 = sFolder & DisplayName & "_inst_" & DevInstanceID & "-Crit-3.txt"
oFile4 = sFolder & DisplayName & "_inst_" & DevInstanceID & "-Crit-4.txt"
hrStorageSizeOID = "1.3.6.1.2.1.25.2.3.1.5." & DevInstanceID
hrStorageUsedOID = "1.3.6.1.2.1.25.2.3.1.6." & DevInstanceID
hrStorageAllocationUnitsOID = "1.3.6.1.2.1.25.2.3.1.4." & DevInstanceID
'Get disk information and calculate
Set objSNMPResult = objSNMPRqst.Get(hrStorageAllocationUnitsOID)
devDiskAllocResult = objSNMPResult.GetPayload
Set objSNMPREsult = objSNMPRqst.Get(hrStorageSizeOID)
devDiskSizeResult = objSNMPResult.GetPayload
devDiskSizeGB = FormatNumber(((devDiskSizeResult * devDiskAllocResult) / CONVERSION_FACTOR), 1)
Set objSNMPREsult = objSNMPRqst.Get(hrStorageUsedOID)
devDiskUsedResult = objSNMPResult.GetPayload
if devDiskUsedResult > 2000 then
devDiskUsedGB = FormatNumber(((devDiskUsedResult * devDiskAllocResult) / CONVERSION_FACTOR), 1)
devUsedPercentMath = ((devDiskUsedGB / devDiskSizeGB) * 100)
drvUsedPercentFinal = FormatNumber(devUsedPercentMath, 2)
Context.LogMessage drvUsedPercentFinal & "% used disk out of total GB: " & devDiskSizeGB
Else
drvUsedPercentFinal = 1
End if
OutputText = "Disk " & DevLabelName & " has " & drvUsedPercentFinal & "%" & " used Diskspace (" & devDiskUsedGB & "GB out" & " of " & devDiskSizeGB & "GB" & "), Alarm threshold is " & DevAttrTresholdFromSql & "%" & vbCrLf & vbCrLf & "Alarm sent on: " & LarmTid
'Reaction to disk size CRITICAL
if int(drvUsedPercentFinal) < int(DevAttrTresholdFromSql) Then
set DateFile4 = oFS.GetFile(oFile4)
If oFS.FileExists(oFile4) Then
Context.LogMessage DateDiff("M", DateFile4.DateLastModified, Now())
If DateDiff( "n", DateFile4.DateLastModified, Now()) =< 20 Then
On Error Resume Next
Context.LogMessage "Percent under critcal threshold. Waits 20 minutes before new alarms are activated"
oFS.DeleteFile oFile3
oFS.DeleteFile oFile2
oFS.DeleteFile oFile1
Context.SetResult 0, " "
Else
On Error Resume Next
Context.LogMessage "Disk under critical threshold, 20 mins has passed. Deleting files 1-4 to reset alarm"
oFS.DeleteFile oFile4
oFS.DeleteFile oFile3
oFS.DeleteFile oFile2
oFS.DeleteFile oFile1
Context.SetResult 0, " "
End if
else
On Error Resume Next
Context.LogMessage "Disk under critical threshold"
oFS.DeleteFile oFile4
oFS.DeleteFile oFile3
oFS.DeleteFile oFile2
oFS.DeleteFile oFile1
Context.SetResult 0, " "
End IF
Else
'''''''''''''''''''''''''''''''''''''''''''''''''''''''
''ingen mail på 4 timme efter 1 disklarm
''''''''''''''''''''''''''''''''''''''''''''''''''''''''
If oFS.FileExists(oFile4) Then
On Error Resume Next
set DateFile4 = oFS.GetFile(oFile4)
oFS.DeleteFile oFile3
oFS.DeleteFile oFile2
oFS.DeleteFile oFile1
If DateDiff( "n", DateFile4.DateLastModified, Now() ) >= 240 Then
Context.LogMessage "Alarm wait time passed, new mail is getting sent"
Set objEmail = CreateObject("CDO.Message")
objEmail.From = EmailFrom
objEmail.To = EmailTo
objEmail.Subject = "DiskUtilization Critical on " & DisplayName & " 4 hours passed without fixing"
objEmail.Textbody = "DiskUtilization Critical on " & DisplayName & vbCrLf & vbCr & OutputText & vbCrLf & vbCrLf & "Notes from Device:" & vbCrLf & devNote
objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 1
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = SmtpServer
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objEmail.Configuration.Fields.Update
objEmail.Send
oFS.DeleteFile oFile4
oFS.CreateTextfile(oFile4)
Context.LogMessage "recreating file #4 to reset alarm wait time"
else
Context.LogMessage "Alarm has been sent. New mail will be sent 4 hours after first alarm"
end if
Else
If oFS.FileExists(oFile3) Then
set DateFile3 = oFS.GetFile(oFile3)
If DateDiff( "n", DateFile3.DateLastModified, Now() ) > 6 Then
Context.LogMessage "Age difference above 6 minutes, creating file 1 because file #3 was too old"
On Error Resume Next
oFS.DeleteFile oFile3
oFS.DeleteFile oFile2
oFS.DeleteFile oFile1
oFS.CreateTextfile(oFile1)
else
Context.LogMessage "File 3# exists and still critical threshold. Setting monitor down"
Set objEmail = CreateObject("CDO.Message")
Context.SetResult = 1, "Disk over threshold, monitor down"
oFS.MoveFile oFile3, oFile4
end if
else
If oFS.FileExists(oFile2) Then
set DateFile2 = oFS.GetFile(oFile2)
If DateDiff( "n", DateFile2.DateLastModified, Now() ) > 5 Then
Context.LogMessage "Age difference above 6 minutes, creating file 1 because file #2 was too old"
On Error Resume Next
oFS.DeleteFile oFile2
oFS.DeleteFile oFile1
oFS.CreateTextfile(oFile1)
else
Context.LogMessage "File #2 exists, critical threshold. Created file #3"
oFS.MoveFile oFile2, oFile3
end if
else
If oFS.FileExists(oFile1) Then
set DateFile1 = oFS.GetFile(oFile1)
If DateDiff( "n", DateFile1.DateLastModified, Now() ) > 4 Then
Context.LogMessage "Age difference above 6 minutes, creating file 1 because file #1 was too old"
On Error Resume Next
oFS.DeleteFile oFile1
oFS.CreateTextfile(oFile1)
else
Context.LogMessage "File #1 exists, critical threshold. Created file #2"
oFS.MoveFile oFile1, oFile2
end if
else
Context.Logmessage "File #1 created, none existed"
oFS.CreateTextfile(oFile1)
end if
end If
END if
EnD if
End if
oRS.MoveNext
Loop
oRs.Close
oRS.Close
objDB.Close
Set oRS = Nothing
Set objDB = Nothing
Set DateFile1 = Nothing
Set DateFile2 = Nothing
Set DateFile3 = Nothing
Set DateFile4 = Nothing
Hi Robin,
This is exactly what I am looking for to use in WUG at my company. I'm very green to WUG and to writing script as well and hoping you can help me out. I put the first code to scan for the drives in to an Active Monitor and then tried to test and below is what I got.
Second: the device you are checking needs snmp working from the wug server. Have you verified that? Timeout on disktyperesult= no connection with snmp
To verify: check if performance monitors are getting data ir by using smnp walker under tools on your wug-website!
//robin
You deleted yur message, so I assume you got it working?
Was it one of those "oh s**t, how could I miss that" kind of errors? :)
Hey Robin,
Yup, did not have the SNMP running on the client server. Now I am getting this error after I test run the script.
That's not an error at all :)
Same output for me:
C:\_DiskWarning__1 attributet finns, uppdaterar
Börjar om på nästa instans
1.3.6.1.2.1.25.2.1.4DiskTypeREsult
SQL query för att kolla om fil fins: select sName from DeviceAttribute where (nDeviceID = '2819 ') and (sName like 'D:\_DiskCritical_%')
False oRS.EOF-resultat
D:\_DiskCritical_2 attributet finns, uppdaterar
SQL query för att kolla om fil fins: select sName from DeviceAttribute where (nDeviceID = '2819 ') and (sName like 'D:\_DiskWarning__%')
False oRS.EOF-resultat
D:\_DiskWarning__2 attributet finns, uppdaterar
Börjar om på nästa instans
1.3.6.1.2.1.25.2.1.7DiskTypeREsult
Ingen diskar fanns på instans 3
Börjar om på nästa instans
1.3.6.1.2.1.25.2.1.7DiskTypeREsult
Ingen diskar fanns på instans 4
Börjar om på nästa instans
1.3.6.1.2.1.25.2.1.3DiskTypeREsult
Ingen diskar fanns på instans 5
Börjar om på nästa instans
1.3.6.1.2.1.25.2.1.2DiskTypeREsult
Ingen diskar fanns på instans 6
Börjar om på nästa instans
Response packet contained the error: No Such NameDiskTypeREsult
The last line is because there is no instance 7 on your server. You have 6 disks (virtual, swap, fixed etc).
That script is the script that puts device attributes on your device. It gets which fixed disks (normal disks) belogns to waht instance and adds to your device attributes. Add the other script to another active monitor and apply to the device.
The script you posted results from only needs to be run:
1: First time when activating disk monitor
2: When a new disk is added
Hope that clears it up!
//Robin
Hi Robin,
I was able to get the second script somewhat working as well. When I run the test I get results like below here:
Checking Address=137.187.224.120
DevInstanceID = 2
C:\ DevLabelName
63.60% used disk out of total GB: 25.0
Procent under 90%. Raderar filer 1-4
DevInstanceID = 3
D:\ DevLabelName
85.59% used disk out of total GB: 220.0
Procent under 90%. Raderar filer 1-4
DevInstanceID = 2
C:\ DevLabelName
63.60% used disk out of total GB: 25.0
Procent under 80%. Raderar filer 1-4
DevInstanceID = 3
D:\ DevLabelName
85.59% used disk out of total GB: 220.0
Fil3 finns, disk over 80%, kollar ålder på fil 3
Disk över warning level, fil mindre än 3 timmar, avvaktar
Script klar!
And I see in the DiskAlarms folder with the text file nindsweb3_inst_3-Warn-3 but I am not getting any warning emails. If I understand the script correctly I should get an email for the D drive being over 80% (Warning threshold) correct?
Just incase you need to see it here is what I have for the second script:
'Sending log message to the WhatsUp Event Viewer
Context.LogMessage "Checking Address=" & Context.GetProperty("Address")
'Set the result code of the check (0=Success, 1=Error)
Context.SetResult 0, "No error"
''''''''''''''''''''''''''''''''''
'Static values etc'''''
''''''''''''''''''''''''''''''''''
CONVERSION_FACTOR = 1073741824
Set objDB = Context.GetDB
Set oRS = CreateObject("ADODB.Recordset")
AMName = Context.GetProperty("ActiveMonitorTypeName")
sysDeviceID = Context.GetProperty("DeviceID")
Set objSNMPRqst = CreateObject("CoreAsp.SnmpRqst")
Set objSNMPResult = objSNMPRqst.Initialize(sysDeviceID)
''''''''''''''''''''''''''''''''''
'''' Folder to save text files on local WUG server
''''''''''''''''''''''''''''''''''
sFolder = "C:\DiskAlarms\"
Set oFS = CreateObject( "Scripting.FileSystemObject" )
''''''''''''''''''''''''''''''''''
''''' Mail settings. Remember to check the script to which you want to use. You can also rename these if you change in the script
''''''''''''''''''''''''''''''''''
EmailFrom = "WUGalerts@ninds.nih.gov"
EmailTo = "ninds10serveradmins@ninds.nih.gov"
'Can add or remove these if you want more mail addresses in different scenarions
EmailToLime = "ninds10serveradmins@ninds.nih.gov"
SmtpServer = "mailfwd.nih.gov"
LarmTid = Now() 'Used to get the current time to send in mail
sqlGetDisplayName = "SELECT sDisplayName,sNote FROM Device WHERE nDeviceID = '" & sysDeviceID &"'"
oRS.Open sqlGetDisplayName, objDB, 3
DisplayName = oRS("sDisplayName")
devNote = oRS("sNote")
oRS.Close
On Error Resume Next
DevAttrNameStd = "%DiskCritical_%"
sqlGetAttrLabelAndInstanceID = "select sName,sValue from DeviceAttribute where (nDeviceID = '" & sysDeviceID & " ') and (sName like '" & DevAttrNameStd & "')"
oRS.Open sqlGetAttrLabelAndInstanceID, objDB, 3
''' Check Critical '''
Do Until oRS.EOF
DevAttrNameFromSql = oRS("sName")
DevAttrTresholdFromSql = ors("sValue")
GetInstanceID = Right(DevAttrNameFromSql, 2)
If isNumeric(GetInstanceID) then
DevInstanceID = GetInstanceID
StaticName = 16
else
DevInstanceID = Right(DevAttrNameFromSql, 1)
StaticName = 15
End If
DevAttrNameLen = Len(DevAttrNameFromSql) - StaticName
DevLabelName = Left(DevAttrNameFromSql, DevAttrNameLen)
Context.LogMessage "DevInstanceID = " & DevInstanceID
Context.LogMessage DevLabelName & " DevLabelName"
oFile1 = sFolder & DisplayName & "_inst_" & DevInstanceID & "-Crit-1.txt"
oFile2 = sFolder & DisplayName & "_inst_" & DevInstanceID & "-Crit-2.txt"
oFile3 = sFolder & DisplayName & "_inst_" & DevInstanceID & "-Crit-3.txt"
oFile4 = sFolder & DisplayName & "_inst_" & DevInstanceID & "-Crit-4.txt"
hrStorageSizeOID = "1.3.6.1.2.1.25.2.3.1.5." & DevInstanceID
hrStorageUsedOID = "1.3.6.1.2.1.25.2.3.1.6." & DevInstanceID
hrStorageAllocationUnitsOID = "1.3.6.1.2.1.25.2.3.1.4." & DevInstanceID
'Get disk information and calculate
Set objSNMPResult = objSNMPRqst.Get(hrStorageAllocationUnitsOID)
devDiskAllocResult = objSNMPResult.GetPayload
Set objSNMPREsult = objSNMPRqst.Get(hrStorageSizeOID)
devDiskSizeResult = objSNMPResult.GetPayload
devDiskSizeGB = FormatNumber(((devDiskSizeResult * devDiskAllocResult) / CONVERSION_FACTOR), 1)
Set objSNMPREsult = objSNMPRqst.Get(hrStorageUsedOID)
devDiskUsedResult = objSNMPResult.GetPayload
if devDiskUsedResult > 2000 then
devDiskUsedGB = FormatNumber(((devDiskUsedResult * devDiskAllocResult) / CONVERSION_FACTOR), 1)
devUsedPercentMath = ((devDiskUsedGB / devDiskSizeGB) * 100)
drvUsedPercentFinal = FormatNumber(devUsedPercentMath, 2)
Context.LogMessage drvUsedPercentFinal & "% used disk out of total GB: " & devDiskSizeGB
Else
drvUsedPercentFinal = 1
End if
'Reaction to disk size CRITICAL
''''''''''''''''''''''''''''''
''' This is output text for critical. Change if you want to. Warning outputtext further down in warning part of script
''''''''''''''''''''''''''''''
OutputText = "Disk " & DevLabelName & " has " & drvUsedPercentFinal & "%" & " used Diskspace (" & devDiskUsedGB & "GB out" & " of " & devDiskSizeGB & "GB" & "), Alarm threshold is " & DevAttrTresholdFromSql & "%" & vbCrLf & vbCrLf & "Alarm sent on: " & LarmTid
if int(drvUsedPercentFinal) < int(DevAttrTresholdFromSql) Then
set DateFile4 = oFS.GetFile(oFile4)
If oFS.FileExists(oFile4) Then
Context.LogMessage DateDiff("M", DateFile4.DateLastModified, Now())
If DateDiff( "n", DateFile4.DateLastModified, Now()) =< 20 Then
On Error Resume Next
Context.LogMessage "Procent under 90%. Fil 4 under 5 min gammel. Avvaktar"
oFS.DeleteFile oFile3
oFS.DeleteFile oFile2
oFS.DeleteFile oFile1
Context.SetResult 0, "Procent under 90%. Fil 4 under 5 min gammel. Avvaktar"
Else
On Error Resume Next
Context.LogMessage "Procent under 90%. Raderar filer 1-4"
oFS.DeleteFile oFile4
oFS.DeleteFile oFile3
oFS.DeleteFile oFile2
oFS.DeleteFile oFile1
Context.SetResult 0, "Procent under 90%. Raderar filer 1-4"
End if
else
On Error Resume Next
Context.LogMessage "Procent under 90%. Raderar filer 1-4"
oFS.DeleteFile oFile4
oFS.DeleteFile oFile3
oFS.DeleteFile oFile2
oFS.DeleteFile oFile1
Context.SetResult 0, "Procent under 90%. Raderar filer 1-4"
End IF
Else
If oFS.FileExists(oFile4) Then
Context.LogMessage "Fil 4 finns, disk over 90%, kollar ålder på fil 4"
On Error Resume Next
set DateFile4 = oFS.GetFile(oFile4)
oFS.DeleteFile oFile3
oFS.DeleteFile oFile2
oFS.DeleteFile oFile1
''''''''''''''''''''''''''''''''''
'''Change value here to say how often it should send mail while disk useage is in critical state
'''If this feature is unwanted, delete below if statement
''''''''''''''''''''''''''''''''''
If DateDiff( "n", DateFile4.DateLastModified, Now() ) >= 240 Then
Context.LogMessage "Skickar mail för fil4 har passerat 4 timmer. ÅTGÄRDA"
Set objEmail = CreateObject("CDO.Message")
objEmail.From = EmailFrom
objEmail.To = EmailTo
objEmail.Subject = "DiskUtilization Critical on " & DisplayName
objEmail.Textbody = DisplayName & vbCrLf & vbCr & OutputText & vbCrLf & vbCrLf & devNote
objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 1
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = SmtpServer
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objEmail.Configuration.Fields.Update
objEmail.Send
oFS.DeleteFile oFile4
oFS.CreateTextfile(oFile4)
Context.LogMessage "Skapar om fil 4 för att resette tid"
Context.SetResult 0, OutputText
else
Context.SetResult 0, OutputText
end if
Else
If oFS.FileExists(oFile3) Then
Context.LogMessage "Fil3 finns, disk over 90%, kollar ålder på fil 3 "
set DateFile3 = oFS.GetFile(oFile3)
If DateDiff( "n", DateFile3.DateLastModified, Now() ) > 6 Then
Context.LogMessage "Ålder skillnad över 6m, raderar filar och skapar ny fil"
On Error Resume Next
oFS.DeleteFile oFile3
oFS.DeleteFile oFile2
oFS.DeleteFile oFile1
oFS.CreateTextfile(oFile1)
else
Context.LogMessage "Ålder skillnad under 5m, Mailar samt flyttar fil till 4"
Set objEmail = CreateObject("CDO.Message")
objEmail.From = EmailFrom
objEmail.To = EmailTo
objEmail.Subject = "DiskUtilization Critical on " & DisplayName
objEmail.Textbody = "DiskUtilization Critical on " & DisplayName & vbCrLf & vbCr & OutputText & vbCrLf & vbCrLf & "Notes from Device:" & vbCrLf & devNote
objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 1
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = SmtpServer
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objEmail.Configuration.Fields.Update
objEmail.Send
oFS.MoveFile oFile3, oFile4
end if
else
If oFS.FileExists(oFile2) Then
Context.LogMessage "Fil finns, disk over 90%, kollar ålder på fil 2 "
set DateFile2 = oFS.GetFile(oFile2)
If DateDiff( "n", DateFile2.DateLastModified, Now() ) > 5 Then
Context.LogMessage "Ålder skillnad över 4m, raderar filar och skapar ny fil"
On Error Resume Next
oFS.DeleteFile oFile2
oFS.DeleteFile oFile1
oFS.CreateTextfile(oFile1)
else
Context.LogMessage "Ålder skillnad under 3m, flyttar fil från 2 till 3"
oFS.MoveFile oFile2, oFile3
end if
else
If oFS.FileExists(oFile1) Then
Context.LogMessage "Fil finns, disk over 90%, kollar ålder på fil 1 "
set DateFile1 = oFS.GetFile(oFile1)
If DateDiff( "n", DateFile1.DateLastModified, Now() ) > 4 Then
Context.LogMessage "Ålder skillnad över 4m, raderar filar och skapar ny fil"
On Error Resume Next
oFS.DeleteFile oFile1
oFS.CreateTextfile(oFile1)
else
Context.LogMessage "Ålder skillnad under 3m, flyttar fil 1 till 2 "
oFS.MoveFile oFile1, oFile2
end if
else
Context.Logmessage "skapar fil då ingen fans"
oFS.CreateTextfile(oFile1)
end if
end If
END if
EnD if
End if
oRS.MoveNext
Loop
oRs.Close
'''' Check warning ''''
DevAttrNameWarn = "%DiskWarning_%"
sqlGetAttrLabelAndInstanceID = "select sName,sValue from DeviceAttribute where (nDeviceID = '" & sysDeviceID & " ') and (sName like '" & DevAttrNameWarn & "')"
oRS.Open sqlGetAttrLabelAndInstanceID, objDB, 3
Do Until oRS.EOF
DevAttrNameFromSql = oRS("sName")
DevAttrTresholdFromSql = ors("sValue")
GetInstanceID = Right(DevAttrNameFromSql, 2)
If isNumeric(GetInstanceID) then
DevInstanceID = GetInstanceID
StaticName = 16
else
DevInstanceID = Right(DevAttrNameFromSql, 1)
StaticName = 15
End If
DevAttrNameLen = Len(DevAttrNameFromSql) - StaticName
DevLabelName = Left(DevAttrNameFromSql, DevAttrNameLen)
Context.LogMessage "DevInstanceID = " & DevInstanceID
Context.LogMessage DevLabelName & " DevLabelName"
oFile1 = sFolder & DisplayName & "_inst_" & DevInstanceID & "-Warn-1.txt"
oFile2 = sFolder & DisplayName & "_inst_" & DevInstanceID & "-Warn-2.txt"
oFile3 = sFolder & DisplayName & "_inst_" & DevInstanceID & "-Warn-3.txt"
oFile4 = sFolder & DisplayName & "_inst_" & DevInstanceID & "-Warn-4.txt"
oFileCritExist = sFolder & DisplayName & "_inst_" & DevInstanceID & "-Crit-4.txt"
hrStorageSizeOID = "1.3.6.1.2.1.25.2.3.1.5." & DevInstanceID
hrStorageUsedOID = "1.3.6.1.2.1.25.2.3.1.6." & DevInstanceID
hrStorageAllocationUnitsOID = "1.3.6.1.2.1.25.2.3.1.4." & DevInstanceID
'Get disk information and calculate
Set objSNMPResult = objSNMPRqst.Get(hrStorageAllocationUnitsOID)
devDiskAllocResult = objSNMPResult.GetPayload
Set objSNMPREsult = objSNMPRqst.Get(hrStorageSizeOID)
devDiskSizeResult = objSNMPResult.GetPayload
devDiskSizeGB = FormatNumber(((devDiskSizeResult * devDiskAllocResult) / CONVERSION_FACTOR), 1)
Set objSNMPREsult = objSNMPRqst.Get(hrStorageUsedOID)
devDiskUsedResult = objSNMPResult.GetPayload
if devDiskUsedResult > 2000 then
devDiskUsedGB = FormatNumber(((devDiskUsedResult * devDiskAllocResult) / CONVERSION_FACTOR), 1)
devUsedPercentMath = ((devDiskUsedGB / devDiskSizeGB) * 100)
drvUsedPercentFinal = FormatNumber(devUsedPercentMath, 2)
Context.LogMessage drvUsedPercentFinal & "% used disk out of total GB: " & devDiskSizeGB
else
drvUsedPercentFinal = 1
End if
''''''''''''''''''''''''''''''
''' This is output text for Warning. Change if you want to. Critical text further up in critical part
''''''''''''''''''''''''''''''
OutputText = "Disk " & DevLabelName & " has " & drvUsedPercentFinal & "%" & " used Diskspace (" & devDiskUsedGB & "GB out" & " of " & devDiskSizeGB & "GB" & "), Alarm threshold is " & DevAttrTresholdFromSql & "%" & vbCrLf & vbCrLf & "Alarm sent on: " & LarmTid
if oFS.FileExists(oFileCritExist) then
Context.Logmessage "Critical larm finns, ignorerar warning filhantering"
On Error Resume Next
oFS.DeleteFile oFile4
oFS.DeleteFile oFile3
oFS.DeleteFile oFile2
oFS.DeleteFile oFile1
Else
'Reaction to disk size Warning
if int(drvUsedPercentFinal) < int(DevAttrTresholdFromSql) Then
set DateFile4 = oFS.GetFile(oFile4)
If oFS.FileExists(oFile4) Then
Context.LogMessage DateDiff( "H", DateFile3.DateLastModified, Now()) & " Datediff värde"
If DateDiff( "H", DateFile4.DateLastModified, Now() ) =< 72 Then
On Error Resume Next
Context.LogMessage "Procent under 80%. Fil 4 under 24 timmar gammel. Avvaktar"
oFS.DeleteFile oFile3
oFS.DeleteFile oFile2
oFS.DeleteFile oFile1
Context.SetResult 0, "Procent under 80%. Fil 4 under 5 min gammel. Avvaktar"
Else
On Error Resume Next
Context.LogMessage "Procent under 80%. WarnFil4 över 24 timmar. Raderar filer 1-4"
oFS.DeleteFile oFile4
oFS.DeleteFile oFile3
oFS.DeleteFile oFile2
oFS.DeleteFile oFile1
Context.SetResult 0, "Procent under 80%. Raderar filer 1-4"
End if
else
On Error Resume Next
Context.LogMessage "Procent under 80%. Raderar filer 1-4"
oFS.DeleteFile oFile3
oFS.DeleteFile oFile2
oFS.DeleteFile oFile1
Context.SetResult 0, "Procent under 80%. Raderar filer 1-4"
End IF
Else
If oFS.FileExists(oFile4) Then
Context.LogMessage "Fil 4 finns, disk over 80%. Låter fil 4 vara kvar då larm har skickats"
Context.SetResult 0, OutputText
Else
If oFS.FileExists(oFile3) Then
Context.LogMessage "Fil3 finns, disk over 80%, kollar ålder på fil 3 "
set DateFile3 = oFS.GetFile(oFile3)
''''''''''''''''''''''''''''''''''
'''You can change value in next line to represent how long disk should stay over treshold before sending mail
''''''''''''''''''''''''''''''''''
If DateDiff( "n", DateFile3.DateLastModified, Now() ) >=180 Then
Context.LogMessage "Warning fil över 3 Timmar, skickar mail samt skapar warning fil 4"
Set objEmail = CreateObject("CDO.Message")
objEmail.From = EmailFrom
objEmail.To = EmailToLime
objEmail.Subject = "DiskUtilization Warning on " & DisplayName
objEmail.Textbody = vbCrLf & OutputText & vbCrLf & vbCrLf & "Notes from Device:" & vbCrLf & devNote
objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 1
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = SmtpServer
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objEmail.Configuration.Fields.Update
objEmail.Send
oFS.MoveFile oFile3, oFile4
Context.SetResult 0, OutputText
else
Context.LogMessage "Disk över warning level, fil mindre än 3 timmar, avvaktar"
Context.SetResult 0, OutPutText
end if
else
If oFS.FileExists(oFile2) Then
set DateFile2 = oFS.GetFile(oFile2)
If DateDiff( "n", DateFile2.DateLastModified, Now() ) > 4 Then
Context.LogMessage "Ålder skillnad över 4m, raderar filar och skapar ny fil"
On Error Resume Next
oFS.DeleteFile oFile2
oFS.DeleteFile oFile1
oFS.CreateTextfile(oFile1)
else
Context.LogMessage "Ålder skillnad under 3m, flyttar fil från 2 till 3"
oFS.MoveFile oFile2, oFile3
end if
else
If oFS.FileExists(oFile1) Then
set DateFile1 = oFS.GetFile(oFile1)
If DateDiff( "M", DateFile1.DateLastModified, Now() ) > 4 Then
Context.LogMessage "Ålder skillnad över 4m, raderar filar och skapar ny fil"
On Error Resume Next
oFS.DeleteFile oFile1
oFS.CreateTextfile(oFile1)
else
Context.LogMessage "Ålder skillnad under 3m, flyttar fil 1 till 2 "
oFS.MoveFile oFile1, oFile2
end if
else
Context.Logmessage "skapar fil då ingen fans"
oFS.CreateTextfile(oFile1)
end if
end If
END if
EnD if
End if
End if
oRS.MoveNext
Loop
oRs.Close
oRS.Close
objDB.Close
Set oRS = Nothing
Set objDB = Nothing
Set DateFile1 = Nothing
Set DateFile2 = Nothing
Set DateFile3 = Nothing
Set DateFile4 = Nothing
Context.SetREsult 0, "Script klar!"
I really appreciate your help with this!
--Tony
Hello Tony.
You will (should) get a warning mail after 180 minutes from which teh disk goes above threshold (I did it like this because backups tends to increase disk size somewaht during the backup-phase)
Also:
Disk över warning level, fil mindre än 3 timmar, avvaktar
In english:
"Disc above warning threshold, file is less than 3 hours (180 minutes from above). Waits"
I've learned from this script that I should stick to english only :) And give better information in the script. But oh well.. First scripts never the best.
Where you change time before mail is sent (warning):
''''''''''''''''''''''''''''''''''
'''You can change value in next line to represent how long disk should stay over treshold before sending mail
''''''''''''''''''''''''''''''''''
If DateDiff( "n", DateFile3.DateLastModified, Now() ) >=180 Then
"n" = minutes. "s" = seconds, "h" = hours, "m" = months.
hey Robin,
So I just changed it to be:
'''You can change value in next line to represent how long disk should stay over treshold before sending mail '''''''''''''''''''''''''''''''''' If DateDiff( "s", DateFile3.DateLastModified, Now() ) >=180 Then Context.LogMessage "Warning fil över 3 Timmar, skickar mail samt skapar warning fil 4"And still not getting any email notifications.
Do you have SMTP:
Locally on your WUG server?
Through an Exchange server?
Or through something else connecting using normal port?
In this (its 2 places in the scripts, update both)
objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 1
cdoSendUsingPickup (1)
cdoSendUsingPort (2)
cdoSendUsingExchange (3)
1 = SMTP local installed, 2 = through port and 3 = through an exchange server.
My guess for the issue ;)
Hey Robin,
We run the smtp (mailfwd.nih.gov) from our exchange server. I made the corrections within the code and still not able to get a notification. I'v obviously got something else set wrong but have not been able to resolve the issue.
Here is what I have for the code:
'Sending log message to the WhatsUp Event Viewer Context.LogMessage "Checking Address=" & Context.GetProperty("Address") 'Set the result code of the check (0=Success, 1=Error) Context.SetResult 0, "No error" 'Sending log message to the WhatsUp Event Viewer Context.LogMessage "Checking Address=" & Context.GetProperty("Address") 'Set the result code of the check (0=Success, 1=Error) Context.SetResult 0, "No error" '''''''''''''''''''''''''''''''''' 'Static values etc''''' '''''''''''''''''''''''''''''''''' CONVERSION_FACTOR = 1073741824 Set objDB = Context.GetDB Set oRS = CreateObject("ADODB.Recordset") AMName = Context.GetProperty("ActiveMonitorTypeName") sysDeviceID = Context.GetProperty("DeviceID") Set objSNMPRqst = CreateObject("CoreAsp.SnmpRqst") Set objSNMPResult = objSNMPRqst.Initialize(sysDeviceID) '''''''''''''''''''''''''''''''''' '''' Folder to save text files on local WUG server '''''''''''''''''''''''''''''''''' sFolder = "C:\DiskAlarms\" Set oFS = CreateObject( "Scripting.FileSystemObject" ) '''''''''''''''''''''''''''''''''' ''''' Mail settings. Remember to check the script to which you want to use. You can also rename these if you change in the script '''''''''''''''''''''''''''''''''' EmailFrom = "WUGalerts@ninds.nih.gov" EmailTo = "ninds10serveradmins@ninds.nih.gov" 'Can add or remove these if you want more mail addresses in different scenarions EmailToLime = "ninds10serveradmins@ninds.nih.gov" SmtpServer = "mailfwd.nih.gov" LarmTid = Now() 'Used to get the current time to send in mail sqlGetDisplayName = "SELECT sDisplayName,sNote FROM Device WHERE nDeviceID = '" & sysDeviceID &"'" oRS.Open sqlGetDisplayName, objDB, 3 DisplayName = oRS("sDisplayName") devNote = oRS("sNote") oRS.Close On Error Resume Next DevAttrNameStd = "%DiskCritical_%" sqlGetAttrLabelAndInstanceID = "select sName,sValue from DeviceAttribute where (nDeviceID = '" & sysDeviceID & " ') and (sName like '" & DevAttrNameStd & "')" oRS.Open sqlGetAttrLabelAndInstanceID, objDB, 3 ''' Check Critical ''' Do Until oRS.EOF DevAttrNameFromSql = oRS("sName") DevAttrTresholdFromSql = ors("sValue") GetInstanceID = Right(DevAttrNameFromSql, 2) If isNumeric(GetInstanceID) then DevInstanceID = GetInstanceID StaticName = 16 else DevInstanceID = Right(DevAttrNameFromSql, 1) StaticName = 15 End If DevAttrNameLen = Len(DevAttrNameFromSql) - StaticName DevLabelName = Left(DevAttrNameFromSql, DevAttrNameLen) Context.LogMessage "DevInstanceID = " & DevInstanceID Context.LogMessage DevLabelName & " DevLabelName" oFile1 = sFolder & DisplayName & "_inst_" & DevInstanceID & "-Crit-1.txt" oFile2 = sFolder & DisplayName & "_inst_" & DevInstanceID & "-Crit-2.txt" oFile3 = sFolder & DisplayName & "_inst_" & DevInstanceID & "-Crit-3.txt" oFile4 = sFolder & DisplayName & "_inst_" & DevInstanceID & "-Crit-4.txt" hrStorageSizeOID = "1.3.6.1.2.1.25.2.3.1.5." & DevInstanceID hrStorageUsedOID = "1.3.6.1.2.1.25.2.3.1.6." & DevInstanceID hrStorageAllocationUnitsOID = "1.3.6.1.2.1.25.2.3.1.4." & DevInstanceID 'Get disk information and calculate Set objSNMPResult = objSNMPRqst.Get(hrStorageAllocationUnitsOID) devDiskAllocResult = objSNMPResult.GetPayload Set objSNMPREsult = objSNMPRqst.Get(hrStorageSizeOID) devDiskSizeResult = objSNMPResult.GetPayload devDiskSizeGB = FormatNumber(((devDiskSizeResult * devDiskAllocResult) / CONVERSION_FACTOR), 1) Set objSNMPREsult = objSNMPRqst.Get(hrStorageUsedOID) devDiskUsedResult = objSNMPResult.GetPayload if devDiskUsedResult > 2000 then devDiskUsedGB = FormatNumber(((devDiskUsedResult * devDiskAllocResult) / CONVERSION_FACTOR), 1) devUsedPercentMath = ((devDiskUsedGB / devDiskSizeGB) * 100) drvUsedPercentFinal = FormatNumber(devUsedPercentMath, 2) Context.LogMessage drvUsedPercentFinal & "% used disk out of total GB: " & devDiskSizeGB Else drvUsedPercentFinal = 1 End if 'Reaction to disk size CRITICAL '''''''''''''''''''''''''''''' ''' This is output text for critical. Change if you want to. Warning outputtext further down in warning part of script '''''''''''''''''''''''''''''' OutputText = "Disk " & DevLabelName & " has " & drvUsedPercentFinal & "%" & " used Diskspace (" & devDiskUsedGB & "GB out" & " of " & devDiskSizeGB & "GB" & "), Alarm threshold is " & DevAttrTresholdFromSql & "%" & vbCrLf & vbCrLf & "Alarm sent on: " & LarmTid if int(drvUsedPercentFinal) < int(DevAttrTresholdFromSql) Then set DateFile4 = oFS.GetFile(oFile4) If oFS.FileExists(oFile4) Then Context.LogMessage DateDiff("M", DateFile4.DateLastModified, Now()) If DateDiff( "n", DateFile4.DateLastModified, Now()) =< 20 Then On Error Resume Next Context.LogMessage "Procent under 90%. Fil 4 under 5 min gammel. Avvaktar" oFS.DeleteFile oFile3 oFS.DeleteFile oFile2 oFS.DeleteFile oFile1 Context.SetResult 0, "Procent under 90%. Fil 4 under 5 min gammel. Avvaktar" Else On Error Resume Next Context.LogMessage "Procent under 90%. Raderar filer 1-4" oFS.DeleteFile oFile4 oFS.DeleteFile oFile3 oFS.DeleteFile oFile2 oFS.DeleteFile oFile1 Context.SetResult 0, "Procent under 90%. Raderar filer 1-4" End if else On Error Resume Next Context.LogMessage "Procent under 90%. Raderar filer 1-4" oFS.DeleteFile oFile4 oFS.DeleteFile oFile3 oFS.DeleteFile oFile2 oFS.DeleteFile oFile1 Context.SetResult 0, "Procent under 90%. Raderar filer 1-4" End IF Else If oFS.FileExists(oFile4) Then Context.LogMessage "Fil 4 finns, disk over 90%, kollar ålder på fil 4" On Error Resume Next set DateFile4 = oFS.GetFile(oFile4) oFS.DeleteFile oFile3 oFS.DeleteFile oFile2 oFS.DeleteFile oFile1 '''''''''''''''''''''''''''''''''' '''Change value here to say how often it should send mail while disk useage is in critical state '''If this feature is unwanted, delete below if statement '''''''''''''''''''''''''''''''''' If DateDiff( "n", DateFile4.DateLastModified, Now() ) >= 240 Then Context.LogMessage "Skickar mail för fil4 har passerat 4 timmer. ÅTGÄRDA" Set objEmail = CreateObject("CDO.Message") objEmail.From = EmailFrom objEmail.To = EmailTo objEmail.Subject = "DiskUtilization Critical on " & DisplayName objEmail.Textbody = DisplayName & vbCrLf & vbCr & OutputText & vbCrLf & vbCrLf & devNote objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 3 objEmail.Configuration.Fields.Item _ ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = SmtpServer objEmail.Configuration.Fields.Item _ ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 objEmail.Configuration.Fields.Update objEmail.Send oFS.DeleteFile oFile4 oFS.CreateTextfile(oFile4) Context.LogMessage "Skapar om fil 4 för att resette tid" Context.SetResult 0, OutputText else Context.SetResult 0, OutputText end if Else If oFS.FileExists(oFile3) Then Context.LogMessage "Fil3 finns, disk over 90%, kollar ålder på fil 3 " set DateFile3 = oFS.GetFile(oFile3) If DateDiff( "n", DateFile3.DateLastModified, Now() ) > 6 Then Context.LogMessage "Ålder skillnad över 6m, raderar filar och skapar ny fil" On Error Resume Next oFS.DeleteFile oFile3 oFS.DeleteFile oFile2 oFS.DeleteFile oFile1 oFS.CreateTextfile(oFile1) else Context.LogMessage "Ålder skillnad under 5m, Mailar samt flyttar fil till 4" Set objEmail = CreateObject("CDO.Message") objEmail.From = EmailFrom objEmail.To = EmailTo objEmail.Subject = "DiskUtilization Critical on " & DisplayName objEmail.Textbody = "DiskUtilization Critical on " & DisplayName & vbCrLf & vbCr & OutputText & vbCrLf & vbCrLf & "Notes from Device:" & vbCrLf & devNote objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 1 objEmail.Configuration.Fields.Item _ ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = SmtpServer objEmail.Configuration.Fields.Item _ ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 objEmail.Configuration.Fields.Update objEmail.Send oFS.MoveFile oFile3, oFile4 end if else If oFS.FileExists(oFile2) Then Context.LogMessage "Fil finns, disk over 90%, kollar ålder på fil 2 " set DateFile2 = oFS.GetFile(oFile2) If DateDiff( "n", DateFile2.DateLastModified, Now() ) > 5 Then Context.LogMessage "Ålder skillnad över 4m, raderar filar och skapar ny fil" On Error Resume Next oFS.DeleteFile oFile2 oFS.DeleteFile oFile1 oFS.CreateTextfile(oFile1) else Context.LogMessage "Ålder skillnad under 3m, flyttar fil från 2 till 3" oFS.MoveFile oFile2, oFile3 end if else If oFS.FileExists(oFile1) Then Context.LogMessage "Fil finns, disk over 90%, kollar ålder på fil 1 " set DateFile1 = oFS.GetFile(oFile1) If DateDiff( "n", DateFile1.DateLastModified, Now() ) > 4 Then Context.LogMessage "Ålder skillnad över 4m, raderar filar och skapar ny fil" On Error Resume Next oFS.DeleteFile oFile1 oFS.CreateTextfile(oFile1) else Context.LogMessage "Ålder skillnad under 3m, flyttar fil 1 till 2 " oFS.MoveFile oFile1, oFile2 end if else Context.Logmessage "skapar fil då ingen fans" oFS.CreateTextfile(oFile1) end if end If END if EnD if End if oRS.MoveNext Loop oRs.Close '''' Check warning '''' DevAttrNameWarn = "%DiskWarning_%" sqlGetAttrLabelAndInstanceID = "select sName,sValue from DeviceAttribute where (nDeviceID = '" & sysDeviceID & " ') and (sName like '" & DevAttrNameWarn & "')" oRS.Open sqlGetAttrLabelAndInstanceID, objDB, 3 Do Until oRS.EOF DevAttrNameFromSql = oRS("sName") DevAttrTresholdFromSql = ors("sValue") GetInstanceID = Right(DevAttrNameFromSql, 2) If isNumeric(GetInstanceID) then DevInstanceID = GetInstanceID StaticName = 16 else DevInstanceID = Right(DevAttrNameFromSql, 1) StaticName = 15 End If DevAttrNameLen = Len(DevAttrNameFromSql) - StaticName DevLabelName = Left(DevAttrNameFromSql, DevAttrNameLen) Context.LogMessage "DevInstanceID = " & DevInstanceID Context.LogMessage DevLabelName & " DevLabelName" oFile1 = sFolder & DisplayName & "_inst_" & DevInstanceID & "-Warn-1.txt" oFile2 = sFolder & DisplayName & "_inst_" & DevInstanceID & "-Warn-2.txt" oFile3 = sFolder & DisplayName & "_inst_" & DevInstanceID & "-Warn-3.txt" oFile4 = sFolder & DisplayName & "_inst_" & DevInstanceID & "-Warn-4.txt" oFileCritExist = sFolder & DisplayName & "_inst_" & DevInstanceID & "-Crit-4.txt" hrStorageSizeOID = "1.3.6.1.2.1.25.2.3.1.5." & DevInstanceID hrStorageUsedOID = "1.3.6.1.2.1.25.2.3.1.6." & DevInstanceID hrStorageAllocationUnitsOID = "1.3.6.1.2.1.25.2.3.1.4." & DevInstanceID 'Get disk information and calculate Set objSNMPResult = objSNMPRqst.Get(hrStorageAllocationUnitsOID) devDiskAllocResult = objSNMPResult.GetPayload Set objSNMPREsult = objSNMPRqst.Get(hrStorageSizeOID) devDiskSizeResult = objSNMPResult.GetPayload devDiskSizeGB = FormatNumber(((devDiskSizeResult * devDiskAllocResult) / CONVERSION_FACTOR), 1) Set objSNMPREsult = objSNMPRqst.Get(hrStorageUsedOID) devDiskUsedResult = objSNMPResult.GetPayload if devDiskUsedResult > 2000 then devDiskUsedGB = FormatNumber(((devDiskUsedResult * devDiskAllocResult) / CONVERSION_FACTOR), 1) devUsedPercentMath = ((devDiskUsedGB / devDiskSizeGB) * 100) drvUsedPercentFinal = FormatNumber(devUsedPercentMath, 2) Context.LogMessage drvUsedPercentFinal & "% used disk out of total GB: " & devDiskSizeGB else drvUsedPercentFinal = 1 End if '''''''''''''''''''''''''''''' ''' This is output text for Warning. Change if you want to. Critical text further up in critical part '''''''''''''''''''''''''''''' OutputText = "Disk " & DevLabelName & " has " & drvUsedPercentFinal & "%" & " used Diskspace (" & devDiskUsedGB & "GB out" & " of " & devDiskSizeGB & "GB" & "), Alarm threshold is " & DevAttrTresholdFromSql & "%" & vbCrLf & vbCrLf & "Alarm sent on: " & LarmTid if oFS.FileExists(oFileCritExist) then Context.Logmessage "Critical larm finns, ignorerar warning filhantering" On Error Resume Next oFS.DeleteFile oFile4 oFS.DeleteFile oFile3 oFS.DeleteFile oFile2 oFS.DeleteFile oFile1 Else 'Reaction to disk size Warning if int(drvUsedPercentFinal) < int(DevAttrTresholdFromSql) Then set DateFile4 = oFS.GetFile(oFile4) If oFS.FileExists(oFile4) Then Context.LogMessage DateDiff( "H", DateFile3.DateLastModified, Now()) & " Datediff värde" If DateDiff( "H", DateFile4.DateLastModified, Now() ) =< 72 Then On Error Resume Next Context.LogMessage "Procent under 80%. Fil 4 under 24 timmar gammel. Avvaktar" oFS.DeleteFile oFile3 oFS.DeleteFile oFile2 oFS.DeleteFile oFile1 Context.SetResult 0, "Procent under 80%. Fil 4 under 5 min gammel. Avvaktar" Else On Error Resume Next Context.LogMessage "Procent under 80%. WarnFil4 över 24 timmar. Raderar filer 1-4" oFS.DeleteFile oFile4 oFS.DeleteFile oFile3 oFS.DeleteFile oFile2 oFS.DeleteFile oFile1 Context.SetResult 0, "Procent under 80%. Raderar filer 1-4" End if else On Error Resume Next Context.LogMessage "Procent under 80%. Raderar filer 1-4" oFS.DeleteFile oFile3 oFS.DeleteFile oFile2 oFS.DeleteFile oFile1 Context.SetResult 0, "Procent under 80%. Raderar filer 1-4" End IF Else If oFS.FileExists(oFile4) Then Context.LogMessage "Fil 4 finns, disk over 80%. Låter fil 4 vara kvar då larm har skickats" Context.SetResult 0, OutputText Else If oFS.FileExists(oFile3) Then Context.LogMessage "Fil3 finns, disk over 80%, kollar ålder på fil 3 " set DateFile3 = oFS.GetFile(oFile3) '''''''''''''''''''''''''''''''''' '''You can change value in next line to represent how long disk should stay over treshold before sending mail '''''''''''''''''''''''''''''''''' If DateDiff( "s", DateFile3.DateLastModified, Now() ) >=180 Then Context.LogMessage "Warning fil över 3 Timmar, skickar mail samt skapar warning fil 4" Set objEmail = CreateObject("CDO.Message") objEmail.From = EmailFrom objEmail.To = EmailToLime objEmail.Subject = "DiskUtilization Warning on " & DisplayName objEmail.Textbody = vbCrLf & OutputText & vbCrLf & vbCrLf & "Notes from Device:" & vbCrLf & devNote objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 3 objEmail.Configuration.Fields.Item _ ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = SmtpServer objEmail.Configuration.Fields.Item _ ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 objEmail.Configuration.Fields.Update objEmail.Send oFS.MoveFile oFile3, oFile4 Context.SetResult 0, OutputText else Context.LogMessage "Disk över warning level, fil mindre än 3 timmar, avvaktar" Context.SetResult 0, OutPutText end if else If oFS.FileExists(oFile2) Then set DateFile2 = oFS.GetFile(oFile2) If DateDiff( "n", DateFile2.DateLastModified, Now() ) > 4 Then Context.LogMessage "Ålder skillnad över 4m, raderar filar och skapar ny fil" On Error Resume Next oFS.DeleteFile oFile2 oFS.DeleteFile oFile1 oFS.CreateTextfile(oFile1) else Context.LogMessage "Ålder skillnad under 3m, flyttar fil från 2 till 3" oFS.MoveFile oFile2, oFile3 end if else If oFS.FileExists(oFile1) Then set DateFile1 = oFS.GetFile(oFile1) If DateDiff( "M", DateFile1.DateLastModified, Now() ) > 4 Then Context.LogMessage "Ålder skillnad över 4m, raderar filar och skapar ny fil" On Error Resume Next oFS.DeleteFile oFile1 oFS.CreateTextfile(oFile1) else Context.LogMessage "Ålder skillnad under 3m, flyttar fil 1 till 2 " oFS.MoveFile oFile1, oFile2 end if else Context.Logmessage "skapar fil då ingen fans" oFS.CreateTextfile(oFile1) end if end If END if EnD if End if End if oRS.MoveNext Loop oRs.Close oRS.Close objDB.Close Set oRS = Nothing Set objDB = Nothing Set DateFile1 = Nothing Set DateFile2 = Nothing Set DateFile3 = Nothing Set DateFile4 = Nothing Context.SetREsult 0, "Script klar!"Hi Robin, hope you're well, I've been running your script you kindly created for me for some time and all is fine.
However I have noticed I am unable to display "devices completely down" using a dynamic group or a dash board display as it seems the Disk Utilisation Active monitor never goes down even when the server is unavailable. Have you experienced this and do you know how I might resolve it? Your help would be appreciated.
Tony: Have you tried value "2" instead of 3?
Graeme: Ye, that might be a problem. First solution I can think of: Using critical monitors. Take "ping" (or whatever you use to count server down) and make it critical. If ping goes down, the whole device is considered down and will not poll anything but ping untill ping answers again (if I understood it correctly).
Sorry Robin, I've tried that, the other monitors report as unknown when the critial monitor is down so the devicde is still not completly down. Any other ideas?
Is there a way for the script to detect if what ever is used for counting as the server being down (e.g. Ping) and then mark its self as down?
Hmm. I could make a part into the script that will run the script, then set the montior as "down" even tho it succesfully ran, but only when the device has a "worst state" of something that means its down.
For us, we've only added "down atleast 20 min", else we got default states.
The states: 0 = unknown, 1,2,3 = down (down, down 2 and down 5 min), 4 = maintenance, 5 = up, 6 = up atleast 5 min. and finally our custom, 10 = down atleast 20 min.
I make it so the script checks if the device is in any of those states. if any monitor is down, the diskutilization will also be "down". I cant make it so it checks if every monitor is down, because diskutilization will not be down.. So diskutilization will also go down as long as any other monitor is down.
Does this sound like a solution?
"Is there a way for the script to detect if what ever is used for counting as the server being down (e.g. Ping) and then mark its self as down? "
After some searching I found how this can be done.
I can make so the script will be considered down on 2 scenarioes (Whichever you want):
1: If the active monitor type which is set to critical monitor (main 1) is down, diskutilization is down. This requires the most work
2: If any monitor is down, the diskutilization is also down. This is quick to fix
In either way, the script will continue to work as normal (although, it will not poll if critical monitor is down due to the nature of critical monitor...)
Option 1 sounds good to me, we don't use critical monitors yet but even if we were too this option will still work for us.
I have attached the script I'm currently using for reference, if you can base the changes on this one that would be great.
Thanks
Attachments
Just to make it clear, in option 1, the script will NOT go down unless there is a monitor which is considered critical monitor and that critical monitor is down.
If those criterias is not met, the diskutilization monitor will not be considered down.
I can also make it go down if Ping is down (regardless of critical monitor). This erquires ping on the device for it to work (else the monitor will not go down).
Yes sounds great, a critical monitor or ping down to bring the diskutilization down.
Here the script is :)
I've tested it quickly, so please test it properly.
Like: have ping down. Does disc check monitor go down?
Have another monitor set as critical. make that monitor go down. Does this script go down then?
Does it go up again?
Hope its works!
//Robin
Attachments
Hi Robin,
Unfortunatly it doesn't seem to work.
I have tested both ping going down and a critcal monitor and the diskspace monitor doesn't go down. with regards to the critical monitor going down, the status of all other non-critical monitors inclusding the disk utilisation changes to unknown. not sure if that makes a difference.
test results details with ping down are below.
DevInstanceID = 2
C:\ DevLabelName
0.00% used disk out of total GB:
Disk under critical threshold
DevInstanceID = 4
E:\ DevLabelName
0.00% used disk out of total GB:
0
Percent under critcal threshold. Waits 20 minutes before new alarms are activated
DevInstanceID = 5
L:\ DevLabelName
0.00% used disk out of total GB:
Disk under critical threshold
DevInstanceID = 6
P:\ DevLabelName
0.00% used disk out of total GB:
Disk under critical threshold
False ORS result
EOF not reached, records presents
Diskcheck ready!
Tested this one. This is working for me :)
Attachments
This one works better.
When ping goes down, so too does the disk monitor, but if a critical monitor goes down (includig ping as a critical monitor) all other monitors have a state of "unknown", and devices competely down doesn't work. May be what I'm using to detect devices completely down needs changing instead. This is using the dashboard addin and a dynamic group.
yeah, I cant help you with that. Or...
EDIT! Edited in some spaces that got formatted away...
If you dont have any "down" states that's custom, you can use this device group:
SELECT * FROM Device
where nBestStateID not between 4 and 6
This returns all devices that's got a state which is not 4,5 or 6 (maintence, up, up atleast 5 min)
Hi Robin, is it possible to have a "resolved" email sent when a disk goes back under its threshold?
This is most useful for servers which continually fluctuate between their thresholds or when other admins are actioning the alerts you can easily tell there is a need to investigate the issue or not.
Oh, this is the version of script I am running
Attachments
Here ya are!
Notice: If a disk goes above 90%, goes a few minutes and sends an email, it will not send a new email or reactivate the check before it has passed 20 minutes from the mail was sent. So it can go up and down for 20 minutes without restarting alarm sequence. After 20 minutes from mail was sent, it can start sending mail again.
For warning mail this is 5 days
So what the modified version attached does: After critical is sent, it will not do any action for 20 minutes (script runs, but wont reset etc). After 20 minutes, if threshold is below critical, a mail will be sent and alarm sequence will reset to start.
Do you want this feature for warning mail aswell? If so, when?
Having it on all the time would potentially cause alot of alarms for devices pending at the threshold value.
//Robin
Attachments
That was quick!
Works a treat, no need for warnings as we don't currenty use these.
Thank you so much for this.
Would you like to comment?
You must be a member. Sign In if you are already a member.