big-ip

How to identify the pool member that processed an HTTP_REQUEST in an iRule


To help with diagnosing a production issue, I'd like to insert the name of the pool member that handled the HTTP_RESPONSE.

I have a pool (my_application_pool) configured with three members (WEB1, WEB2, WEB3), like this:

I have an iRule that looks like this:

when HTTP_REQUEST {
      pool my_application_pool
}

when HTTP_RESPONSE {
      HTTP::header insert pool_member_name value_1
}

If it is WEB2 that processed a request, how can I replace "value_1" with "WEB2"

Thanks!


Solution

  • You can add this to your irule above to populate value_1:

    when LB_SELECTED {
      set value_1 [LB::server addr]
    }
    

    If you are using multiple ports with same addr and/or route domains, you can expand that to be:

    set value_1 "[LB::server addr]%[LB::server route_domain]:[LB::server port]"