Cold Fusion Tips-N-Tricks
Monitoring a webserver

If you have multiple webservers (ie: development and production), you can have one webserver monitoring the other webserver and if either the webserver software or Cold Fusion goes down, to notify whomever via Email that it's down. If you have an Email address that pipes all email to a pager, you can be notified anywhere if your server goes screaming into the night.

Attached are the templates you will need to create on both the webserver being monitored and the webserver doing the monitoring.

These templates will only work if you are not using SSL (https) since Cold Fusion can't seem to read in these sites thanks to a Microsoft bug.

Create a directory called "WebserverTests" or whatever you desire (but be sure to change it in the code) on both webservers and place everything in it. Once you can get it working on an on-demand basis, add an entry in the CF Administrator's Schedulers page to kick it off every 15 minutes or so from 00:15:00 to 23:45:00 every day. The program will first fetch an HTML document which will verify if the Webserver is responding. Then it will fetch a Cold Fusion program which will test to see if CF is responding.



Example HTML/CFML code:
Test.cfm, located on webserver being monitored (1 line)
=====
<CFOUTPUT>OK</CFOUTPUT>
=====

Test.html, located on webserver being monitored (1 line)
=====
OK
=====

WebserverTest.cfm, located on webserver doing the monitoring
=====
<CFSET SystemName="Production">  <!--- The system being checked --->
<CFSET EmailList="someone@somewhere.com,somepager@somewhere.com">
<CFSET cf=1>
<CFSET iis=0>

<cfhttp url="http://www.mydomain.com/WebserverTests/Test.html"
        method="GET"
        resolveurl="false"
        timeout="15"></cfhttp>
<CFOUTPUT>IIS Server: #cfhttp.filecontent#<br></CFOUTPUT>
<CFIF cfhttp.FileContent CONTAINS "OK">
  <cfhttp url="http://www.mydomain.com/WebserverTests/Test.cfm"
          method="GET"
          resolveurl="false"
          timeout="15"></cfhttp>
          <CFOUTPUT>Cold Fusion Server: #cfhttp.filecontent#<br></CFOUTPUT>
  <CFIF cfhttp.FileContent CONTAINS "OK">
    <CFSET cf=0>
  </CFIF>
<CFELSE>
  <CFSET iis=1>
</CFIF>

<CFSET mess="">
<CFIF iis EQUAL 1>
  <CFSET mess="The #SystemName# Web Server is not responding.">
<CFELSEIF cf EQUAL 1>
  <CFSET mess="The #SystemName# Cold Fusion server is not responding.">
</CFIF>

<CFIF mess NOT EQUAL "">
  <CFMAIL TO="#EmailList#"
          FROM="Cold Fusion Server"
          SUBJECT="(#SystemName#) Webserver Tests failed">#mess#

Message received:
#cfhttp.filecontent#
</CFMAIL>
  <CFOUTPUT><h1>#mess#</h1></CFOUTPUT>
<CFELSE>
  <CFOUTPUT><font face="Arial" size="6">The #SystemName# servers are responding.</font></CFOUTPUT>
</CFIF>


Return to the Cold Fusion Tips-N-Tricks topic list