cancel
Showing results for 
Search instead for 
Did you mean: 

Problem this snippet solves:

This pyControl v2 script prints out status and statistics for LTM virtual servers and pools.

How to use this snippet:

This pyControl v2 script will print out status and statistics for all LTM virtual servers and pools.

Usage: ltmStats.py

Code :

#!/usr/bin/python
'''
----------------------------------------------------------------------------
 The contents of this file are subject to the "END USER LICENSE AGREEMENT FOR F5
 Software Development Kit for iControl"; you may not use this file except in
 compliance with the License. The License is included in the iControl
 Software Development Kit.

 Software distributed under the License is distributed on an "AS IS"
 basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
 the License for the specific language governing rights and limitations
 under the License.

 The Original Code is iControl Code and related documentation
 distributed by F5.

 The Initial Developer of the Original Code is F5 Networks,
 Inc. Seattle, WA, USA. Portions created by F5 are Copyright (C) 1996-2004 F5 Networks,
 Inc. All Rights Reserved.  iControl (TM) is a registered trademark of F5 Networks, Inc.

 Alternatively, the contents of this file may be used under the terms
 of the GNU General Public License (the "GPL"), in which case the
 provisions of GPL are applicable instead of those above.  If you wish
 to allow use of your version of this file only under the terms of the
 GPL and not to allow others to use your version of this file under the
 License, indicate your decision by deleting the provisions above and
 replace them with the notice and other provisions required by the GPL.
 If you do not delete the provisions above, a recipient may use your
 version of this file under either the License or the GPL.
----------------------------------------------------------------------------
'''
__author__ = "jason.rahm"

def get_virtuals(obj):
vips = obj.get_list()
status = obj.get_object_status(virtual_servers = vips)

combined = zip(vips,status)

for x in combined:
print "Virtual: ", x[0]
print "\t", x[1].availability_status
print "\t", x[1].enabled_status
print "\t", x[1].status_description
print "\n"*2

def get_pools(obj):
pools = obj.get_list()
status = obj.get_object_status(pool_names = pools)

combined = zip(pools,status)

for x in combined:
print "Pool: ", x[0]
print "\t", x[1].availability_status
print "\t", x[1].enabled_status
print "\t", x[1].status_description
print "\n"*2

def get_virtuals_stats(obj):
stats = obj.get_all_statistics()

for x in stats.statistics:
print "Virtual Server: ", x.virtual_server.name
for y in x.statistics:
print "\t%s = %s" % (y.type, (y.value.high<<32)|y.value.low)

def get_pools_stats(obj):
stats = obj.get_all_statistics()

for x in stats.statistics:
print "Pool: ", x.pool_name
for y in x.statistics:
print "\t%s = %s" % (y.type, (y.value.high<<32)|y.value.low)

if __name__ == "__main__":

import pycontrol.pycontrol as pc
import getpass
from sys import argv


if pc.__version__[:3] == '2.0':
pass
else:
print "Requires pycontrol version 2.x!"
sys.exit()

if len(argv) != 3:
exit("Usage ltmStats.py  ")

host = argv[1]
uname = argv[2]
upass = getpass.getpass()

b = pc.BIGIP(
hostname = host,
username = uname,
                password = upass,
                fromurl = True,
                wsdls = ['LocalLB.VirtualServer', 'LocalLB.Pool']
)

v = b.LocalLB.VirtualServer
p = b.LocalLB.Pool

print "Virtual Server status...\n"
get_virtuals(v)

print "Virtual Server stats...\n"
get_virtuals_stats(v)

print "Pool status...\n"
get_pools(p)

print "Pool stats...\n"
get_pools_stats(p)
Version history
Last update:
‎07-Mar-2015 16:22
Updated by:
Contributors