Forum Discussion
NathanAsky
Altostratus
Mar 19, 2025F5-SDK Get GTM Pool Server, Virtual Server, Unused Objects, and JSON Conversion for Data Processing
I am honored to be able to use the f5-sdk python compilation tool. I think it is great! Unfortunately, it is no longer supported for updates. Recently, when helping users process data, I wrote some python scripts to handle unused objects and output them in dictionary format. There will not be many updates later. If you are interested, you can update the code. f5-sdk.readthedocs.io
Some of the code is shown below. You can refer to the attachment!
It’s a great honor to study and discuss with you all!😇
from f5.bigip import ManagementRoot
import json
from tqdm import tqdm
"""
Author: Nathan'Asky
Date: 2025-03-14
Version: 1.0
Description: Read DNS Device ConfigInfo
"""
class GTMVisualProcessing:
def LoadAccount(self,HostName,User,Pass):
try:
ConnectMgmt = ManagementRoot(HostName,User,Pass)
return ConnectMgmt
except:
return "Device link failed. Check network and device availability!"
def GetWideipDic(self,ConnectMgmt,WideipsJsonPath):
try:
WideipData = []
for WideipType in tqdm(['a_s', 'aaaas', 'cnames','mxs'],desc="Processing Wideip", unit="Member"):
for wideip in getattr(ConnectMgmt.tm.gtm.wideips, WideipType).get_collection():
if '_meta_data' in wideip.raw:
del wideip.raw['_meta_data']
WideipData.append(wideip.raw)
with open(WideipsJsonPath, 'a', encoding='utf-8') as WideipsJsonFile:
json.dump(WideipData, WideipsJsonFile, ensure_ascii=False, indent=4)
del WideipData
except:
return "Data acquisition is abnormal; check the network connection!"
def GetPoolMemberDic(self,ConnectMgmt,PoolMemberJsonPath):
try:
PoolMemberData = []
PoolTypeDic = {'a_s':'a','aaaas':'aaaa','cnames':'cname','mxs':'mx'}
for PoolType in tqdm(PoolTypeDic.keys(), desc="Processing PoolMembers Types", unit="type"):
for pool in getattr(ConnectMgmt.tm.gtm.pools,PoolType).get_collection():
for PoolMember in getattr(getattr(ConnectMgmt.tm.gtm.pools, PoolType), PoolTypeDic.get(PoolType)).load(name=pool.raw['name']).members_s.get_collection():
if '_meta_data' in PoolMember.raw:
del PoolMember.raw['_meta_data']
PoolMember.raw.update(PoolName=pool.raw['name'])
PoolMemberData.append(PoolMember.raw)
with open(PoolMemberJsonPath, 'a', encoding='utf-8') as PoolMemberJsonFile:
json.dump(PoolMemberData, PoolMemberJsonFile, ensure_ascii=False, indent=4)
del PoolMemberData
except:
return "Data acquisition is abnormal; check the network connection!"
def GetPoolDic(self,ConnectMgmt,PoolJsonPath):
try:
PoolData = []
PoolTypeDic = {'a_s':'a','aaaas':'aaaa','cnames':'cname','mxs':'mx'}
for PoolType in tqdm(PoolTypeDic.keys(), desc="Processing PoolMembers Types", unit="type"):
for pool in getattr(ConnectMgmt.tm.gtm.pools,PoolType).get_collection():
if '_meta_data' in pool.raw:
del pool.raw['_meta_data']
PoolData.append(pool.raw)
with open(PoolJsonPath, 'a', encoding='utf-8') as PoolJsonFile:
json.dump(PoolData, PoolJsonFile, ensure_ascii=False, indent=4)
del PoolData
except:
return "Data acquisition is abnormal; check the network connection!"
def GetServerDic(self,ConnectMgmt,ServerJsonPath):
try:
ServerData = []
for server in tqdm(ConnectMgmt.tm.gtm.servers.get_collection(),desc="Processing Server", unit="Member"):
if '_meta_data' in server.raw:
del server.raw['_meta_data']
ServerData.append(server.raw)
with open(ServerJsonPath, 'a', encoding='utf-8') as ServerJsonFile:
json.dump(ServerData, ServerJsonFile, ensure_ascii=False, indent=4)
del ServerData
except:
return "Data acquisition is abnormal; check the network connection!"
def GetVirtualServerDic(self,ConnectMgmt,VirtualServerJsonPath):
try:
VirtualServerData = []
for server in tqdm(ConnectMgmt.tm.gtm.servers.get_collection(),desc="Processing VirtualServer", unit="Member"):
for VirtualServer in ConnectMgmt.tm.gtm.servers.server.load(name=server.raw['name']).virtual_servers_s.get_collection():
if '_meta_data' in VirtualServer.raw:
del VirtualServer.raw['_meta_data']
VirtualServer.raw.update(ServerName=server.raw['name'])
VirtualServerData.append(VirtualServer.raw)
with open(VirtualServerJsonPath, 'a', encoding='utf-8') as VirtualServerJsonFile:
json.dump(VirtualServerData, VirtualServerJsonFile, ensure_ascii=False, indent=4)
del VirtualServerData
except:
return "Data acquisition is abnormal; check the network connection!"
def GetMonitorDic(self,ConnectMgmt,MonitorJsonPath):
try:
MonitorData = []
for MonitorType in tqdm(["bigips", "bigip_links", "externals", "firepass_s", "ftps", "gateway_icmps", "gtps", "https", "https_s", "imaps", "ldaps", "mssqls", "mysqls", "nntps", "oracles", "pop3s", "postgresqls", "radius_s", "radius_accountings", "real_servers", "scripteds", "sips", "smtps", "snmps", "snmp_links", "soaps", "tcps", "tcp_half_opens", "udps", "waps", "wmis"],desc="Processing Monitor Type", unit="type"):
for Monitor in getattr(ConnectMgmt.tm.gtm.monitor,MonitorType).get_collection():
if '_meta_data' in Monitor.raw:
del Monitor.raw['_meta_data']
MonitorData.append(Monitor.raw)
with open(MonitorJsonPath, 'a', encoding='utf-8') as MonitorJsonFile:
json.dump(MonitorData, MonitorJsonFile, ensure_ascii=False, indent=4)
del MonitorData
except:
return "Data acquisition is abnormal; check the network connection!"
No RepliesBe the first to reply
Recent Discussions
Related Content
DevCentral Quicklinks
* 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
Discover DevCentral Connects