Simple Web Site Monitoring Script – written for Outlook Web Access server monitoring


I wanted to monitor our Exchange Front-End server and OWA URL at ISA server (in DMZ). There are tons of tools/scripts available to monitor web sites. But, I usually create a script by myself to fit my own needs.

This script is really really simple and gets the job done. Once it called with a web site URL, it will check the availability. If the web site is not reachable, it will send emails to specified administrators. Hope somebody make use of this simple script.

1. Copy and Paste the following script in Notepad. Save this script as "WebSiteMon.vbs" (type with quotes in File->Save dialog)
2. Search for "<<<<<" in this script and change the values like SMTP server name, Mail TO addresses
3. Create Batch file (somename.bat) and call this script by CScript WebSiteMon.vbs http://owa.xyz.com from the batch file.
4. Schedule to run this batch file every 15 minutes
5. Any Questions…leave a reply for this blog.

‘===============================================================
‘ Name: WebSiteMon.vbs
‘ Purpose:Checks availability of the given server and sends email
‘ if the server is not reachable.
‘ Paramenters: website URL (e.g., http://www.yahoo.com)
‘ Written By: Anand Venkatachalapathy
‘ Written Date: Aug 17th 2007
‘===============================================================
Dim MonitoredSite
Dim objWinHttp, strHTMResponse, strHTMStatus
Dim sTo, sSub, sBody

‘Get the Web Site URL from Arguments array
MonitoredSite = WScript.Arguments(0)

‘Open Windows HTTP Request object
Set objWinHttp = CreateObject("WinHttp.WinHttpRequest.5.1")

‘On Error is set to Resume Next. This is important.
On Error Resume Next

‘Open (get) the website
objWinHttp.Open "GET", MonitoredSite
objWinHttp.Send
objWinHttp.WaitforResponse(10000)

‘Get the website page data
strHTMResponse = objWinHttp.ResponseText
strHTMStatus = objwinHttp.status

‘If Error is generated, website is not available
If Err.Number <> 0 Then
    sTo = "JohnDoe@xyz.com;JoeAverage@xyz.com" ‘<<<<< Change E-Mail Addresses
    sSub = MonitoredSite & " is NOT available"
    sBody = MonitoredSite & " is NOT available. This web site may be down. " & vbCrLf & vbCrLf & _
            "This alert mails will be send again in 15 minutes if the web site is not available."
    Alert_Admins sTo,sSub,sBody
    WScript.Echo MonitoredSite & " is not reachable and may be down"
End If

‘Memory wipe the objWinHttp
Set objWinHttp = Nothing

‘*-*-*-* End Of Script *-*-*-*

‘===============================================================
‘ Name:      Alert_Admins
‘ Purpose:   Send email using SMTP server.
‘ Input:     strTo – Who to send to, strSub – Subject of the message
‘             strBody – Body of the message
‘ Output:    Sends the emails to the strTO recipients
‘===============================================================
Sub Alert_Admins( strTo,strSub,strBody)

    ‘* iMsg – holds CDO.Message object
    ‘* Flds – Enumeration for CDO SMTP object properties
    ‘* iConf – holds CDO.Configuration
    Dim iMsg, Flds, iConf

    ‘* sSMTPServerName – SMTP Server Name
    Dim sSMTpServerName

    ‘* Assign your SMTP server here
    sSMTPServerName = "SMTPServer.xyz.com"   ‘<<<<< Change the SMTP server name

    ‘* Assign cdoSendUsingPort is set to 2, i.e., send using SMTP (25) port
    Const cdoSendUsingPort = 2

    ‘* Create CDO Objects and assign to variables
    Set iMsg = CreateObject("CDO.Message")
    Set iConf = CreateObject("CDO.Configuration")
    Set Flds = iConf.Fields

    ‘* Assign values to Flds class properties

    With Flds
        .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = cdoSendUsingPort
        .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = sSMTPServerName
        .Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 25 
        .Update
    End With

    ‘* Assign message properties and Send the mail
    With iMsg
        Set .Configuration = iConf
        .Fields("urn:schemas:httpmail:importance").Value = 2    ‘Setting Mail importance to High (2)
        .Fields.Update
        .To = strTo
        .From = "SystemAdministrator@xyz.com"               ‘Fake, but make-sense email FROM address
        .Sender = "Administrator@xyz.com"            ‘Return Email address
        .Subject = strSub
        .TextBody = strBody
    .Send
    End With

End Sub

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s