Forum Discussion

gdoyle's avatar
gdoyle
Icon for Cirrostratus rankCirrostratus
Nov 27, 2018

How to skip a section of iRule based on matches?

Hey, y'all. So I have this irule that I've been working on for a while (long story... Mostly haven't had a chance to test). I have included the irule below.

When I run test while doing a "tail -f /var/log/ltm | grep MaintenancePage" (the name of the irule) I see my one request hitting multiple portions of the rule. So when I navigate to the vip /hrp/ I should be redirected to Pool2, but in the logs I am seeing 11 HTTP requests. 10 of these are going to Pool2 (the correct pool), but the last one always goes to Pool3 (the default pool). However, the correct page loads.

So the logs would look like this (with 10 instances of "Pool2_pool" instead of one):

Nov 27 13:09:02 a70kpcrp5dc1007-corp info tmm[11991]: Rule /external_corp/mye-work_with_MaintenancePage_irule : Making URI lowercase.
Nov 27 13:09:02 a70kpcrp5dc1007-corp info tmm[11991]: Rule /external_corp/mye-work_with_MaintenancePage_irule : Redirecting based on hrp.
Nov 27 13:09:02 a70kpcrp5dc1007-corp info tmm[11991]: Rule /external_corp/mye-work_with_MaintenancePage_irule : Sending to Pool2_pool.
Nov 27 13:09:02 a70kpcrp5dc1007-corp info tmm[11991]: Rule /external_corp/mye-work_with_MaintenancePage_irule : Inserting HttpsIndicatorHeader Value
Nov 27 13:09:03 a70kpcrp5dc1007-corp info tmm[11991]: Rule /external_corp/mye-work_with_MaintenancePage_irule : Making URI lowercase.
Nov 27 13:09:03 a70kpcrp5dc1007-corp info tmm[11991]: Rule /external_corp/mye-work_with_MaintenancePage_irule : Redirecting based on default.
Nov 27 13:09:03 a70kpcrp5dc1007-corp info tmm[11991]: Rule /external_corp/mye-work_with_MaintenancePage_irule : Sending to the Pool3_pool.
Nov 27 13:09:03 a70kpcrp5dc1007-corp info tmm[11991]: Rule /external_corp/mye-work_with_MaintenancePage_irule : Inserting HttpsIndicatorHeader Value

So I am trying to make sure that only the correct portion of the iRule is processed, but I also need the last lines to process because I need the HttpsIndicatorHeader Value inserted.

Any thoughts?

Thanks.

when HTTP_REQUEST {
    log local0. "Making URI lowercase."
    switch -glob [string tolower [HTTP::uri]] {
      "/abc/xyz" -
      "/abc/xyz/" -
      "/" { 
    log local0. "Redirecting based on /abc/xyz."
        HTTP::respond 301 "Location" "https://myplace.com/abc/xyz/myplace" 
       }
      "/redirect*" { 
     log local0. "Redirecting based on redirect"

 
 This next section states that if there are more than 0 pool members are active in the Pool1_pool 
 then the user is redirected there, else they are presented a Maintenance Page.

          if { [active_members Pool1_pool] > 0 } {
            log local0. "Sending to Pool1_pool."
              pool Pool1_pool 
          } else {
            log local0. "Sending to MX Page for Pool1_pool."
              HTTP::respond 503 content [ifile get "/external/MaintenancePage_ifile"] noserver "Content-Type" "text/html" "Cache-Control" "no-cache, must-revalidate"
              return
          }
      }
      "*/hrp/*" { 
        log local0. "Redirecting based on hrp."

 
 This next section states that if there are more than 0 pool members are active in the Pool2_pool 
 then the user is redirected there, else they are presented a Maintenance Page.

          if { [active_members Pool2_pool] > 0 } {
            log local0. "Sending to Pool2_pool."
              pool Pool2_pool 
          } else {
            log local0. "Sending to MX Page for the Pool2_pool."
              HTTP::respond 503 content [ifile get "/external/MaintenancePage_ifile"] noserver "Content-Type" "text/html" "Cache-Control" "no-cache, must-revalidate"
              return
          }
       }
      default { 
        log local0. "Redirecting based on default."

 
 This next section states that if there are more than 0 pool members are active in the Pool3_pool 
 then the user is redirected there, else they are presented a Maintenance Page.

          if { [active_members Pool3_pool] > 0 } {
            log local0. "Sending to the Pool3_pool."
              pool Pool3_pool 
          } else {
            log local0. "Sending to MX Page for the Pool3_pool."
              HTTP::respond 503 content [ifile get "/external/MaintenancePage_ifile"] noserver "Content-Type" "text/html" "Cache-Control" "no-cache, must-revalidate"
              return
          }
      }
    }

 This next section inserts an HttpsIndicatorHeader value of True to prevent Websphere redirect errors.

    log local0. "Inserting HttpsIndicatorHeader Value"
    HTTP::header insert HttpsIndicatorHeader True
}

2 Replies

  • how do you try? with a browser???

     

    Are you sure the browser doesn't request a URI which doesn't match first statements and matches default?

     

    Does the main page contain links to other content out of defined path?

     

  • That last one that takes the default route to pool3 might be caused by your browser requesting the "favicon" for the site. (Chrome does that by default.) To troubleshoot more effectively, try adding [HTTP::host] and [HTTP::uri] to your log statements to understand what the request was for. That should explain why the surprise default switch condition was triggered.