Forum Discussion
Cheers.
Lot more messy, but works.
If anyone else wants basic outline of the code ...
f5nodename='an_f5_target'
node = f5cli.F5(f5nodename,'asimpleaccount','asimplepassword')
r = node.invoke('ltm/virtual/stats')
counters = dict()
counters['vips'] = 0
if r.status_code == 200:
fh = open(timeStamped(fmt='%Y%m%d') + '.' + f5nodename + '.dat','w+')
rtnData = r.json()['entries']
for vs in rtnData:
counters['vips'] += 1
enableState = rtnData[vs]['nestedStats']['entries'].get('status.enabledState',{"description":'N/A'})['description']
availableState = rtnData[vs]['nestedStats']['entries'].get('status.availabilityState',{"description":'N/A'})['description']
reasonState = rtnData[vs]['nestedStats']['entries'].get('status.statusReason',{"description":'N/A'})['description']
output = "\t".join([vs.replace('/stats/',''), enableState, availableState, reasonState])
print(output)
if availableState != 'available':
fh.write(output + "\n")
if availableState not in counters:
counters[availableState] = 1
else:
counters[availableState] += 1
fh.close()
print('---------------------')
for counter, value in counters.items():
print(f"{counter} = {value}")
print('---------------------')
f5cli.F5 is my own super simple class to store the node and credentials and then invoke python 'requests' call.
prints some counters to screen and records all the none online entries in a file with reverse date and f5 name, for now.