Pages

Friday, July 1, 2011

How to PING a specific website and send email, if site is down

This little Vbscript allows you to ping a site and send email, if the site is down

Dim strWebsite
strWebsite = "sitename.com"
If PingSite( strWebsite ) Then
    
Else
     Set myMail=CreateObject("CDO.Message")
            myMail.Subject="SITE is Down"
            myMail.From = fromemailaddress                
            myMail.To = toemailaddress
            myMail.HTMLBody= strWebsite
            myMail.Send
            set myMail=nothing
End If


Function PingSite( myWebsite )    Dim siteStatus, objHTTP
    Set objHTTP = CreateObject( "WinHttp.WinHttpRequest.5.1" )
    objHTTP.Open "GET", "http://" & myWebsite & "/", False
    objHTTP.SetRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MyApp 1.0; Windows NT 5.1)"

    On Error Resume Next
    objHTTP.Send
    siteStatus = objHTTP.Status

    On Error Goto 0
    If siteStatus = 200 Then
        PingSite = True
    Else
        PingSite = False
    End If

    Set objHTTP = Nothing
End Function

No comments:

Post a Comment