I need some help with creating an automatic timing script with ColdFusion. Every 60 minutes I would like to see if a page on one of my servers (http://www.mysite.com/ALERT.cfm) is working or not.
If the page is down when it is checked, then it will check again in 5 minutes to see if the page is back up. If it is not back up, then I am sent an e-mail to [email protected]. If it is back up, then no action is required and we start the 60 minute cycle check again.
I now understand how to do one check, but not two.
So here is the CFschedule code I am using
<cfhttp url="http://example.com/testpagetocheck.cfm" method="get" >
<cfif cfhttp.statusCode neq "200 OK">
<cfschedule action = "update"
task = "TaskName"
operation = "HTTPRequest"
url = "http://www.example.com/ALERT.cfm"
startDate = "#createdate(2012,4,01)#"
startTime = "08:00 AM"
interval = "3600"
requestTimeOut = "10">
</cfif>
So say I have 4 pages - the page I want to check to see if it is down or not (testpagetocheck.cfm), page1.cfm which has the above code, ALERT.cfm which has the cfmail to send me a message if testpagetocheck.cfm is down, and then page2.cfm has the above code again, but with an interval of "once" and a start time of 5 minutes from now.
Page1.cfm to alertMe.cfm works like a charm. I am sent a message of the page being down. Page 2.cfm to alertMe.cfm also works beautifully. It also sends me a message the page I am checking is down. But, when I try to go from page1.cfm to page 2.cfm to alertMe.cfm, it does not seem like the cfschedule on page2.cfm is running so I end up not getting any mail when the server is dowm.
Can anybody please tell me what I am doing wrong? I am using CF7
I think the logic itself is wrong.
Actually you want to do two things:
So first create a file to call it one time. That file - say - createSchedule.cfm its job is to create the schedule only. Just write the schedule creation code:
Then create the checker file checksite.cfm that will be requested every while (by the scheduled task). This file checksite.cfm should include the cfhttp call and the if check, like this:
Finally just call the file createSchedule.cfm to schedule a task to keep requesting checksite.cfm that will do cfhttp check and take an action.
If all these cfm files are running on one CFServer, then if server goes down. All of them won't work, I mean you will never get an alert. Bul will get the Alert only if error occurred on thePageYouWantToCheck.cfm or it was running on other CFServer, in this case even if CFServer goes down you should get the alert.
Now .. there are many websites that provide this service (Site Down Check). Some are paid and others are free. The best free I am using since long time is this: http://www.uptimerobot.com/ It is only free with very nice features, check it.