Forum Discussion
IRULE redirection to maintenance pool based on client IP and cookie...
Hi,
I have a requirement to redirect test clients to a maintenance pool based on client IP address and the client manually inserting a cookie. The process will be..
Server maintenance flag set which takes server out of the live pool and enables it in the maintenance pool. The a test client will set a cookie in browser and get redirected to the active server in the maintenance pool.
I have all this working with the IRULE below (there are actually more sites). However I am wondering if there is a more efficient way to do this (i am fairly new to IRULES)..
Thanks Matt
I think this will do what you need...
when HTTP_REQUEST { if {[class match [HTTP::header "True-Client-IP"] equals MAINTENANCE-CLIENTS]} { if {[HTTP::cookie exists "MAINTENANCE"]} { switch -glob [string tolower [HTTP::uri]] { "/site1*" - "/site2*" - "/site3*" { pool MAINT-A; persist cookie } } go no further return } } switch -glob [string tolower [HTTP::uri]] { "/site1*" { pool POOL-A; persist cookie } "/site2*" { pool POOL-B ; persist cookie } "/site3*" { pool POOL-C; persist cookie } } }
- Kevin_Davies_40Nacreous
Sorry I cant see an iRule here
- matt1985_299432Nimbostratus
First time I have posted here and when i add my irules it sees it as spam....
- matt1985_299432Nimbostratus
image of IRULE inserted
- Kevin_Davies_40Nacreous
Just paste it to notepad, then paste it here. Then highlight the entire iRule then hit TAB to indent it. This will make Devcentral treat it like code and not markup. Do this in the original post by editing it. Click the tiny little pad and pencil next to your profile picture at the top of your post to edit.
- matt1985_299432Nimbostratus
Inserting as image as no luck with txt so far
- Kevin_Davies_40Nacreous
I think this will do what you need...
when HTTP_REQUEST { if {[class match [HTTP::header "True-Client-IP"] equals MAINTENANCE-CLIENTS]} { if {[HTTP::cookie exists "MAINTENANCE"]} { switch -glob [string tolower [HTTP::uri]] { "/site1*" - "/site2*" - "/site3*" { pool MAINT-A; persist cookie } } go no further return } } switch -glob [string tolower [HTTP::uri]] { "/site1*" { pool POOL-A; persist cookie } "/site2*" { pool POOL-B ; persist cookie } "/site3*" { pool POOL-C; persist cookie } } }
- Kevin_Davies_40Nacreous
Only if the True-Client-IP equals the data class AND the cookie exists will it select the maintenance pool. Otherwise it will process the next section routing traffic as normal. If the header does not exist it will simply return "" which should not match anything in the data class.
- matt1985_299432Nimbostratus
Thanks Kevin looks allot cleaner ;) I will give it a try...
- matt1985_299432Nimbostratus
Hi Kevin,
That works much better certainly if I set client IP AND cookie as specified it still gets me to the maintenance pools. However not falling through to the normal pools when there is no specific cookie client IP required.. just trying to work that through
Thanks
Matt
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