Forum Discussion
Naman_65674
Nimbostratus
Nov 06, 2008active_nodes and matchclass
Hi all,
I wanted to implement the following scenario:
if
hoolio
Cirrostratus
Nov 10, 2008Hi Naman,
What does your node_main datagroup contain? Is it IP addresses or IP addresses and ports? Can you run 'b class node_main list' to show the contents?
I'm not sure what the difference between active_nodes and active_members is. They seem to return the same output.
active_nodes -list will return a TCL list of the IP address and port for each member. You could save this output and then loop through it and compare the IP address and/or port to the contents of your node_main datagroup:
when RULE_INIT {
Create a list (instead of a datagroup) for testing
set ::node_main [list \
"1.1.1.1" \
"2.1.1.1" \
"3.1.1.1" \
]
}
when CLIENT_ACCEPTED {
Compare active_nodes output with active_members
log local0. "\[active_nodes -list \[LB::server pool\]\]: [active_nodes -list [LB::server pool]]"
log local0. "\[\[llength active_nodes -list \[LB::server pool\]\]\]: [llength [active_nodes -list [LB::server pool]]]"
log local0. "\[active_members -list \[LB::server pool\]\]: [active_members -list [LB::server pool]]"
log local0. "\[\[llength active_members -list \[LB::server pool\]\]\]: [llength [active_members -list [LB::server pool]]]"
Save the active members to a TCL list
set members [active_members -list [LB::server pool]]
Loop through the list and look up the IP address in the node_main "datagroup"
foreach a_member $members {
log local0. "Checking \$a_member: $a_member, [lindex $a_member 0]"
Get the IP address from the "IP port" list item and compare it against the node_main datagroup
if {[matchclass [lindex $a_member 0] eq $::node_main]}{
log local0. "Found $a_member in node_main datagroup"
Found match, so exit foreach loop
break
}
}
}
Here is an example which checks the port as well:
when RULE_INIT {
Create a list (instead of a datagroup) for testing
set ::node_main [list \
"1.1.1.1:80" \
"2.1.1.1:80" \
"3.1.1.1:80" \
"10.41.135.3:80" \
]
}
when CLIENT_ACCEPTED {
Compare active_nodes output with active_members
log local0. "\[active_nodes -list \[LB::server pool\]\]: [active_nodes -list [LB::server pool]]"
log local0. "\[\[llength active_nodes -list \[LB::server pool\]\]\]: [llength [active_nodes -list [LB::server pool]]]"
log local0. "\[active_members -list \[LB::server pool\]\]: [active_members -list [LB::server pool]]"
log local0. "\[\[llength active_members -list \[LB::server pool\]\]\]: [llength [active_members -list [LB::server pool]]]"
Save the active members to a TCL list
set members [active_members -list [LB::server pool]]
Loop through the list and look up the IP address and port in the node_main "datagroup"
foreach a_member $members {
Use string map to replace the space in the list element with a colon
log local0. "Checking \$a_member: $a_member, [string map {" " :} $a_member]"
if {[matchclass [string map {" " :} $a_member] eq $::node_main]}{
log local0. "Found [string map {" " :} $a_member] in node_main datagroup"
Found match, so exit foreach loop
break
}
}
}
Aaron
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects