Return status of WebPage in Coldfusion using cfhtt





6
Date Submitted Sun. Aug. 27th, 2006 11:03 AM
Revision 1 of 1
Beginner cf_ernie
Tags cfhttp | ColdFusion
Comments 0 comments
Scriptname: WhatsUpCF.cfm
Author: Ernest Breau Jr.
StartDate: 08/02/2006
EndDate: 08/02/2006
Description: This script returns the status of a web page
Dependancies: CFHTTP

Usage:
cf_WhatsUpCF
url="http://#qry_detail.DomainName#"
timeout="1"
SendMail="yes"
MailTo=""
MailFrom=""
MailServer="localhost"
var="WhatsUpCF"

<!----------------------------------------------------------------------------------------------

                Scriptname: WhatsUpCF.cfm
                    Author: Ernest Breau Jr.
             StartDate: 08/02/2006
                   EndDate: 08/02/2006
           Description: This script returns the status of a web page
          Dependancies: CFHTTP
          
                 Usage:
                    <cf_WhatsUpCF
                        url="http://#qry_detail.DomainName#"
                            timeout="1"
                            SendMail="yes"
                            MailTo=""
                            MailFrom=""
                            MailServer="localhost"
                            var="WhatsUpCF">

          
   <cfswitch expression="#WhatsUpCF.Response#">
    <cfcase value="UP">
         <td align="center" bgcolor="green"><span style="font-family: helvetica; font-size: 10px; color: white;">UP</span></td>
        </cfcase>
    <cfcase value="DOWN">
         <td align="center" bgcolor="red"><span style="font-family: helvetica; font-size: 10px; color: white;">DOWN</span></td>
        </cfcase>
    <cfcase value="403">
         <td align="center" bgcolor="efefef"><span style="font-family: helvetica; font-size: 10px; color: black;">403</span></td>
        </cfcase>
   </cfswitch>

           Changes:
                            08/02/2006 ... Added support for cfmail          

         Wish List:
                            PRIORITY    DESCRIPTION
                                        Medium    Put wish list items here
                                                                                                                   
----------------------------------------------------------------------------------------------->

<cfparam name="attributes.url" default="">
<cfparam name="attributes.timeout" default="10">
<cfparam name="attributes.var" default="WhatsUpCF">
<cfparam name="attributes.SendMail" default="no">
<cfparam name="attributes.MailServer" default="192.168.0.33">
<cfparam name="attributes.MailTo" default="8605529719@messaging.sprintpcs.com, ernest.breau@gmail.com">
<cfparam name="attributes.MailFrom" default="leads@webcopilot.com">


<cfhttp method="get"
        url="#attributes.url#"
            timeout="#attributes.timeout#">

</cfhttp>
<cfset sendMail="no">
<cfset 'caller.#attributes.var#.details' = cfhttp>

<cfif ParameterExists(cfhttp.ResponseHeader.Status_Code)>
<cfswitch expression="#cfhttp.ResponseHeader.Status_Code#">
 <cfcase value="200">
  <cfset 'caller.#attributes.var#.Response' = "UP">
 </cfcase>
 <cfcase value="403">
  <cfset 'caller.#attributes.var#.Response' = "403">
  <cfset sendMail="yes">
 </cfcase>

 <cfdefaultcase>
  <cfset 'caller.#attributes.var#.Response' = "DOWN">
  <cfset sendMail="yes">
 </cfdefaultcase>
</cfswitch>
<cfelse>
   <cfset 'caller.#attributes.var#.Response' = "DOWN">
   <cfset sendMail="yes">
</cfif>

<cfif SendMail eq "yes" and attributes.sendMail eq "yes" and len(attributes.mailServer) gte 4>
 <cfmail server="#attributes.MailServer#"
         from="#attributes.MailFrom#"
         to="#attributes.MailTo#"
                 subject="#attributes.URL# is DOWN on #Now()#" type="HTML">

 #attributes.url# is DOWN on #Now()#<br>
 ------------------------------------<br>
 <cfdump var="#cfhttp#">
 </cfmail>
</cfif>
       
 

Ernest Breau

Comments

There are currently no comments for this snippet.

Voting