cancel
Showing results for 
Search instead for 
Did you mean: 
Kai_Wilke
MVP
MVP

Problem this snippet solves:

Hi Folks,

the iCall script and handler below can be used to auto-generate a NodeIP-to-NodeName datagroup on scheduled intervals. The auto-generate datagroup can then be used to resolve the [LB::server addr] output to the coresponsing node name label using the [class match -value] syntax.

Cheers, Kai

How to use this snippet:

  1. Tweak the periodic intervals (in seconds) of the iCall handler as needed.
  2. Import the provided iCall script and handler using the tmsh load config merge from-terminal syntax
  3. Take a look to the configured data-groups and LTM logfiles to verify the results.
  4. Use [class match -value [LB::server addr] DG_IP_2_NODENAME] within an iRule to resolve the name of a selected pool member.

Code :

sys icall script DataGroup_NodeIP_to_NodeName {
    app-service none
    definition {
        set nodelist ""
        set nodecounter 0
        # tmsh::log "iCall: Starting to enumerate existing node objects..."
        foreach partition [tmsh::get_config auth partition] {
            set partition "/[tmsh::get_name $partition]"
            # tmsh::log "iCall: Processing Partition: $partition"
            tmsh::cd $partition
            set nodes [tmsh::get_config /ltm node]
            foreach node $nodes {
                # tmsh::log "Processing Node : $partition/[tmsh::get_name $node]"
                append nodelist "\"[tmsh::get_field_value $node "address"]\" \{ data \"[tmsh::get_name $node]\" \}\n"
                incr nodecounter
            }
            # tmsh::log "Finished Partition: $partition"
        }
        tmsh::cd "/Common"
        if { not ([tmsh::list /ltm data-group] contains "ltm data-group internal DG_IP_2_NODENAME") } then {
            tmsh::log "iCall: Created the data-group \"DG_IP_2_NODENAME\"."
            tmsh::create /ltm data-group internal "DG_IP_2_NODENAME" type "string"
        } else {
            # tmsh::log "iCall: The DataGroup does exist."
        }
        eval "tmsh::modify /ltm data-group internal DG_IP_2_NODENAME \{ records replace-all-with \{ $nodelist \} \}"
        tmsh::log "iCall: Updated the data-group DG_IP_2_NODENAME with \"$nodecounter\" entries."
    }
    description none
    events none
}
sys icall handler periodic DataGroup_NodeIP_to_NodeName {
    first-occurrence 2016-09-12:00:00:00
    interval 60
    script DataGroup_NodeIP_to_NodeName
}

Tested this on version:

12.0
Version history
Last update:
‎12-Sep-2016 04:59
Updated by:
Contributors