Forum Discussion

pele1_71290's avatar
pele1_71290
Icon for Nimbostratus rankNimbostratus
Dec 04, 2012

How do I make an iRule that has a Context that needs to be rewritten before forwarded to a pool ?

I have a working context switching rule that needs to be updated with rewriting of the url as well.

 

The working iRule looks like this.

 

 

when HTTP_REQUEST {

 

if { [HTTP::uri] contains "/streaming/node1" } {

 

pool pool1_http

 

} elseif { [HTTP::uri] contains "/streaming/node2" } {

 

pool pool2_http

 

} else {

 

pool pool_http

 

}

 

}

 

 

 

My problem has been to add the rewrite to the same rule.

 

 

Before I forward each session i would like to change the string that contains the same statement

 

for example

 

 

"/streaming/node1" to “/external" and then forward to the pool1_http in this case

 

and then

 

elsif next string "/streaming/node2" rewrite to “/external" and then forward to pool2_http

 

 

and then last else statement to

 

pool pool_http

 

 

Im very new to iRules so I hope I dont upset to much of the Feng Shui with this question.

 

 

//Peter

 

6 Replies

  • e.g.

    [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 pool pool1_http list
    pool pool1_http {
       members 200.200.200.101:80 {}
    }
    [root@ve10:Active] config  b pool pool2_http list
    pool pool2_http {
       members 200.200.200.111:80 {}
    }
    [root@ve10:Active] config  b pool pool_http list
    pool pool_http {
       members 172.28.19.251:80 {}
    }
    [root@ve10:Active] config  b rule myrule list
    rule myrule {
       when HTTP_REQUEST {
       if { [HTTP::uri] contains "/streaming/node1" } {
          HTTP::uri "/external"
          pool pool1_http
       } elseif { [HTTP::uri] contains "/streaming/node2" } {
          HTTP::uri "/external"
          pool pool2_http
       } else {
          pool pool_http
       }
    }
    }
    
    1
    
    [root@ve10:Active] config  ssldump -Aed -nni 0.0 port 80
    New TCP connection 1: 172.28.20.11(39575) <-> 172.28.19.79(80)
    1354615050.5267 (0.0030)  C>S
    ---------------------------------------------------------------
    HEAD /streaming/node1/something HTTP/1.1
    User-Agent: curl/7.19.7 (i686-redhat-linux-gnu) libcurl/7.19.7 OpenSSL/0.9.8x zlib/1.2.3 libidn/0.6.5
    Host: 172.28.19.79
    Accept: */*
    
    ---------------------------------------------------------------
    
    New TCP connection 2: 200.200.200.10(39575) <-> 200.200.200.101(80)
    1354615050.5296 (0.0019)  C>S
    ---------------------------------------------------------------
    HEAD /external HTTP/1.1
    User-Agent: curl/7.19.7 (i686-redhat-linux-gnu) libcurl/7.19.7 OpenSSL/0.9.8x zlib/1.2.3 libidn/0.6.5
    Host: 172.28.19.79
    Accept: */*
    
    ---------------------------------------------------------------
    
    2
    
    [root@ve10:Active] config  ssldump -Aed -nni 0.0 port 80
    New TCP connection 1: 172.28.20.11(39586) <-> 172.28.19.79(80)
    1354615088.2146 (0.0030)  C>S
    ---------------------------------------------------------------
    HEAD /streaming/node2/something HTTP/1.1
    User-Agent: curl/7.19.7 (i686-redhat-linux-gnu) libcurl/7.19.7 OpenSSL/0.9.8x zlib/1.2.3 libidn/0.6.5
    Host: 172.28.19.79
    Accept: */*
    
    ---------------------------------------------------------------
    
    New TCP connection 2: 200.200.200.10(39586) <-> 200.200.200.111(80)
    1354615088.2169 (0.0010)  C>S
    ---------------------------------------------------------------
    HEAD /external HTTP/1.1
    User-Agent: curl/7.19.7 (i686-redhat-linux-gnu) libcurl/7.19.7 OpenSSL/0.9.8x zlib/1.2.3 libidn/0.6.5
    Host: 172.28.19.79
    Accept: */*
    
    ---------------------------------------------------------------
    
  • This worked almost perfectly :)

     

    when HTTP_REQUEST {

     

    if { [HTTP::uri] contains "/streaming/node1" } {

     

    HTTP::uri "/external"

     

    pool pool1_http

     

    } elseif { [HTTP::uri] contains "/streaming/node2" } {

     

    HTTP::uri "/external"

     

    pool pool2_http

     

    } else {

     

    pool pool_http

     

    }

     

    }

     

     

    One detail IF I have something after /streaming/node1/xxxxxxxxx/yyyyyy that I like to keep and its just

     

    the /streaming/nodex/ that i like to substitute with the /external/ and still keep the string that follows after is that possible to do ?

     

     

    //Peter
  • This worked almost perfectly :)

     

    when HTTP_REQUEST {

     

    if { [HTTP::uri] contains "/streaming/node1" } {

     

    HTTP::uri "/external"

     

    pool pool1_http

     

    } elseif { [HTTP::uri] contains "/streaming/node2" } {

     

    HTTP::uri "/external"

     

    pool pool2_http

     

    } else {

     

    pool pool_http

     

    }

     

    }

     

     

    One detail IF I have something after /streaming/node1/xxxxxxxxx/yyyyyy that I like to keep and its just

     

    the /streaming/nodex/ that i like to substitute with the /external/ and still keep the string that follows after is that possible to do ?

     

     

    //Peter
  •  

    This worked almost perfectly :)

     

     

    when HTTP_REQUEST {

     

    if { [HTTP::uri] contains "/streaming/node1" } {

     

    HTTP::uri "/external"

     

    pool pool1_http

     

    } elseif { [HTTP::uri] contains "/streaming/node2" } {

     

    HTTP::uri "/external"

     

    pool pool2_http

     

    } else {

     

    pool pool_http

     

    }

     

    }

     

     

    One detail IF I have something after /streaming/node1/xxxxxxxxx/yyyyyy that I like to keep and its just

     

    the /streaming/nodex/ that i like to substitute with the /external/ and still keep the string that follows after is that possible to do ?

     

     

    //Peter

     

  • e.g.

    [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 pool pool1_http list
    pool pool1_http {
       members 200.200.200.101:80 {}
    }
    [root@ve10:Active] config  b pool pool2_http list
    pool pool2_http {
       members 200.200.200.111:80 {}
    }
    [root@ve10:Active] config  b pool pool_http list
    pool pool_http {
       members 172.28.19.251:80 {}
    }
    [root@ve10:Active] config  b rule myrule list
    rule myrule {
       when HTTP_REQUEST {
       if { [HTTP::uri] contains "/streaming/node1" } {
          HTTP::uri [string map {"/streaming/node1" "/external"} [HTTP::uri]]
          pool pool1_http
       } elseif { [HTTP::uri] contains "/streaming/node2" } {
          HTTP::uri [string map {"/streaming/node1" "/external"} [HTTP::uri]]
          pool pool2_http
       } else {
          pool pool_http
       }
    }
    }
    
    1
    
    [root@ve10:Active] config  ssldump -Aed -nni 0.0 port 80
    New TCP connection 1: 172.28.20.11(40589) <-> 172.28.19.79(80)
    1354630059.4768 (0.0022)  C>S
    ---------------------------------------------------------------
    GET /streaming/node1/xxxxxxxxx/yyyyyy HTTP/1.1
    User-Agent: curl/7.19.7 (i686-redhat-linux-gnu) libcurl/7.19.7 OpenSSL/0.9.8x zlib/1.2.3 libidn/0.6.5
    Host: 172.28.19.79
    Accept: */*
    
    ---------------------------------------------------------------
    
    New TCP connection 2: 200.200.200.10(40589) <-> 200.200.200.101(80)
    1354630059.4797 (0.0010)  C>S
    ---------------------------------------------------------------
    GET /external/xxxxxxxxx/yyyyyy HTTP/1.1
    User-Agent: curl/7.19.7 (i686-redhat-linux-gnu) libcurl/7.19.7 OpenSSL/0.9.8x zlib/1.2.3 libidn/0.6.5
    Host: 172.28.19.79
    Accept: */*
    
    ---------------------------------------------------------------
    
    2
    
    [root@ve10:Active] config  ssldump -Aed -nni 0.0 port 80
    New TCP connection 1: 172.28.20.11(40592) <-> 172.28.19.79(80)
    1354630093.4867 (0.0029)  C>S
    ---------------------------------------------------------------
    GET /streaming/node2/aaaaaa/bbbbbbbb HTTP/1.1
    User-Agent: curl/7.19.7 (i686-redhat-linux-gnu) libcurl/7.19.7 OpenSSL/0.9.8x zlib/1.2.3 libidn/0.6.5
    Host: 172.28.19.79
    Accept: */*
    
    ---------------------------------------------------------------
    
    New TCP connection 2: 200.200.200.10(40592) <-> 200.200.200.111(80)
    1354630093.4888 (0.0009)  C>S
    ---------------------------------------------------------------
    GET /streaming/node2/aaaaaa/bbbbbbbb HTTP/1.1
    User-Agent: curl/7.19.7 (i686-redhat-linux-gnu) libcurl/7.19.7 OpenSSL/0.9.8x zlib/1.2.3 libidn/0.6.5
    Host: 172.28.19.79
    Accept: */*
    
    ---------------------------------------------------------------