Logging pool member name (and not just address)

Problem this snippet solves:

I wanted to see a pool member's text name, not just the IP address, in logs. We accomplished this by creating an iCall script that routinely created dynamic data-groups from existing pools, then using an iRule to log the pool member's name based on lookup.

How to use this snippet:

We had this script run periodically as new pool members were not created/added on a regular basis:

create sys icall handler periodic create_poolmember_datagroups interval 86400 script create_poolmember_datagroups  


The iRule would look in "dynpoolmbrdg-[pool_name]" by IP address and log the corresponding member text name.

Code :

icall script create_poolmember_datagroups {  
    app-service none  
    definition {  
        # Define variable types  
        set poollist [list]  
        set memberlist [list]  
        set datagrouplist [list]  
        # get a list of current data-groups  
        set dglistraw [tmsh::get_config /ltm data-group internal]  
        foreach datagroup $dglistraw {  
            lappend datagrouplist [tmsh::get_name $datagroup]  
        # process each pool member in the configuration  
        set poollistraw [tmsh::get_config /ltm pool]  
        foreach pool $poollistraw {  
            # retrieve the pool name and current members  
            set poolname [tmsh::get_name $pool]  
            set memberlist [tmsh::get_field_value $pool members]  
            # Create the pool's data group if it doesn't exist  
            set dyndgname dynpoolmbrdg-$poolname  
            if {[lsearch $datagrouplist $dyndgname] >= 0} {  
            } else {  
                tmsh::create ltm data-group internal $dyndgname type string  
            # Overwrite the data-group with a list of the current members  
            foreach member $memberlist {  
                set membername [tmsh::get_name $member]  
                set memberaddr [tmsh::get_field_value $member "address"]  
                append payload "$memberaddr { data $membername } "  
            set records "{ $payload }"  
            tmsh::modify ltm data-group internal $dyndgname records replace-all-with $records  
    description none  
    events none  

Tested this on version:

No Version Found
Published Aug 13, 2019
Version 1.0

Was this article helpful?

No CommentsBe the first to comment