Forum Discussion
nested elseif unexpected behaviour
I created an iRule to (first) redirect to maintenance page and then if available redirect traffic to 1 of 3 pools based on URI data groups. The iRule compiles fine but the result is unexpected. The correct home page comes up but is missing parts and if I try any of the links the lead nowhere and the home page remains.
New rule:
when HTTP_REQUEST {
if { [active_members INF-HEC-HTTP] < 1 } {
switch -glob [string tolower [HTTP::path]] {
"_.gif" -
"_.css" {
HTTP::uri [string range [HTTP::uri] [string last / [HTTP::uri]] end]
}
default {
HTTP::uri /
}
}
pool QA-PH
} elseif { [class match [string tolower [HTTP::uri]] starts_with QA-HEC-ENT-URI] } {
pool INF-ENT-HTTP
} elseif { [class match [string tolower [HTTP::uri]] starts_with QA-HEC-URI] } {
pool INF-HEC-DNNREDIRECT
} else {
pool INF-HEC-HTTP
}
}
Old rule that works except for maintenace: and no uri
when HTTP_REQUEST {
switch -glob [string tolower [HTTP::uri]] {
"/ent/*" -
"/"
{ pool QA-ENT-HTTP
return
}
}
switch -glob [string tolower [HTTP::uri]] {
"/site_includes/_" -
"/backoffice_newer_" -
"/emp_banner/_" -
"/media_kits/" -
"/promo/_" -
"/adproducts/" -
"/cst/ui/_" -
"/cst/backoffice/_" -
"/employer_" -
"/employer/" -
"/js-old/_" -
"/employer\asp" -
"/site_templates/_" -
"/assoclist.asp_"
{
pool QA-HEC-HTTP-DNNREDIRECT
}
default
{
pool QA-HEC-HTTP
}
}
}
- nitassEmployee
The correct home page comes up but is missing parts and if I try any of the links the lead nowhere and the home page remains.
may you try tcpdump on bigip to see what the wrong is?
- Kevin_StewartEmployee
So are you saying that in the absence of the maintenance condition it all works?
when HTTP_REQUEST { if { [class match [string tolower [HTTP::uri]] starts_with QA-HEC-ENT-URI] } { pool INF-ENT-HTTP } elseif { [class match [string tolower [HTTP::uri]] starts_with QA-HEC-URI] } { pool INF-HEC-DNNREDIRECT } else { pool INF-HEC-HTTP } }
Are you specifically testing the maintenance condition, or are you saying that the inclusion of the maintenance condition code causes issues when not in a maintenance condition ([active_members INF-HEC-HTTP] < 1)?
If the former, perhaps removing the default HTTP::uri / statement might help. You're basically saying that for anything that doesn't end with .gif or .css, rewrite the URI to /.
Otherwise, as alluded earlier, it may be a good idea to fire up a client side analysis tool like Fiddler or HTTPWatch to see what's going on under the hood.
- ryan_rockwell_1Nimbostratus
I guess I'm trying to make too many changes at once so I decided to narrow my focus. First I need to get the rule to work with Data Groups. So I used Kevin's rule and checked it against my environment:
when HTTP_REQUEST { if { [class match [string tolower [HTTP::uri]] starts_with QA-HEC-ENT-URI] } { pool INF-ENT-HTTP } elseif { [class match [string tolower [HTTP::uri]] starts_with QA-HEC-URI] } { pool INF-HEC-DNNREDIRECT } else { pool INF-HEC-HTTP } }
Now I get a 500 Internal server error. I'm not familiar with HTTPWatch or Fiddler so I'm going to have to introduce myself to them before I can see what's going on under the hood.
- Kevin_StewartEmployee
You may also want to add in some additional logging.
when HTTP_REQUEST { log local0. "incoming URI = [HTTP::uri]" if { [class match [string tolower [HTTP::uri]] starts_with QA-HEC-ENT-URI] } { log local0. "sending to INF-ENT-HTTP" pool INF-ENT-HTTP } elseif { [class match [string tolower [HTTP::uri]] starts_with QA-HEC-URI] } { log local0. "sending to "INF-HEC-DNNREDIRECT" pool INF-HEC-DNNREDIRECT } else { log local0. "sending to INF-HEC-HTTP" pool INF-HEC-HTTP } }
- ryan_rockwell_1Nimbostratus
Got a better idea of what's going on. Here's my rule:
when HTTP_REQUEST { log local0. "incoming URI = [HTTP::uri]" if { [active_members INF-HEC-HTTP] < 1 } { switch -glob [string tolower [HTTP::path]] { "*.gif" - "*.jpg" - "*.css" { HTTP::uri [string range [HTTP::uri] [string last / [HTTP::uri]] end] } default { HTTP::uri / } } pool QA-PH } elseif { [class match [string tolower [HTTP::uri]] starts_with QA-HEC-ENT-URI] } { log local0. "sending to INF-ENT-HTTP" pool INF-ENT-HTTP } elseif { [class match [string tolower [HTTP::uri]] starts_with QA-HEC-URI] } { log local0. "sending to INF-HEC-DNNREDIRECT" pool INF-HEC-DNNREDIRECT } else { log local0. "sending to INF-HEC-HTTP" pool INF-HEC-HTTP } }
When I look in the log my second esleif is not redirecting to the correct pool. From logs: Rule /Common/INF-HEC-LB-URI-HTTP : incoming URI = /emp_banner/emp_logo/1546723432_City_In_The_Cloud.jpg Rule /Common/INF-HEC-LB-URI-HTTP : sending to INF-ENT-HTTP
emp_banner is included in QA-HEC-URI data group.
So the question then becomes: Is the second elseif being ignored because the first elseif changes something in the URI or do I not have the data group set right.
QA-HEC-URI data group: Type string /backoffice_newer /emp_banner/ /employer
- Kevin_StewartEmployee
None of the conditions are writing anything, so my first guess would be that the QA-HEC-ENT-URI data group also has "/emp_banner" in it. Or does it have something like it but shorter (ex. "/emp", or simply "/")?
- ryan_rockwell_1Nimbostratus
yep. QA-HEC-ENT-URI has a "/" in it. And it's required, so I'm guessing I'm going to have to figure another direction.
- Kevin_StewartEmployee
If you remove "/" from that data group, and add it at as a separate elseif condition, that may help:
} elseif { [HTTP::uri] equals "/" } { pool INF-ENT-HTTP }
- ryan_rockwell_1Nimbostratus
That worked so far. Now back to the problem I have with other sites that I thought I had fixed. When I disable the QA-HEC-HTTP pool the maintenance page comes up but is missing the css and gif's. Thought I have fixed this earlier but apparently not. sigh.
- Kevin_StewartEmployee
Okay, so presumably if the maintenance page comes up, and that maintenance page has links to image objects, the client will fetch those resources. In your iRule, if the path ends with, say *.gif, then
HTTP::uri [string range [HTTP::uri] [string last / [HTTP::uri]] end]
which should be stripping any leading URI from the path.
/foo/bar/my_cat.gif = /my_cat.gif
Is that what you want? Would you need to do that at all, given you're only processing the maintenance mode condition and that maintenance page should have object references you can address directly?
Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com