Forum Discussion

Gill_32697's avatar
Gill_32697
Icon for Nimbostratus rankNimbostratus
Oct 21, 2012

help making redirect irule

Im new to irules, need some help writing a irule

 

vip: 10.1.255.32

 

node: 10.13.0.61

 

node: 10.0.1.213

 

Web programer wants any http request with

 

http://test.com/Akcelerant/

 

http://test.com/IDSAkcelerant/

 

http://test.com/LMAkcelerant/

 

http://test.com/IDSAkcelerantMTG/...

 

to hit pool member 10.13.0.61 otherwise goto 10.0.1.213.

 

they just need the f5 to pass the url with the path and have it hit the page otherwise go to

 

node 10.0.1.213.

 

 

Thanks

 

9 Replies

  • Might be better for you to use an HTTP class, instead of an iRule:

     

     

    - Remove 10.13.0.61 from the pool.

     

    - Add 10.13.0.61 to a new pool, call it my_special_pool

     

    - Create and apply an HTTP class to the VIP, that :

     

    -- matches any of the URIs you need matched.

     

    -- Use my_special_pool

     

    -- all other traffic will use the default pool.
  • Ok I will try. Thank you Mohamed

     

    Web developer said he will add more path to the header. He will adding

     

    more /something. If I do use an irule and want to add both nodes to the pool and just pass the header intact that matches only the specified /path with a "else" statement that will point to the second node. Can you tell me the irule for that.

     

    Its just incase I need it because I want do this first thing in the morning.

     

    Thank you.

     

  • Ok can you send me a sample of the http class rule, I'm not to good with scripting.

     

    Web developer said he will add more path to the header.

     

    He will adding more /something. If I do use an irule and want to add both nodes to the pool and just pass the header intact that matches only the specified /path with a "else" statement that will point to the second node. Can you tell me the irule for that.

     

    Its just incase I need it because I want do this first thing in the morning.

     

    Thank you.

     

  • you can add more uri to httpclass.

    anyway, this is an example in case of irule.

    [root@ve10:Active] config  b virtual bar list
    virtual bar {
       snat automap
       destination 172.28.19.79:80
       ip protocol 6
       rules myrule
       profiles {
          http {}
          tcp {}
       }
    }
    [root@ve10:Active] config  b class uri_class list
    class uri_class {
       {
          "/akcelerant/"
          "/idsakcelerant/"
          "/idsakcelerantmtg/"
          "/lmakcelerant/"
       }
    }
    [root@ve10:Active] config  b rule myrule list
    rule myrule {
       when HTTP_REQUEST {
       set uri [HTTP::uri]
       if { [class match -- [string tolower $uri] starts_with uri_class] } {
          node 200.200.200.111
       } else {
          node 200.200.200.101
       }
    }
    when HTTP_RESPONSE {
       log local0. "[IP::client_addr]:[TCP::client_port] -> [clientside {IP::local_addr}]:[clientside {TCP::local_port}] -> [IP::remote_addr]:[TCP::remote_port] | $uri"
    }
    }
    
    [root@ve10:Active] config  cat /var/log/ltm
    Oct 22 09:17:21 local/tmm info tmm[7926]: Rule myrule : 172.28.19.251:36438 -> 172.28.19.79:80 -> 200.200.200.111:80 | /Akcelerant/something
    Oct 22 09:17:30 local/tmm info tmm[7926]: Rule myrule : 172.28.19.251:36439 -> 172.28.19.79:80 -> 200.200.200.111:80 | /IDSAkcelerant/something
    Oct 22 09:17:34 local/tmm info tmm[7926]: Rule myrule : 172.28.19.251:36440 -> 172.28.19.79:80 -> 200.200.200.111:80 | /LMAkcelerant/something
    Oct 22 09:17:39 local/tmm info tmm[7926]: Rule myrule : 172.28.19.251:36441 -> 172.28.19.79:80 -> 200.200.200.111:80 | /IDSAkcelerantMTG/something
    Oct 22 09:17:42 local/tmm info tmm[7926]: Rule myrule : 172.28.19.251:36442 -> 172.28.19.79:80 -> 200.200.200.101:80 | /somethingelse/
    
  • Ok can you send me a sample of the http class rule, I'm not to good with scripting.c

     

     

    An http class is all GUI. No need to know scripting.

     

     

  • Below is my irule, Im also showing the uri paths I need. I just don't know how to add more to the irule to include

     

    the other uri paths. As you can see I've added the Akcelerate uri path. But how do I add the rest?

     

    I know is has to contain more IF staetments, but I don't know how to write it. I new to the irules.

     

    -http://test.com/Akcelerant/

     

    -http://test.com/IDSAkcelerant/…

     

    -http://test.com/LMAkcelerant/…

     

    -http://test.com/IDSAkcelerantMTG/...

     

    ----- this is the irule im writing ---------------------------------------------------------

     

    when HTTP_REQUEST {

     

    if { [HTTP::uri] contains "Akcelerant" } {

     

    pool Server1-pool

     

    } else {

     

    pool Server2-pool

     

    }

     

    }

     

     

    Thanks.

     

     

     

  • nitass is showing you how to do this with a switch statement, instead of "if" and using a data class to hold your URIs, instead of hard coding them into the iRule, which a lot better.

     

     

    go under: Local Traffic ›› iRules : Data Group List ›› New Data Group...

     

    Create a String group called uri_class, like in nitass example, put all your URIs there, as "String", leave "Value" empty.

     

     

    Create the iRule as in nitass example, just use "pool" instead of "node"

     

     

    I still think you will better served by an HTTP class, instead of an iRule, given that you are not comfortable with scripting.
  • i agree with Mohamed. if you are not familiar with irule, you had better use httpclass.

    sol13753: Using HTTP Classes to load balance HTTP requests to multiple pools

    http://support.f5.com/kb/en-us/solutions/public/13000/700/sol13753.html

    i used data group in previous example because i thought it would be easier to add or remove uri. anyway, if you do not want to use data group, you can use switch statement and put uri in the irule.

    e.g.

    [root@ve10:Active] config  b rule myrule list
    rule myrule {
       when HTTP_REQUEST {
       switch -glob [HTTP::uri] {
          "/Akcelerant/*" -
          "/IDSAkcelerant/*" -
          "/LMAkcelerant/*" -
          "/IDSAkcelerantMTG/*" {
             pool Server1-pool
          }
          default {
             pool Server2-pool
          }
       }
    }
    }