Forum Discussion

mbamusa_59409's avatar
mbamusa_59409
Icon for Nimbostratus rankNimbostratus
Sep 02, 2013

irule to distribute based on user agent

Hello ;

 

could you please help me creating irule to send traffic to specific pool if its comes from IE6,7 and 8 and rest to default pool .

 

Your kind assistance is highly appreciated.

 

mbamusa

 

17 Replies

    • mbamusa_59409's avatar
      mbamusa_59409
      Icon for Nimbostratus rankNimbostratus
      thank you for your reply . i created the following (can we combine the first 3 conditions in 1 using OR). when HTTP_REQUEST { if {[string tolower [HTTP::header User-Agent]] contains "msie6" }{ pool Pool1 } elseif {[string tolower [HTTP::header User-Agent]] contains "msie7" }{ pool Pool } elseif {[string tolower [HTTP::header User-Agent]] contains "msie8" }{ pool Pool1 }else { pool Pool2 } }
    • nitass's avatar
      nitass
      Icon for Employee rankEmployee
      you can use "or" e.g. if { [...] or [...] or [...] } {
    • mbamusa_59409's avatar
      mbamusa_59409
      Icon for Nimbostratus rankNimbostratus
      will this work ? when HTTP_REQUEST { if {[string tolower [HTTP::header User-Agent]] contains "msie6" or "msie7" or "msie8"}{ pool Pool1 }else { pool Pool2 } }
    • mbamusa_59409's avatar
      mbamusa_59409
      Icon for Nimbostratus rankNimbostratus
      thank you for your reply . i created the following (can we combine the first 3 conditions in 1 using OR). when HTTP_REQUEST { if {[string tolower [HTTP::header User-Agent]] contains "msie6" }{ pool Pool1 } elseif {[string tolower [HTTP::header User-Agent]] contains "msie7" }{ pool Pool } elseif {[string tolower [HTTP::header User-Agent]] contains "msie8" }{ pool Pool1 }else { pool Pool2 } }
    • mbamusa_59409's avatar
      mbamusa_59409
      Icon for Nimbostratus rankNimbostratus
      will this work ? when HTTP_REQUEST { if {[string tolower [HTTP::header User-Agent]] contains "msie6" or "msie7" or "msie8"}{ pool Pool1 }else { pool Pool2 } }
  • Try:

    when CLIENT_ACCEPTED {
        set default_pool [LB::server pool]
    }
    when HTTP_REQUEST {
        if { [string tolower [HTTP::header User-Agent]] contains "blah" } {
            pool ms_pool
        } else {
            pool $default_pool
        }
    }
    

    Change "blah" to a unique value in the IE User-Agent header, and change ms_pool to the name if your MS pool.

  • will this work ? when HTTP_REQUEST { if {[string tolower [HTTP::header User-Agent]] contains "msie6" or "msie7" or "msie8"}{ pool Pool1 }else { pool Pool2 } }

    you have to repeat [string tolower [HTTP::header User-Agent]] (or set it to variable first and re-use it later) in if-condition.

    e.g.

      set uagent [string tolower [HTTP::header User-Agent]]
      if { $uagent contains "msie6" or $uagent contains "msie7" or $uagent contains "msie8"} {
    

    or you may use switch instead of if-condition.

    e.g.

    [root@ve11a:Active:Not All Devices Synced] config  tmsh list ltm rule myrule
    ltm rule myrule {
        when HTTP_REQUEST {
      switch -glob [HTTP::header value "User-Agent"] {
        "*MSIE 6*" -
        "*MSIE 7*" -
        "*MSIE 8*" {
          pool qux
        }
        default {
          pool [LB::server pool]
        }
      }
    }
    }
    
    • mbamusa_59409's avatar
      mbamusa_59409
      Icon for Nimbostratus rankNimbostratus
      Thank you Nitass , is the below OK ? set uagent [string tolower [HTTP::header User-Agent]] if { $uagent contains "msie6" or $uagent contains "msie7" or $uagent contains "msie8"}{ pool Pool1 } else { pool Pool2 } }
    • Colin_Walker_12's avatar
      Colin_Walker_12
      Historic F5 Account
      That looks logically sound to me, but you might want to think about using a switch statement, as nitass showed above, if you start expanding it to include any more options for User-Agent. The or conditional forces iRules to effectively run multiple if comparisons, one for each or clause, and after a handful of those you'll start seeing switch perform more efficiently. Not to mention switch is way prettier to look at, and we all like pretty code, right? Right. Colin
  • will this work ? when HTTP_REQUEST { if {[string tolower [HTTP::header User-Agent]] contains "msie6" or "msie7" or "msie8"}{ pool Pool1 }else { pool Pool2 } }

    you have to repeat [string tolower [HTTP::header User-Agent]] (or set it to variable first and re-use it later) in if-condition.

    e.g.

      set uagent [string tolower [HTTP::header User-Agent]]
      if { $uagent contains "msie6" or $uagent contains "msie7" or $uagent contains "msie8"} {
    

    or you may use switch instead of if-condition.

    e.g.

    [root@ve11a:Active:Not All Devices Synced] config  tmsh list ltm rule myrule
    ltm rule myrule {
        when HTTP_REQUEST {
      switch -glob [HTTP::header value "User-Agent"] {
        "*MSIE 6*" -
        "*MSIE 7*" -
        "*MSIE 8*" {
          pool qux
        }
        default {
          pool [LB::server pool]
        }
      }
    }
    }
    
    • mbamusa_59409's avatar
      mbamusa_59409
      Icon for Nimbostratus rankNimbostratus
      Thank you Nitass , is the below OK ? set uagent [string tolower [HTTP::header User-Agent]] if { $uagent contains "msie6" or $uagent contains "msie7" or $uagent contains "msie8"}{ pool Pool1 } else { pool Pool2 } }
    • Colin_Walker_12's avatar
      Colin_Walker_12
      Historic F5 Account
      That looks logically sound to me, but you might want to think about using a switch statement, as nitass showed above, if you start expanding it to include any more options for User-Agent. The or conditional forces iRules to effectively run multiple if comparisons, one for each or clause, and after a handful of those you'll start seeing switch perform more efficiently. Not to mention switch is way prettier to look at, and we all like pretty code, right? Right. Colin