Forum Discussion
Get list of monitors through SDK
I am trying to mimic the Health Monitors section from a pool properties page from the BigIP gui. I need to get a list of all monitors so I can construct a select field in a web page. I have tried several versions of:
for monitor in mgmt.tm.ltm.monitor.get_collection():
for item in monitor.get_collection():
pprint(item)
But, this obviously doesn't work. If I could get a list of the monitor types I could iterate through them, but I can't seem to get a list of types either.
- amintej
Cirrus
'monitor' is another collection with the various monitor types collections inside. You can access to the monitor type collections. Example for TCP:
tcps_monitors = mgmt.tm.ltm.monitor.tcps.get_collection() for monitor in tcps_monitors: print "TCP monitors:" print monitor.name print monitor.interval print monitor.timeout
- Satoshi_Toyosa1Ret. Employee
From tmsh, type list ltm monitor and TAB completion. You will find the list of monitor types.
In iControl REST, the /mgmt/tm/ltm/monitor returns a list of objects. Each object represents the endpoint for a type: e.g.,
{ "reference": { "link": "https://localhost/mgmt/tm/ltm/monitor/diameter?ver=13.1.0" } },
For curl users, it's as simple as grepping the link lines:
curl -sku admin: https://localhost/mgmt/tm/ltm/monitor | python -m json.tool | grep link
In Python API, the object is represented as dict, so you can do something like this:
from f5.bigip import ManagementRoot mgmt = ManagementRoot('mgmtPort', 'user', 'pass') monitor = mgmt.tm.ltm.monitor.get_collection() for t in monitor: print(t['reference']['link'])
You can use the link value as is to obtain the monitors under a specific type.
- Satoshi_Toyosa1Ret. Employee
for t in monitorTypes: endp = 'mgmt.tm.ltm.monitor.' + t + '.get_collection()' try: e = eval(endp) Get list eList = map(lambda x: x.name, e) print('{}: {}'.format(t, ','.join(eList))) except AttributeError: print('{} does not exist.'.format(t))
The code would yield something like this (truncated):
diameters: diameter dns_s: dns externals: external firepass_s: firepass ftps: ftp gateway_icmps: gateway_icmp https: http,http_head_f5 https_s: https,https_443,https_head_f5 ...
Recent Discussions
Related Content
* 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