Question

I need some help with creating a simple site status (uptime/downtime) monitor script in ColdFusion.

My guess it can be done using cfschedule, but I am not knowledgeable with that so I would really appreciate any help.

Basically I would like the script to check if an application on my site (http://www.mysite.com/application) is accessible or not 60 minutes. If the application is down in that 60 minutes, then I am sent an e-mail to email@mysite.com.

Can anybody please help me with this? I am using ColdFusion 7.

Was it helpful?

Solution

Remember that checking your site/application using a script on the same server may not do much good. After all, if the server or CF is down then your script will fail to run in any case.

Be that as it may the easiest thing is to create some sort of page on your application that returns something you can check - like an XML packet or simply the word "ok" if you like. In some cases you might run a DB query as well - since DB's are at the top of the list for likely culprits when you have trouble. So for example you might do something like:

<cfsetting enablecfoutputonly="yes"/>
<cfquery name="checkQuery" datasource="myDSN">
    SELECT getDate() AS myDate
</cfquery>
<cfoutput>OK</cfoutput>

And save the page as "test.cfm" in your application. You might do other things as well.

Then, in a CFM page that is NOT a part of your application - and preferably on a different server altogether - you would create a script that hits your test.cfm page and looks for return of "OK". Anything else would be a problem and you could log or send an email or whatever. That code might look like this.

<cfhttp 
    url="http://www.mysite.com/myapplication/test.cfm" 
    timeout="10">
</cfhttp>

<cfif trim(cfhttp.filecontent) IS NOT "OK">

    send an email or log or whatever action you want to take to handle the exception.

</cfif>

Hope this helps :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top