Forum Discussion
F5 BIG-IP Irule - redirect to individual node for external monitoring
Hi all
I'm looking at implementing an external monitoring solution whereby we do something like the following
-
read the URI and see if it contains formatting like this "/monitoring/servername" (filter on the "monitoring/" part and set that as a variable)
-
use that variable as the pool name and send traffic to it (ideally create the pool dynamically based on DNS)
-
rewrite the uri to remove the "/monitoring/servername" (where servername can be anything) to "*" (whatever is behind /monitoring/servername)
e.g if the f5 receives the following traffic:
HTTP GET: http://testing.com/login/login.aspx/monitoring/server21
It should interpret the string, send the traffic to server21, and remove the /monitoring/server21 from the URI.
i have looked at both policies and irules for this and I am pretty sure I need an irule. However I am not 100% on what to do. I would like the irule to be as flexible as possible ideally.
I know the below does not work but I am just trying to piece it together now... help?
when HTTP_REQUEST {
Check if path contains /monitoring
if {[HTTP::path] contains "/monitoring "}{
use getfield to split the uri based on monitoring/ and then return the server name after that
set server_id [getfield [HTTP::uri] "monitoring/" 1 ]
Replace /monitoring with / in the path
HTTP::redirect [string map {/monitoring /} [HTTP::path]]
pool ${server_id}
}
}
3 Replies
- Al_s_296685
Nimbostratus
ok, im getting there towards answering my own question.
any refinements on this would be appreciated:
when HTTP_REQUEST { Check if path contains /monitoring if {[HTTP::path] contains "/monitoring/"}{ use getfield to split the uri based on monitoring/ and then return the server name after that set server_id [getfield [HTTP::uri] "monitoring/" 2 ] log local0. "Server id: $server_id" Replace /monitoring and servername in the path set toremove [string range [HTTP::uri] [expr {[string first "/monitoring/" [HTTP::uri]]}] end] log local0. "part of uri to remove: $toremove" set replace "/" set uri [string map [list $toremove $replace] [HTTP::uri]] log local0. "New URI = $uri" HTTP::uri $uri redirect or rewrite uri? HTTP::redirect "http://[HTTP::host]$uri" pool "/Common/${server_id}" } } - Faruk_AYDIN
Altostratus
Change the second part(replace) of your irule like this :
when HTTP_REQUEST { Check if path contains /monitoring if {[HTTP::path] contains "/monitoring/"}{ use getfield to split the uri based on monitoring/ and then return the server name after that set server_id [getfield [HTTP::uri] "monitoring/" 2 ] log local0. "Server id: $server_id" Replace /monitoring and servername in the path set uri [string range [HTTP::uri] 0 [expr {[string first "/monitoring/" [HTTP::uri]] - 1}]] log local0. "orginal part of uri: $uri" HTTP::uri $uri redirect or rewrite uri? HTTP::redirect "http://[HTTP::host]$uri" pool "/Common/${server_id}" } }If I were you, I would use node ip (and w/o node port) instead of Server name, like this:
when HTTP_REQUEST { Check if path contains /monitoring if {[HTTP::path] contains "/monitoring/"}{ use getfield to split the uri based on monitoring/ and then return the node ip after that set server_id [getfield [HTTP::uri] "monitoring/" 2 ] log local0. "Node IP: $node_ip" Omit /monitoring and nodeip in the path set uri [string range [HTTP::uri] 0 [expr {[string first "/monitoring/" [HTTP::uri]] - 1}]] log local0. "orginal part of uri: $uri" HTTP::uri $uri Send the request to the specified node node $node_ip 80 } } - jomedusa
Altocumulus
I have been looking for something similar to this for a bit...do you have any updates or current config that is in production? I am going to test with the above snippet and see the results.
Any additional information would be appreciated.
Joe
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)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
