Forum Discussion

Nik's avatar
Nik
Icon for Cirrus rankCirrus
Oct 29, 2012

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?

 

  • 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
    
  • tmsh

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

     

  • 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.

     

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

     

  • I make some modification on the basis, and output the vs-pool-pool_member, like this

     

    [root@lab-1:Active:Standalone] config # sh network-map-output.sh 10.128.1.245

    Searching for 10.128.1.245 in LTM config ...

    dns_listener (10.128.10.230 on port 53/udp)

      Pool: bind_server_pool

         ---> 10.128.20.11 on port 53

         ---> 10.128.20.12 on port 53

         ---> 10.128.20.13 on port 53

    p80_virtual1 (10.128.10.20 on port 80/tcp)

      Pool: p80_pool_11-12

         ---> 10.128.20.11 on port 53

         ---> 10.128.20.12 on port 53

    p80_virtual2 (10.128.10.30 on port 80/tcp)

      Pool: p80_pool_13-14

         ---> 10.128.20.13 on port 53

         ---> 10.128.20.14 on port 80

    vs_https_need_to_del (10.242.136.15 on port 443/tcp)

      Pool: p80_pool_11-12

         ---> 10.128.20.11 on port 53

         ---> 10.128.20.12 on port 53

    vs_policy (10.128.10.201 on port any/tcp)

      Pool: iRules_pool11

         ---> 10.128.20.11 on port 53

    vs_temp_need_to_del (10.242.136.1 on port 4488/tcp)

      Pool: bind_server_pool

         ---> 10.128.20.11 on port 53

         ---> 10.128.20.12 on port 53

         ---> 10.128.20.13 on port 53

     

     

    ============================================================================================

    tmsh_mod="tmsh -q"

     

    echo "Searching for $1 in LTM config ... "

     

    vs_list=$( $tmsh_mod list ltm virtual one-line | grep " pool" | awk '{print $3}')

     

     

    for vs in $vs_list

    do

      vs_protocol=$($tmsh_mod list ltm virtual $vs | awk '$1=="ip-protocol" {print $2}')

      vs_ip_port=$($tmsh_mod list ltm virtual $vs | awk '$1=="destination" {print $2}')  

      vs_ip=$(echo $vs_ip_port | awk -F: '{print $1}' )

      vs_port_name=$(echo $vs_ip_port | awk -F: '{print $2}' )

    vs_pool_name=$($tmsh_mod list ltm virtual $vs | awk '$1=="pool" {print $2}')  

      if [ "$(grep $vs_protocol /etc/services | awk '$1=="'$vs_port_name'" {print $2}')" ]  

      then

        vs_port=$(grep $vs_protocol /etc/services | awk '$1=="'$vs_port_name'" {print $2}')  

      else

        vs_port=$(echo "$vs_port_name/$vs_protocol")

      fi  

     

      echo "$vs ($vs_ip on port $vs_port)"

    pool_member_addr_list=$($tmsh_mod list ltm pool $vs_pool_name | awk '$1=="address" {print $2}' )

    echo "  Pool: $vs_pool_name"

    for pool_member_addr in $pool_member_addr_list

    do

      

    pool_member_port_name=$($tmsh_mod list ltm pool $pools_pool | grep $pool_member_addr | grep addr -B1 | awk -F: 'NR==1 {print $2}' | awk ' {print $1}' )

    the_name_map_to_port_requirement=$(grep $vs_protocol /etc/services | awk '$1=="'$pool_member_port_name'" {print $2}')

        if [ "$the_name_map_to_port_requirement" ]

    then

    pool_member_port=$(echo $the_name_map_to_port_requirement | awk -F/ '{print $1}')

      else

    pool_member_port=$(echo $pool_member_port_name)

    fi

    echo "     ---> $pool_member_addr on port $pool_member_port"

    done

     

    done

     

    • Srikar's avatar
      Srikar
      Icon for Altostratus rankAltostratus

      output is giving whole network map. is it possible to filter only one virtual server details?