Search This Blog

Tuesday, July 16, 2013

Ways to parse tmsh output and automate task on F5

Problem

How to parse the output from tmsh shell.
How to write your own scripts to automate manual or complex actions on the F5 load balancer.

Solution

By default the 'show' action generate human readable output. With the additional option 'field-fmt' you can generate more machine-readable format that is more suitable for parsing.
 
lbal1(Active)(tmos.ltm.virtual)# show vs_1.1.1.1

Ltm::Virtual Server: vs_1.1.1.1
---------------------------------------------------------
Status
  Availability     : available
  State            : enabled
  Reason           : The virtual server is available
  CMP              : enabled
  CMP Mode         : all-cpus


Traffic                    ClientSide  Ephemeral  General
  Bits In                       89.1G          0        -
  Bits Out                       1.1T          0        -
  Packets In                    89.5M          0        -
  Packets Out                  124.7M          0        -
  Current Connections              54          0        -
  Maximum Connections             334          0        -
  Total Connections              2.6M          0        -
  Min Conn Duration/msec            -          -      367
  Max Conn Duration/msec            -          -   186.4M
  Mean Conn Duration/msec           -          -    84.1K
  Total Requests                    -          -     6.0M

 
lbal1(Active)(tmos.ltm.virtual)# show vs_1.1.1.1 field-fmt
ltm virtual vs_1.1.1.1 {
    clientside.bits-in 89.1G
    clientside.bits-out 1.1T
    clientside.cur-conns 67
    clientside.max-conns 334
    clientside.pkts-in 89.5M
    clientside.pkts-out 124.7M
    clientside.tot-conns 2.6M
    cs-max-conn-dur 186.4M
    cs-mean-conn-dur 76.7K
    cs-min-conn-dur 367
    ephemeral.bits-in 0
    ephemeral.bits-out 0
    ephemeral.cur-conns 0
    ephemeral.max-conns 0
    ephemeral.pkts-in 0
    ephemeral.pkts-out 0
    ephemeral.tot-conns 0
    name vs_95.138.158.17
    tot-requests 6.0M
    virtual-server.cmp-enable-mode all-cpus
    virtual-server.cmp-enabled enabled
    virtual-server.status.availability-state available
    virtual-server.status.enabled-state enabled
    virtual-server.status.status-reason The virtual server is available
}

To create your own scripts you can use grep to parse the output above or take it to the next level and write a native script in TCL using the tmsh API.

References
  1. https://devcentral.f5.com/wiki/TMSH.ConfigSearch.ashx
  2. https://devcentral.f5.com/community/group/aft/1180665/asg/53
  3. https://devcentral.f5.com/wiki/TMSH.tmsh__get_config.ashx
  4. https://devcentral.f5.com/wiki/TMSH.tmsh__get_status.ashx

No comments:

Post a Comment