Forum Discussion

Will_Petersen_9's avatar
Will_Petersen_9
Icon for Nimbostratus rankNimbostratus
Aug 29, 2006

XML Redirect via iRule

Trying to determine how I can post an XML document to the client if both of the servers fail. In our case when the client sends a request we respond back with an XML document containing a url link. Based on what I read this is what i came up with but I am not sure

 

 

when HTTP_RESPONSE {

 

if { [HTTP::status] contains "404"} {

 

HTTP::payload replace 1 0

 

{

 

http://www.hireright.com

 

}

 

}

 

}

 

  • Jason_Roppolo_3's avatar
    Jason_Roppolo_3
    Historic F5 Account
    I am not sure about replacing the payload, but you can try doing something like this:

     

     

    when HTTP_RESPONSE {

     

    if { [HTTP::status] == "404" }{

     

    HTTP::respond 404 content "SorrySorry. This site is temporarily down."

     

    }

     

    }

     

     

     

    In working with deb on this in the past she noticed that it would work correctly in some instances of ie with the Show Friendly URL error Messages turned off.

     

     

    I need to look into replacing the payload for XML content

     

     

    -J

     

  • I got this to work just using when HTTP_REQUEST but when I added the if statement it didn't work. It should be checking whether a node is up and if it is down provide my XML page. Both nodes in the pool referenced are down as I took them down to test

     

     

    when HTTP_REQUEST {

     

    if { [LB::status pool $pool_mip_test member $192.168.26.88 $80] eq "down" }

     

    {HTTP::respond 200 content {

     

    xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"

     

    xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

     

     

     

     

     

     

     

     

    http://www.f5.com

     

     

     

     

     

     

     

     

    }}

     

    }

     

     

    Thanks,

     

     

    Will
  • Deb_Allen_18's avatar
    Deb_Allen_18
    Historic F5 Account
    Try removing the "$" preceding the poolname, IP address and port. The $ are only needed to indicate a variable reference. Either
    if { [LB::status pool pool_mip_test member 192.168.26.88 80] eq "down" }{
    or
    set myPool pool_mip_test
    set myIP 192.168.26.88
    set myPort 80
    if { [LB::status pool $myPool member $myIP $myPort] eq "down" }{
    will work.

    /deb

  • bl0ndie_127134's avatar
    bl0ndie_127134
    Historic F5 Account
    You know the saying 'when you have a BigIP in you hand, every thing looks like iRules' ....

     

     

    Well I am not sure why no one has told you that you are duplicating something that you paid big bucks for the BigIP to do.

     

     

    Unless you have a really good reason to do an explicit status check your self, there is a far easier way to go about doing this. And that's to do a redirect on LB_FAILED (event which fires if your picked server is unvailable).

     

     

    With that said, there is a bug when you use HTTP::redirect (it works most of the times though) on LB_FAILED and will be fixed on the next release(9.4). If you can't wait that long then you can always set the fallback host in the http profile or with the rule HTTP::fallback to re-direct the user to the sorry page with the XML information.
  • Deb_Allen_18's avatar
    Deb_Allen_18
    Historic F5 Account
    I suppose I should also have pointed out that you wouldn't get a syntax error, but there will be runtime errors like this in the LTM Local Traffic log: Aug 31 12:42:01 tmm tmm[1077]: 01220001:3: TCL error: can't read "ip": no such variable while executing "log local0. "0000 init $ip""/deb

     

  • I tried the LB_FAILED as so

     

     

    when LB_FAILED {

     

    {HTTP::respond 200 content {

     

    xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"

     

    xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

     

     

     

     

     

     

     

     

    http://www.f5.com

     

     

     

     

     

     

     

     

    }}

     

    }

     

     

    However it didn't work. As when I put both nodes in the pool into unavailable status it didn't give me the XML info. When I used the other logic when HTTP_REQUEST and the check on the node it did give me back the XML I was looking for. Did I not use it correctly?

     

     

    Will
  • bl0ndie_127134's avatar
    bl0ndie_127134
    Historic F5 Account
    If the LB_FAILED event did fire then you are probably running into the bug that I talked about. In such case, your best bet is to set the fallback host via rule or http profile to point to the page with the XML response. Some SOAP clients don't understand 302 Redirects. In those cases, you will have to resort to your original rule.