Forum Discussion

collinz1_17223's avatar
collinz1_17223
Icon for Nimbostratus rankNimbostratus
Jun 06, 2011

irule active_members <1 and MSIE 7

I have an irule that returns HTML when all pool members are down, this works fine, hower what i now want to do is return different HTML if users are using IE7. It would be great to be able to return differnt HTML for multiple other browsers (IE6 & IE7) also.

 

 

when HTTP_REQUEST {

 

if { ([active_members [LB::server pool]] < 1) and ( [string tolower [HTTP::header User-Agent]] eq [string tolower "*msie 7.*"])} {

 

HTTP::respond 200 content {

 

...

 

 

elseif { [active_members [LB::server pool]] < 1} {

 

HTTP::respond 200 content {

 

...

 

8 Replies

  • when HTTP_REQUEST {

     

    if {[active_members [LB::server pool]] < 1} {

     

    if {[string tolower [HTTP::header User-Agent]] contains "msie 7"} {

     

    do something

     

    } else {

     

    do something else

     

    }

     

    }

     

    }
  • Thats great thanks. How would i specify multiple agents in the same line? I have tried the following as an example, but it doesnt appear to work:

     

     

    when HTTP_REQUEST {

     

    if {[active_members [LB::server pool]] < 1} {

     

    if {[string tolower [HTTP::header User-Agent]] contains "msie 7" or "msie 6"} {

     

    do something

     

    } else {

     

    do something else

     

    }

     

    }

     

    }
  • i think matchclass/class with data group should be good. what bigip version r u running?

     

     

    matchclass

     

    http://devcentral.f5.com/wiki/default.aspx/iRules/matchclass.html

     

     

    class

     

    http://devcentral.f5.com/wiki/default.aspx/iRules/class.html
  • i have setup a data group (called msie) with string values of msie 6 & msie 7 and attempted to reference the group in an irule, but it doesn't appear to be working. Traffic seems to be matching my "else" statement.

     

     

    when HTTP_REQUEST {

     

    if {[active_members [LB::server pool]] < 1} {

     

    if {[class match [HTTP::header User-Agent] equals "msie" ] } {

     

    do something

     

    } else {

     

    do something else

     

    }

     

    }

     

    }

     

  • can u try this one?

     

     

    when HTTP_REQUEST {

     

    if {[active_members [LB::server pool]] < 1} {

     

    if {[class match [HTTP::header User-Agent] contains msie]} {

     

    do something

     

    } else {

     

    do something else

     

    }

     

    }

     

    }
  • Colin_Walker_12's avatar
    Colin_Walker_12
    Historic F5 Account
    You'll almost certainly want to use contains, not equals, otherwise you'll have to have the entire and exact entry in the class, and that would be a pain given all the different possible user agent strings. You'll also want to be sure that you're forcing everything to either upper or lowercase for the comparison.

     

     

    Something like : [class match [string tolower [HTTP::header User-Agent]] contains "msie"]

     

     

    Colin
  • That did indeed work, thanks.

     

    I now have an irule that returns one set of HTML for IE7 and IE6 users when all pool members are down and a different set of HTML for all other users.