Forum Discussion

F5-Geek's avatar
F5-Geek
Icon for Nimbostratus rankNimbostratus
Jun 18, 2018

irule help

I would like convert the email address into username. for example email address Jack.White001@acme.com to username jwhit001

 

5 Replies

  • Hello Innovator,

     

    what is the motive or reason for change name?, can you prove more information of the that you need, please

     

  • I think what Edward is asking for are the specifications for the conversion. In your example, it looks like you pull the first character of the email address part that appears before the dot, followed by the first four characters of the part that appears after the dot, followed by the numbers that appear at the end of the part after the second dot. But is it always this way? Are there always a static number of digits in the email address (3), or is it variable? In other words, to do this programmatically, such as with an iRule, we have to know the rules for transformation.

     

  • thanks for reply, this email address which we get the email address of the UPN, but the back only knows the username , we want to convert the email address in username send to the backend server yes,jwhit001, username would always be in this format first letter from the firstname then four letters from the lastname and ends with three digits

     

  • Hi,

    i write you this irule:

    when HTTP_REQUEST {
    
    set mail "youssef.brown@mydomain.com"
    
    regexp {^(.{0,1})[^.]+.([^@]+)} $mail -> firletername lastname
    
    set username "$firletername$lastname"
    
    log local0. "USERNAME: $username"
    
     you will receive this logs  USERNAME: ybrown
    
    }
    

    If you give me the context (if you use APM or not) I can give you more details. keep me in touch

    Regards

  • Hi,

     

    In such case, I request AD server with UPN and retrieve AD sAMAccountName.

     

    First, replace this irule to a variable assign like in this link. the following code extract without the irule event.

     

    set extension [string tolower [mcget {session.ssl.cert.x509extension}]];  
    return [string range $extension [expr {[string first "othername:ups<" $extension] +14}] [expr {[string last ">" $extension] -1}] ];  

    after this, add a AD query box with Filter:

     

    (userPrincipalName=%{session.logon.last.upn})

    then sAMAccountName is store in session.ad.last.attr.sAMAccountName. you can copy it in session.logon.last.username with a new variable assign box with expression.

     

    expr {[mcget {session.ad.last.attr.sAMAccountName}]}

    don't forget to create 2 variables:

     

    • session.logon.last.username
    • session.logon.last.logonname (used in active session or event logs)

    Note: Variable assign code change. there was an issue with string first searching for an uppercase string in a lowercase converted string.