Forum Discussion
Kai_Wilke
Sep 27, 2016MVP
Hi Phong,
below are the required steps to setup the iCall handler to create and periodically update a data-group containing your Virtual Server Name and their corresponding IPs...
1.) SSH to your LTM and enter TMSH
2.) Issue the command: load sys config merge from-terminal
3.) Copy and Paste the code below...
Note: You may want to tweak the interval of the iCall handler as needed...
sys icall script DataGroup_Virtual_to_IP {
app-service none
definition {
set virtual_list ""
set virtual_counter 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
foreach virtual [tmsh::get_config /ltm virtual] {
tmsh::log "Processing Node : $partition/[tmsh::get_name $virtual]"
set destination [lindex [split [tmsh::get_field_value $virtual "destination"] ":"] 0]
set destination [lindex [split $destination "%"] 0]
append virtual_list "\"[tmsh::get_name $virtual]\" \{ data \"$destination\" \}\n"
incr virtual_counter
}
tmsh::log "Finished Partition: $partition"
}
tmsh::cd "/Common"
if { not ([tmsh::list /ltm data-group] contains "ltm data-group internal DG_VS_2_IP") } then {
tmsh::log "iCall: Created the data-group \"DG_VS_2_IP\"."
tmsh::create /ltm data-group internal "DG_VS_2_IP" type "string"
} else {
tmsh::log "iCall: The DataGroup does exist."
}
eval "tmsh::modify /ltm data-group internal DG_VS_2_IP \{ records replace-all-with \{ $virtual_list \} \}"
tmsh::log "iCall: Updated the data-group DG_VS_2_IP with \"$virtual_counter\" entries."
}
description none
events none
}
sys icall handler periodic DataGroup_Virtual_to_IP {
first-occurrence 2016-09-27:00:00:00
interval 60
script DataGroup_Virtual_to_IP
}
4.) Hit CTRL+D to apply the config merge.
5.) After a short period, take a look to your LTM logfile and see the resulting log output.
6.) Verify that the data-group "DG_VS_2_IP" is successfully created.
7.) Write an iRule and see if it works...
when RULE_INIT {
log local0.debug "IP Address of Virtual Server \"VS_A\" is \"[class match -value "VS_A" equals DG_VS_2_IP]\""
}
8.) Verify once again the log output.
Cheers, Kai