Forum Discussion
list pools a node is in via tmsh
- Oct 29, 2012
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!
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 ...
I personally find this super annoying.
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
Recent Discussions
Related Content
* 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