I use three scripts to confirm that a site is responding.
Script 1 runs at 0,5,10...,55 minutes on the hour.
Script 1 sets things up for script 2.
Script 2 sets things up for script 3.
Here is script 1: It removes a tag file.
----------------
On Error Resume Next
Set fs = CreateObject("Scripting.FileSystemObject")
fs.DeleteFile("c:\_myserver_myport.txt")
set fs = Nothing
-------------
Script 2 fetches the HTML on
http://myserver:myport
When the site responds or if the page renders in less than 12 seconds
a tag file, C:\myserver_myport.txt, is created.
When the site is not responding or is responding slowly the tag file
is not created.
Script 2 runs on 1,6,11,...56 on the hour.
----
dim oHTTP, bRespReceived, iTimeout, httpStatus, t
On Error Resume Next
''Global Variables
bRespReceived = False
iTimeout = 0
t = now
URL = "http://myserver:myport"
upDown = "Down"
'Subs and Functions
Sub RespReceived
If oHTTP.readystate = 4 Then
bRespReceived = True
End If
End Sub
Function TimedOut
Set oHTTP = WScript.CreateObject("Microsoft.XMLHTTP")
oHTTP.onreadystatechange = GetRef("RespReceived")
oHTTP.open "GET", URL, False
oHTTP.send
upDown = "Up"
httpStatus = False
Do while bRespReceived = False
iTimeout = iTimeout + 1
if datediff("s",t,now) > 12 then
httpStatus = True
oHTTP.abort
on error goto 0
exit Do
end if
Loop
TimedOut = httpStatus
End Function
'Main
Set fs = CreateObject("Scripting.FileSystemObject")
If false = TimedOut() And upDown = "Up" Then
set file = fs.OpenTextFile("c:\_myserver_myport.txt", 2, "true")
file.close()
Else
'Do Nothing
end if
Set fs = Nothing
------------
Script three runs at 2,7,9,... 57 on the hour.
It checks for the tag file and when it does not exist, it sends an
email message to stake holders.
-----------
Sub Notify()
Set msg = CreateObject("CDO.Message")
msg.Subject = "http://myserver:myport is timing out or is down"
msg.From = "gimme_this_gimme_that@xxxxxx"
msg.To = "gimme_this_gimme_that@xxxxxx"
msg.TextBody = "This message was sent from an automated script."
msg.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/
configuration/sendusing") = 2
msg.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/
configuration/smtpserver") = "gimmes_smtpserver"
msg.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/
configuration/smtpserverport") = 25
msg.Configuration.Fields.Update
msg.Send
End Sub
On Error Resume Next
Set fs = CreateObject("Scripting.FileSystemObject")
If fs.FileExists("C:\_myserver_myport.txt") Then
'' Do Nothing
Else
Notify()
End If
Set fs = Nothing
---
This is a barebones implementation. If you want take these scripts to
the next level - where you examine the HTML page for specific text,
you would add logic to fetch the HTML and parse it. Then after that
you could modify the script so that response times get persisted to a
database, or whatever.
It's a little tricky setting things up with Task Scheduler - but if
you read my recent posts on this news group you'll find tips on how
to do it.