Posts tagged ‘site down alert’

Remote Site Monitoring Alert

On occasion there may be a need to be notified if a remote server is off-line due to an Internet outage, router issue, power outage, or server down.  There are many excellent services that will monitor and alert you, but most are intended for multi-site and/or multi-server configurations and require a monthly fee.  You might just want to monitor a single site and be notified if it fails.

I had this situation and therefore decided to write a simple script to accomplish the task.  I am not a programmer so I am sure this could be improved upon, but it works.  Feel free to add suggestions or alternatives in the comments section, I am sure we would all be interested.

Basically there is a batch file that makes use of a free little utility called http-ping by www.CoreTechnologies.com which runs every ‘X’ minutes using a scheduled task and verifies if the site is accessible.  If not, a simple VBS script sends an e-mail alert.

Http-ping does need to be able to access an http or https server, which could be a web server, Exchange (OWA), a router management page, or one of many other possibilities.

To configure simply create a folder such as C:\SiteMonitor and place in it; the batch and VBS script below, and http-ping .  You will have to download http-ping from http://www.coretechnologies.com/products/http-ping/

Batch file:

@echo off
:: Enter the directory location (e.g. C:\SiteMonitor\)
Set Directory=C:\SiteMonitor
:: Enter the address of the site to ping (e.e. 123.123.123.123/Exchange:443 or server.domain.com/Exchange:443)
:: (The first example should be used if you need to know if the public IP has changed)
Set Site=123.123.123.123/Exchange:443
::
If Exist %Directory%\PingResult.txt Del %Directory%\PingResult.txt
%Directory%\http-ping.exe %Site% >> %Directory%\PingResult.txt
findstr /M "Reply" %Directory%\PingResult.txt
If %errorlevel%==1 GoTo EMAIL
GoTo END
:EMAIL
cscript %Directory%\SendAlert.vbs
:END

VBS script:

' VBS script to send an alert via e-mail
Dim SMTPserver, Sender, Recipient, Subject
' Set client specific variables
SMTPserver = "smtp.ISPname.abc"
Sender = "alert@SomeDomain.abc"
Recipient = "me@MyDomain.abc"
Subject = "Alert off-line"
Message = "An automated script has determined the server at is currently off-line."
' Send E-mail
       set objMessage = CreateObject("CDO.Message")
       objMessage.Subject = Subject
       objMessage.Sender = Sender
       objMessage.To = Recipient
       objMessage.TextBody = Message
       objMessage.Configuration.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = SMTPserver
       objMessage.Configuration.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
       objMessage.Configuration.Fields.Update
       objMessage.Send
       set objMessage = Nothing

Customize scripts:

When complete save the batch file as something similar to SiteMonitor.bat.  In the batch file you need to set two variables; the “Directory” where you saved the files, and the “Site” htpp-ping is to test.  The site can be a FQDN or an IP, and needs to point to a server  or router.  In some cases you need to add the port number. Some examples include:

http://www.mysite.abc
remote.domain.abc:443
router1.DDNSservice.abc:8080  (router)
remote.domain.abc/OWA   (Exchange port 80)
123.123.123.123/Exchange:443

In my case the site I wanted to monitor had a dynamic IP.  I needed to be alerted if the public IP changed due to a service used by the site that would not work with a DDNS service.  Therefore I used the last example above.

The VBS script needs to be saved as SendAlert.vbs or change the name used within the batch file to match.  In the VBS script you need to set the following 5 variables as per the examples in the script; SMTPserver, Sender, Recipient, Subject, Message.

Schedule:

Finally, you need to schedule a task to run the batch file every half hour (or your time frame).   The following is an example as to how to do so with Vista/Server 2008 and newer.  Similar can be done under Control Panel, Scheduled Task in XP/Server 2003 and earlier.

Open the Task scheduler under Control Panel / Administrative tools, click on Task Schedule Library, and on the right select Create a Basic Task.  Assign the task a name and you can enter a description if you like.  Make sure you also select “Run whether the user is logged on or not”.

image

Configure the “Trigger” options as per the following image:

image

In the “Actions” pane choose to start a program, and point to your batch file:

image

You can then complete the wizard accepting defaults.  Your monitoring service should now be complete.  If you want to test, change the “Site” variable in the batch file to a non existent IP or FQDN, and you should get an alert the next time it runs.  Note if troubleshooting the results of the last http-ping are recorder in the directory you created as a text file named PingResult.txt

Tag Cloud