Learn F5 Technologies, Get Answers & Share Community Solutions Join DevCentral

Filter by:
  • Solution
  • Technology
Answers

Get pool member NAMES in irule?

members -list and nodes -list produces a list of IP addresses of the pool members. Node command does not seem to have an option to get the node name from an IP. Is there any command that can retrieve the pool member names? Node names have to be specified when adding them, why would there not be an option to retrieve them from an irule?

0
Rate this Question

Answers to this Question

placeholder+image
USER ACCEPTED ANSWER & F5 ACCEPTED ANSWER

Hi Sas,

had some spare time in the evening to play around with iCall. The iCall script below will dump your Node Names and Node IPs of every single /Partition/ every 60 seconds into the datagroup "/Common/DG_IP_2_NODENAME". Enjoy... ;-)

sys icall script NodeList_2_Datagroup {
    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 NodeList_2_Datagroup {
    first-occurrence 2016-08-15:00:00:00
    interval 60
    script NodeList_2_Datagroup
}

Note: Tweak the periodic update interval (in seconds) as needed. Then use tmsh load sys config merge from-terminal to import and merge the partial configuration.

Cheers, Kai

1
Comments on this Answer
Comment made 08-Feb-2017 by Jonathan 67

Love this!

0
Comment made 08-Feb-2017 by Kai Wilke 6774

You're welcome^^ ;-)

Cheers, Kai

0
Comment made 08-Feb-2017 by Jonathan 67

this might be a dumb question, but once you have loaded the script, if you want to stop it, how do you do that? Do you just delete the .conf file and reload the config?

0
Comment made 08-Feb-2017 by Kai Wilke 6774

Hi Jonathan,

simply remove the periodic icall handler and script via...

[root@f5-02:Active:Standalone] config # tmsh delete sys icall handler periodic NodeList_2_Datagroup
[root@f5-02:Active:Standalone] config # tmsh delete sys icall script NodeList_2_Datagroup

Cheers, Kai

0
Comment made 08-Feb-2017 by Jonathan 67

Thanks again!

0
Comment made 17-Feb-2017 by Jonathan 67

We are running HA pairs. If i drop the icall script on the active, will that all sync to the standby or do i need to load it there as well?

0
Comment made 19-Feb-2017 by Kai Wilke 6774

Hi Jonathan,

you need to deploy the iCall script and handler just on one unit an then replicate the configuration within the device group. After that, the iCall script gets executed on each unit independently.

Cheers, Kai

0
Comment made 21-Feb-2017 by Jonathan 67

This is the version I ended up using. I added some logic to strip off the route domain and made it all lower case. I am running it every 24 hours. So far works like a charm.

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
}

Then I i reference the data group in my logging irule with set member_name [class match -value $member_ip eq nodename_dg]

0
placeholder+image
USER ACCEPTED ANSWER & F5 ACCEPTED ANSWER

Hi Sas,

unfortunately its not a build-in iRule functionality to resolve the name-labels of a member in given pool.

But you could resolve the names manually by creating a [datagroup] or [array] containing all the pool member IP/Port combinations and their name-labels.

Note: Sorry for providing an answer you may not wanted to hear... :-(

Cheers, Kai

0
Comments on this Answer
Comment made 15-Aug-2016 by sas 53

Thanks for the reply.

Unfortunately I wanted to avoid manually maintaining a list of name/address pairs.

I don't understand why this is not accessible given the names of the nodes are in the config, lookup would be pretty much same effort as other lookups that can be done, wonder why this was left out.

0
Comment made 15-Aug-2016 by Kai Wilke 6774

Hi Sas,

I guess this is because the [active_members -list] command exist much longer than the added name-label feature of the configuration. But who knows for sure...

You may also play around using a periodic iCall script to automatically generate/update the required datagroup entries of the currently configured nodes. It shouldn't be that difficult... ;-)

Cheers, Kai

0