Difference between revisions of "F5 sdk snippets"
Jump to navigation
Jump to search
(3 intermediate revisions by the same user not shown) | |||
Line 12: | Line 12: | ||
session = requests.Session() | session = requests.Session() | ||
session.auth = (AD_USER, AD_PASS) | session.auth = (AD_USER, AD_PASS) | ||
+ | ``` | ||
## Virtuals | ## Virtuals | ||
Line 25: | Line 26: | ||
r = session.get(url, verify=False) | r = session.get(url, verify=False) | ||
r.json()['entries']['https://localhost/mgmt/tm/ltm/pool/~QA~vs_api.qa.example.com_int_https/stats']['nestedStats']['entries'] | r.json()['entries']['https://localhost/mgmt/tm/ltm/pool/~QA~vs_api.qa.example.com_int_https/stats']['nestedStats']['entries'] | ||
+ | ``` | ||
+ | |||
+ | ``` | ||
+ | import pprint as pp | ||
+ | pools_url = f"https://{F5_HOST}/mgmt/tm/ltm/pool" | ||
+ | pools_rsp = session.get(pools_url) | ||
+ | for pool in pools_rsp.json()['items']: | ||
+ | print(pool['name'], pool['partition']) | ||
+ | pool_stats_url = f"https://{F5_HOST}/mgmt/tm/ltm/pool/~{pool['partition']}~{pool['name']}/stats" | ||
+ | pool_stats_url_local = f"https://localhost/mgmt/tm/ltm/pool/~{pool['partition']}~{pool['name']}/stats" | ||
+ | pool_stats_rsp = session.get(pool_stats_url) | ||
+ | pool_stats = pool_stats_rsp.json()['entries'][pool_stats_url_local]['nestedStats']['entries'] | ||
+ | serverside_bitsOut = pool_stats['serverside.bitsOut']['value'] | ||
+ | serverside_bitsIn = pool_stats['serverside.bitsIn']['value'] | ||
+ | status_availabilityState = pool_stats['status.availabilityState']['description'] | ||
+ | print(f"{F5_HOST}~{pool['partition']}~{pool['name']} {serverside_bitsIn} {serverside_bitsOut} {status_availabilityState}") | ||
+ | # pp.pprint(pool_stats) | ||
+ | break | ||
``` | ``` | ||
## Members (Pool) | ## Members (Pool) | ||
+ | ``` | ||
+ | url = "https://{F5_HOST}/mgmt/tm/ltm/pool/~QA~vs_api.qa.example.com_int_https/members" | ||
+ | ``` | ||
## Nodes | ## Nodes | ||
+ | ``` | ||
+ | url = "https://{F5_HOST}/mgmt/tm/ltm/node/~QA~foo-backend~/stats" | ||
+ | url = https://{F5_HOST}/mgmt/tm/ltm/node | ||
+ | ``` |
Latest revision as of 19:04, 10 September 2023
import requests import os requests.packages.urllib3.disable_warnings() F5_HOST = os.getenv('AD_HOST') AD_USER = os.getenv('AD_USER') AD_PASS = os.environ.get('AD_PASS') url = f"https://{F5_HOST}/mgmt/tm/ltm/virtual" session = requests.Session() session.auth = (AD_USER, AD_PASS)
Virtuals
r = session.get(url, verify=False) r.json()['entries']['https://localhost/mgmt/tm/ltm/virtual/~QA~vs_api.qa.example.com_int_https/stats']['nestedStats']['entries']
Pools
url = f"https://{F5_HOST}/mgmt/tm/ltm/pool" url = "https://{F5_HOST}/mgmt/tm/ltm/pool/~QA~vs_api.qa.example.com_int_https/stats" r = session.get(url, verify=False) r.json()['entries']['https://localhost/mgmt/tm/ltm/pool/~QA~vs_api.qa.example.com_int_https/stats']['nestedStats']['entries']
import pprint as pp pools_url = f"https://{F5_HOST}/mgmt/tm/ltm/pool" pools_rsp = session.get(pools_url) for pool in pools_rsp.json()['items']: print(pool['name'], pool['partition']) pool_stats_url = f"https://{F5_HOST}/mgmt/tm/ltm/pool/~{pool['partition']}~{pool['name']}/stats" pool_stats_url_local = f"https://localhost/mgmt/tm/ltm/pool/~{pool['partition']}~{pool['name']}/stats" pool_stats_rsp = session.get(pool_stats_url) pool_stats = pool_stats_rsp.json()['entries'][pool_stats_url_local]['nestedStats']['entries'] serverside_bitsOut = pool_stats['serverside.bitsOut']['value'] serverside_bitsIn = pool_stats['serverside.bitsIn']['value'] status_availabilityState = pool_stats['status.availabilityState']['description'] print(f"{F5_HOST}~{pool['partition']}~{pool['name']} {serverside_bitsIn} {serverside_bitsOut} {status_availabilityState}") # pp.pprint(pool_stats) break
Members (Pool)
url = "https://{F5_HOST}/mgmt/tm/ltm/pool/~QA~vs_api.qa.example.com_int_https/members"
Nodes
url = "https://{F5_HOST}/mgmt/tm/ltm/node/~QA~foo-backend~/stats" url = https://{F5_HOST}/mgmt/tm/ltm/node