Forum Discussion
iRule to Extract and Repsond back with client IP
All,
I've got the following iRule setup that's being used as a health check for some of our clients. Right now the text we reply back with is a basic static value "TestOk". I'm wondering if its possible to something more dynamic where we extract the IP address of the client and respond back with it as the value, but so far I haven't had any luck. I've looked around here for a similar topic, but haven't found anything yet.
when CLIENT_ACCEPTED { if {[active_members client-443-pool-01] < 1}{ reject } }
when HTTP_REQUEST {
Look for a URI If found send back an HTTP 200 if { [HTTP::uri] equals "/about/health/status" } { Send a 200 response with data HTTP::respond 200 "X-Responce" "TestOk" } else { drop } }
5 Replies
- Brad_Parker_139
Nacreous
Give this a try:
when HTTP_REQUEST { Look for a URI If found send back an HTTP 200 if { [HTTP::uri] equals "/about/health/status" } { Send a 200 response with data HTTP::respond 200 "X-Responce" "TestOk for client [getfield [IP::client_addr] {%} 1]" } else { drop } }- Tyler_Brown_949
Nimbostratus
Thanks for the quick response Brad, I'll give that a try. I just got it working with the following as well. when CLIENT_ACCEPTED { if {[active_members client-443-pool-01] < 1}{ reject } } when HTTP_REQUEST { Look for a URI If found send back an HTTP 200 if { [HTTP::uri] equals "/about/health/status" } { Send a 200 response with data HTTP::respond 200 "X-PublicIP" "[IP::client_addr]" "X-Responce" "TestOk" } else { drop } }
- Brad_Parker
Cirrus
Give this a try:
when HTTP_REQUEST { Look for a URI If found send back an HTTP 200 if { [HTTP::uri] equals "/about/health/status" } { Send a 200 response with data HTTP::respond 200 "X-Responce" "TestOk for client [getfield [IP::client_addr] {%} 1]" } else { drop } }- Tyler_Brown_949
Nimbostratus
Thanks for the quick response Brad, I'll give that a try. I just got it working with the following as well. when CLIENT_ACCEPTED { if {[active_members client-443-pool-01] < 1}{ reject } } when HTTP_REQUEST { Look for a URI If found send back an HTTP 200 if { [HTTP::uri] equals "/about/health/status" } { Send a 200 response with data HTTP::respond 200 "X-PublicIP" "[IP::client_addr]" "X-Responce" "TestOk" } else { drop } }
- Kevin_Stewart
Employee
I assume you understand that "X-Response" will be returned to the client as an HTTP header. If you want the data to be present in the HTTP payload you'd use the "Content" tag:
when HTTP_REQUEST { if { [HTTP::uri] equals "/about/health/status" } { HTTP::respond 200 Content "TestOK" } }As far as the data that you send back, that can come from any values presented in the client's request and potentially a wealth of server side information. For example, to send the client's IP back:
when HTTP_REQUEST { if { [HTTP::uri] equals "/about/health/status" } { HTTP::respond 200 X-Response "TestOK: [IP::client_addr]" } }
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