strComputer = "Calvin"
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colFiles = objWMIService.ExecQuery _
("Select * from CIM_Datafile Where Name = '\\Downtime_eMAR\\eMAR_ADMINISTRATION_REPORT'")
For Each objFile in colFiles
strOriginalTimestamp = objFile.LastModified
Next
Wscript.Echo "Monitoring eMAR_ADMINISTRATION_REPORT file: " & Now
Wscript.Echo
Do While True
Wscript.Sleep 1800000
Set colFiles = objWMIService.ExecQuery _
("Select * from CIM_Datafile Where Name = 'D:\\Downtime_eMAR\\eMAR_ADMINISTRATION_REPORT'")
For Each objFile in colFiles
strLatestTimestamp = objFile.LastModified
Next
If strLatestTimestamp <> strOriginalTimestamp Then
strOriginalTimestamp = strLatestTimeStamp
Else
Set objEmail = CreateObject("CDO.Message")
objEmail.From = "emarbackup@xyz.local"
objEmail.To = "jc@xyz.com, networkadmins@xyz.com,"
objEmail.Subject = "Testing....testing...testing...eMAR_ADMINISTRATION_REPORT timestamp exceeds threshold"
objEmail.Textbody = "The eMAR_ADMINISTRATION_REPORT timestamp exceeds the alloted time threshold."
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = _
"mailbox"
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objEmail.Configuration.Fields.Update
objEmail.Send
End If
Loop
Do more with
strComputer = "Calvin"
strFirstFile = "D:\\Downtime_eMAR\\eMAR_ADMINISTRATION_REPORT"
strSecondFile = ""
strThirdFile = ""
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
iCount = 0
Do While True
'FIRST FILE - EVERY 30 MINUTES----------------------------------
Set colFiles = objWMIService.ExecQuery _
("Select * from CIM_Datafile Where Name = '"&strFirstFile&"'")
For Each objFile in colFiles
str1stTimestamp = objFile.LastModified
Next
If str1stTimestamp <> str1stOrigTimestamp Then
str1stOrigTimestamp = str1stTimeStamp
Else
SendEmail strFirstFile&" timestamp exceeds threshold.",strFirstFile&" timestamp exceeds threshold."
End If
'SECOND FILE - EVERY 30 MINUTES----------------------------------
Set colFiles = objWMIService.ExecQuery _
("Select * from CIM_Datafile Where Name = '"&strSecondFile&"'")
For Each objFile in colFiles
str2ndTimestamp = objFile.LastModified
Next
If str2ndTimestamp <> str2ndOrigTimestamp Then
str2ndOrigTimestamp = str2ndTimestamp
Else
SendEmail strSecondFile&" timestamp exceeds threshold.",strSecondFile&" timestamp exceeds threshold."
End If
'THIRD FILE ONLY EVERY 24 LOOPS - EVERY 12 HOURS----------------------------------
If iCount mod 24 = 0 then
Set colFiles = objWMIService.ExecQuery _
("Select * from CIM_Datafile Where Name = '"&strThirdFile&"'")
For Each objFile in colFiles
str3rdTimestamp = objFile.LastModified
Next
If str3rdTimestamp <> str3rdOrigTimestamp Then
str3rdOrigTimestamp = str3rdTimestamp
Else
SendEmail strThirdFile&" timestamp exceeds threshold.",strThirdFile&" timestamp exceeds threshold."
End If
End If
iCount = iCount + 1
Wscript.Sleep 1800000
Loop
Function SendEmail(strSubject,strBody)
Set objEmail = CreateObject("CDO.Message")
objEmail.From = "emarbackup@xyz.local"
objEmail.To = "jc@xyz.com, networkadmins@xyz.com,"
objEmail.Subject = strSubject
objEmail.Textbody = strBody
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = _
"mailbox"
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objEmail.Configuration.Fields.Update
objEmail.Send
End Function
Premium Content
You need an Expert Office subscription to comment.Start Free Trial