Created
May 26, 2023 17:11
-
-
Save f5-rahm/07d73e496a0f49568465b8cadfbe8a1b to your computer and use it in GitHub Desktop.
Download LTM pool members stats from all partitions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from bigrest.bigip import BIGIP | |
from time import sleep | |
import argparse | |
import getpass | |
import sys | |
def build_parser(): | |
parser = argparse.ArgumentParser() | |
parser.add_argument("host", help="BIG-IP IP/FQDN") | |
parser.add_argument("user", help="BIG-IP Username") | |
return parser.parse_args() | |
def instantiate_bigip(host, user): | |
pw = getpass.getpass(prompt=f"\n\tWell hello {user}, please enter your password: ") | |
try: | |
obj = BIGIP(host, user, pw, session_verify=False) | |
except Exception as e: | |
print(f"Failed to connect to {args.host} due to {type(e).__name__}:\n") | |
print(f"{e}") | |
sys.exit() | |
return obj | |
def deploy_script(): | |
# slurp the file | |
with open('poolstats.tcl') as f: | |
tmsh_script = f.read() | |
try: | |
cli_script = {'name': 'poolstats.tcl', 'apiAnonymous': tmsh_script} | |
b.create('/mgmt/tm/cli/script', cli_script) | |
except Exception as e: | |
print(f'{e}') | |
sys.exit() | |
def run_poolstats(b): | |
try: | |
data = {'command': 'run', 'name': '/Common/poolstats.tcl', 'utilCmdArgs': ''} | |
b.command('/mgmt/tm/cli/script', data) | |
except Exception as e: | |
print(f'{e}') | |
def download_poolstats_data(b): | |
try: | |
b.download('/mgmt/cm/autodeploy/software-image-downloads', 'poolstats.csv') | |
except Exception as e: | |
print(f'{e}') | |
if __name__ == "__main__": | |
args = build_parser() | |
b = instantiate_bigip(args.host, args.user) | |
if not b.exist('/mgmt/tm/cli/script/poolstats.tcl'): | |
deploy_script() | |
run_poolstats(b) | |
# might need to add a delay here if the file write takes a long time with big configs | |
# sleep(30) | |
download_poolstats_data(b) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use this in conjunction with https://gist.github.com/f5-rahm/c523f88717a7fa2d6d6d12af5b022057