Node Name
From Tech-Wiki
More actions
F5 BIG-IP iCall example that periodically enumerates LTM nodes and maintains an internal data group mapping node IP addresses to node names.
Purpose
The generated
nodename_dg data group can then be queried from an iRule when a node name is needed for a selected member address.Example lookup
set member_name [class match -value $member_ip eq nodename_dg]
Periodic iCall handler and script
# set member_name [class match -value $member_ip eq nodename_dg]
sys icall handler periodic node_names {
first-occurrence 2016-08-15:00:00:00
interval 43200
script node_names
}
sys icall script node_names {
app-service none
definition {
set node_rd ""
set node_no_rd ""
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]"
set node_rd [tmsh::get_field_value $node "address"]
set node_no_rd [string map {%1 "" %2 "" %3 "" %4 ""} $node_rd]
append nodelist "\"$node_no_rd\" \{ 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 nodename_dg") } then {
#tmsh::log "icall: created the data-group \"nodename_dg\"."
tmsh::create /ltm data-group internal "nodename_dg" type "string"
} else {
#tmsh::log "icall: the datagroup does exist."
}
eval "tmsh::modify /ltm data-group internal nodename_dg \{ records replace-all-with \{ $nodelist \} \}"
tmsh::log "icall: updated the data-group nodename_dg with \"$nodecounter\" entries."
}
description none
events none
}