Monitoring WebSite State

chlf2008發表於2011-04-20

Const EVENT_SUCCESS=0
Const EVENT_ERROR=1
Const EVENT_WARNING=2
Const EVENT_INFORMATION=4
Const EVENT_AUDIT_SUCCESS=8
Const EVENT_AUDIT_FAILURE=16

Const ForReading = 1
Set objDictionary = CreateObject("Scripting.Dictionary")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile _
("web.txt", ForReading)

i = 0
Do Until objTextFile.AtEndOfStream
strNextLine = objTextFile.Readline
objDictionary.Add i, strNextLine
i = i + 1
loop

For Each objItem in objDictionary
strLine = objDictionary.Item(objItem)

send_request(strLine)


Next

function send_request(url)
set http_request = CreateObject( "Msxml2.XMLHTTP")
'http_request.setRequestHeader "Content-Type","text/html;charset=gb2312"
http_request.open "GET ", url, false
sub_echo=""
code="0"
fname=Replace(Replace(Replace(Replace(url,"/","_"),"","_"),":","_"),".","_")
On Error Resume Next
http_request.send(null)
If Err.Number <> 0 Then
sub_echo="Unavailable"
If Not objFSO.Fileexists(fName) Then
Call EventLogingError(url,sub_echo,code)
Set f1= objFSO.Createtextfile(fName, true)
End If
Err.Clear
Else
If http_request.statusText="OK" Then
If objFSO.Fileexists(fName) Then
sub_echo="OK"
code=http_request.Status
Call EventLogingSuccess(url,sub_echo,code)
set f2 = objFSO.getfile(fName)
f2.delete
End If
Else
sub_echo="BAD"
code=http_request.Status
If Not objFSO.Fileexists(fName) Then
Call EventLogingError(url,sub_echo,code)
Set f1= objFSO.Createtextfile(fName, true)
End If
End If
End If

set http_request=nothing
end function

Function EventLogingError(url,textstate,code)
Set objShell = CreateObject("Wscript.Shell")
objShell.LogEvent EVENT_ERROR, _
"Error: There URL OF "&url&" Current State is "&textstate&" With Return Code "&code&" !"
End Function


Function EventLogingSuccess(url,textstate,code)
Set objShell = CreateObject("Wscript.Shell")
objShell.LogEvent EVENT_SUCCESS, _
"Success: There URL OF "&url&" Current State is "&textstate&" With Return Code "&code&" !"
End Function

[@more@]

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/12262773/viewspace-1048922/,如需轉載,請註明出處,否則將追究法律責任。

相關文章