Forum Discussion

Jcan_4445_38285's avatar
Jcan_4445_38285
Icon for Nimbostratus rankNimbostratus
Feb 11, 2019

Extract email from uri in APM

In APM I'm trying to extract email from uri and assign it to custom variable, but without luck

 

basically from URL https://web.domain1.com/?User=user3@AnotherDomain.com&variable2=blabla, I want to assign user3@AnotherDomain.com to variable userid.

 

I tried something like this: mcget {URI::query [HTTP::uri] User} return

 

But no results (but I'm sort of newbie to bigip) Any suggestions?

 

2 Replies

  • You can try with this

    when ACCESS_SESSION_STARTED {
          ACCESS::session data set session.custom.mail [URI::query [HTTP::uri] User]     
    }
    
  • Fatim's avatar
    Fatim
    Icon for Nimbostratus rankNimbostratus

    It looks like you are using F5 BIG-IP APM (Access Policy Manager) to extract the email address from a URI and assign it to a custom variable. It works similarly like to export LinkedIn contacts to excel. Here's an example iRule that should work:

    when ACCESS_SESSION_STARTED {
    set uri [HTTP::uri]
    set query [URI::query $uri]
    set userid [lindex [regexp -inline {User=([^&]+)} $query] 1]
    if {$userid ne ""} {
    set session_data(userid) $userid
    }
    }

    Here's how this iRule works:

    1. When an APM session is started, the iRule sets the uri variable to the current URI.

    2. The query variable is set to the query string portion of the URI.

    3. The userid variable is set to the value of the User parameter in the query string, using a regular expression to extract it.

    4. If a userid value is found, it is stored in the session_data(userid) variable, which is a custom session variable that you can use in subsequent APM policies or iRules.

    5. You can modify the iRule to assign the userid variable to your custom variable userid instead of session_data(userid) if you prefer.

    Make sure to attach this iRule to your APM virtual server. You can do this in the BIG-IP Configuration utility by going to Local Traffic > Virtual Servers > [your APM virtual server] > Resources > iRules > Edit > Add.