Learn F5 Technologies, Get Answers & Share Community Solutions Join DevCentral

Filter by:
  • Solution
  • Technology
Answers

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 <HTTP_REQUEST>: Making URI lowercase.
Nov 27 13:09:02 a70kpcrp5dc1007-corp info tmm[11991]: Rule /external_corp/mye-work_with_MaintenancePage_irule <HTTP_REQUEST>: Redirecting based on hrp.
Nov 27 13:09:02 a70kpcrp5dc1007-corp info tmm[11991]: Rule /external_corp/mye-work_with_MaintenancePage_irule <HTTP_REQUEST>: Sending to Pool2_pool.
Nov 27 13:09:02 a70kpcrp5dc1007-corp info tmm[11991]: Rule /external_corp/mye-work_with_MaintenancePage_irule <HTTP_REQUEST>: Inserting HttpsIndicatorHeader Value
Nov 27 13:09:03 a70kpcrp5dc1007-corp info tmm[11991]: Rule /external_corp/mye-work_with_MaintenancePage_irule <HTTP_REQUEST>: Making URI lowercase.
Nov 27 13:09:03 a70kpcrp5dc1007-corp info tmm[11991]: Rule /external_corp/mye-work_with_MaintenancePage_irule <HTTP_REQUEST>: Redirecting based on default.
Nov 27 13:09:03 a70kpcrp5dc1007-corp info tmm[11991]: Rule /external_corp/mye-work_with_MaintenancePage_irule <HTTP_REQUEST>: Sending to the Pool3_pool.
Nov 27 13:09:03 a70kpcrp5dc1007-corp info tmm[11991]: Rule /external_corp/mye-work_with_MaintenancePage_irule <HTTP_REQUEST>: 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
}
0
Rate this Question

Answers to this Question

placeholder+image
USER ACCEPTED ANSWER & F5 ACCEPTED ANSWER

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.

1
Comments on this Answer
Comment made 1 month ago by gdoyle 255

Fantastic, crodriguez! That told me exactly what I needed, and it is in fact requesting different parts of the website (page border images and favicon). This is outstanding.

0
placeholder+image
USER ACCEPTED ANSWER & F5 ACCEPTED ANSWER

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?

0
Comments on this Answer
Comment made 1 month ago by gdoyle 255

Yes, I am trying with a web browser. I am going directly to the URI path, so "http://domain/hrp/"; will cause me to hit Pool2, but I get the logs shown above where it looks like it is cycling through the iRule multiple times and finally ending when it hits the default pool. The behavior, from the end user perspective (which is only me at this point), appears to work as it should however.

I don't know where information is being pulled from to render that webpage, but that is all a separate connection, is it not? I wouldn't think that would invoke the irule in anyway, or am I misunderstanding the connectivity?

Thanks for your response!

0