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

Filter by:
  • Solution
  • Technology
Answers

list pools a node is in via tmsh

before i write a wrapper script for tmsh does anyone know if there's a simple way to find out what pools a single member is in?

0
Rate this Question
Comments on this Question
Comment made 04-Oct-2017 by The-messenger 355

Found this thread looking for the same data. I'd like to clean up unused nodes, as we move out of a data center. None of these submitted solutions return any data for me.

0
Comment made 04-Oct-2017 by cjunior 1819

Hi, you could try to generate a QKVIEW and upload it to https://ihealth.f5.com, so, you'll get check diagnostics including unused objects.

Regards.

0

Answers to this Question

placeholder+image
USER ACCEPTED ANSWER & F5 ACCEPTED ANSWER

I would recommend using the "one-line" parameter to help ensure you don't get false positives due to the vagaries of configuration lengths.

tmsh -q list ltm pool one-line | grep -E '($node_hostname|$node_ip)' | awk '{ print $3 }'
1
Comments on this Answer
Comment made 16-Dec-2014 by J Massaglia 0
Wow, that one-line argument makes it so much easier to work with! Thanks for sharing it.
0
placeholder+image
USER ACCEPTED ANSWER & F5 ACCEPTED ANSWER

Something like this should do the trick;

 list ltm pool | grep -B 20 x.x.x.x | grep ltm pool 

The -B 20 specifies the display of twenty 'lines' of output prior to the match for x.x.x.x. If you have pools with many members you may want to increase the value. Each node in a pool takes three lines, each pool name takes 2. So 20 should suffice for pools with up to six members but of course beware that the value isn't too high either else you'll potentially see pool names that the node isn't a member of.

0
placeholder+image
USER ACCEPTED ANSWER & F5 ACCEPTED ANSWER
i think tmsh's confirmation is getting in the way of this executing. when i pipe the output to grep it hangs indefinitely. here's an example of my confirmation:

nambrosch@dqulb01(Active)(tmos.ltm)# list pool
Display all 969 items? (y/n) n
0
placeholder+image
USER ACCEPTED ANSWER & F5 ACCEPTED ANSWER
OK, I've tested further using this to show line numbers and whatever the -B value grep seems smart enough not to duplicate matches;
list ltm pool | grep -B 30 x.x.x.x | grep -n ltm pool
0
placeholder+image
USER ACCEPTED ANSWER & F5 ACCEPTED ANSWER
the prompt was getting in the way of the remainder of the commands executing. to combat i did this:

echo y | tmsh list ltm pool|grep -B 20 10.5.72.109 | grep "ltm pool"|awk '{print $3}'


works great now!
0
placeholder+image
USER ACCEPTED ANSWER & F5 ACCEPTED ANSWER
Looks good, what does the awk command do?
0
placeholder+image
USER ACCEPTED ANSWER & F5 ACCEPTED ANSWER
i used it to print out the third parameter, which is the pool name.
0
placeholder+image
USER ACCEPTED ANSWER & F5 ACCEPTED ANSWER
Ah OK, nice. Thanks
0
placeholder+image
USER ACCEPTED ANSWER & F5 ACCEPTED ANSWER
the prompt was getting in the way of the remainder of the commands executing.

just in case if you have not yet seen this tmsh option.
 

          -q Prevents tmsh from responding to user actions with questions. This
          option is useful when writing non-interactive shell scripts from
          the system shell.
0
placeholder+image
USER ACCEPTED ANSWER & F5 ACCEPTED ANSWER

you can also use the "display-threshold" preference to stop tmsh from giving you the "display all items" prompt (set to some reasonably large number for your environment):

# modify cli preference display-threshold 500

0
placeholder+image
USER ACCEPTED ANSWER & F5 ACCEPTED ANSWER

Hi all,

I found this post while attempting to do something very similar, and thought I'd share what I came up with. It's my first time posting code on devcentral, so hopefully it comes through with the formatting in tact. FYI I'm running this directly on the LTM, version 11.2.1

Caveats:
1. The script uses full output of 'tmsh list' a lot, but I don't think there's any way around that.
2. Short of rolling my own tmsh output / ltm config parser, there are some silly grep/awk tricks in here. If you run it in your environment and it screws up due to more levels of nested brackets, etc - let me know and I'd be happy to try to update it.
3. Only default pools are being looked at - if there's an irule or something that steers traffic, the script won't pick that up.

Here's an example output (names/IPs changed from my work environment):

#./map.sh 192.168.0.10
Searching for 192.168.0.10 in LTM config ...
  pool_web_servers (session monitor-enabled, state up)
    --> vs_website01 (192.168.1.80 on port 80/tcp)
    --> vs_website01-https (192.168.1.80 on port 443/tcp)

  pool_ssh_servers (session monitor-enabled, state up)
    --> vs_login_pool (192.168.1.22 on port 22/tcp)

Anyway, of course standard disclaimer applies (ymmv, "no warranty or guarantee of fit for any purpose is expressed or implied", don't run this in production without testing it in your environment first!! yadda yadda yadda ... ) - hope this is helpful to someone out there!
-Josh

#!/bin/bash

# Eventually, some nicer input handling would be great
: ${1:?"The first argument of this script is the IP address to find.  Example: ./map.sh 192.168.1.1"}
IP=$1

# Just in case you want to modify the invocation of tmsh
TMSH='tmsh -q';

echo "Searching for $IP in LTM config ... ";

# This outputs Node->Pool->VS ... opposite of the GUI
for POOL in `$TMSH list /ltm pool one-line | grep $1: | awk '{print $3}'`; do
        # Get session and state info from the pool listing
        session=`$TMSH list /ltm pool $POOL members | grep -A30 "address $1" | grep -m 1 -B30 "}" | grep "session " | awk '{print $2}'`
        state=`$TMSH list /ltm pool $POOL members | grep -A30 "address $1" | grep -m 1 -B30 "}" | grep "state " | awk '{print $2}'`

        # Spit out info on the pool membership
        echo "  $POOL (session $session, state $state)";

        # Now go trolling through all the VSs for any one that has this pool as its default pool
        for VIRTUAL in `$TMSH list /ltm virtual one-line | grep $POOL | awk '{print $3}'`; do
                # Get the IP address and service port
                destination=`$TMSH list ltm virtual $VIRTUAL | grep destination | awk '{print $2}'`

                # F5 uses names of ports from /etc/services instead of numbers ...
                # <rant> I personally find this super annoying. </rant>

                # Figure out if it's tcp or udp (or sctp)
                protocol=`$TMSH list ltm virtual $VIRTUAL | grep ip-protocol | awk '{print $2}'`
                # Split out the IP ...
                vs_ip=`echo $destination | cut -f1 -d':'`
                # ... and the name of the service port
                vs_svc_name=`echo $destination | cut -f2 -d':'`
                # Now find it in /etc/services
                vs_svc_port=`grep $protocol /etc/services | awk '$1 == "'$vs_svc_name'" {print $2}'`

                # Finally, spit out the information about the VS
                echo "    --> $VIRTUAL ($vs_ip on port $vs_svc_port)";
        done;
        echo;
done
0
placeholder+image
USER ACCEPTED ANSWER & F5 ACCEPTED ANSWER

tmsh

(tmos)#list ltm pool | grep -b 20 x.x.x.x | grep ltm pool

0
placeholder+image
USER ACCEPTED ANSWER & F5 ACCEPTED ANSWER

Is there any way to find out a member in GTM pools?

0
placeholder+image
USER ACCEPTED ANSWER & F5 ACCEPTED ANSWER

tmsh list ltm pool one-line | grep xxx.xxx.xxx.xxx | awk '{print $3}' > test.txt

0