F5 sdk

From UVOO Tech Wiki
Revision as of 22:28, 6 August 2023 by Busk (talk | contribs)
Jump to navigation Jump to search

SDK

More

https://community.f5.com/t5/technical-forum/python-f5-sdk-401-unexpected-error-f5-authorization-required/td-p/167675

https://community.f5.com/t5/technical-forum/get-list-of-monitors-through-sdk/td-p/120088

https://community.f5.com/t5/technical-articles/tinkering-with-the-bigrest-python-sdk-part-2/ta-p/285190

Monitors

https://community.f5.com/t5/technical-forum/using-the-python-sdk-for-monitors/td-p/231801

Stats

https://community.f5.com/t5/technical-forum/how-do-i-get-pool-stats-using-f5-sdk/td-p/86748

Code Examples

from f5.bigip import ManagementRoot
from f5.utils.responses.handlers import Stats

#Authentication
mgmt = ManagementRoot("***", "***", "***")

#Print tmos version
file = open('Availability.txt', 'w')
TMOS = "TMOS version - " + mgmt.tmos_version
print(TMOS)
file.write(TMOS + '\n')

#Get a collection of all Virtual Servers, pools
all_vips = mgmt.tm.ltm.virtuals.get_collection()
all_pools = mgmt.tm.ltm.pools.get_collection()

#Loop over all virtual servers and fetch name and availability
for vip in all_vips:
    vip_stats = Stats(vip.stats.load())
    State = vip_stats.stat.status_availabilityState['description']
    file.write(vip.name + " - " + State + '\n')

#Loop over all pools
for pool in all_pools:
    pool_stats = Stats(pool.stats.load())
    State = pool_stats.stat.status_availabilityState['description']
    file.write(pool.name + " - " + State + '\n')
    #Loop over all pool members
    for member in pool.members_s.get_collection():
        member_stats = Stats(member.stats.load())
        State = member_stats.stat.status_availabilityState['description']
        file.write(member.name + " - " + State + '\n')