Nov-07-2023, 09:49 PM
I know that there are cisco python libs to login and execute CLI and get output , is there such a ting for Juniper/JUNOS?
currently I use the paramiko lib like below but it is a PITA , might be better with vendor supported libs
currently I use the paramiko lib like below but it is a PITA , might be better with vendor supported libs
#!/usr/bin/python3 import paramiko server = "10.228.9.75" un = "username" pw = "password" poolArray = ["pools"] ssh = paramiko.client.SSHClient() ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) cmd_to_execute = "show security nat resource-usage source-pool all" ssh.connect(server, username=un, password=pw) ssh_stdin, ssh_stdout, ssh_stderr = ssh.exec_command(cmd_to_execute) x = 1 for line in ssh_stdout: try: lineArray = line.strip().split() if "node" in lineArray[0]: nodeIs = lineArray[0] if "%" in lineArray[5]: #print (nodeIs +" " + lineArray[0]) #poolArray.append(nodeIs +" " + lineArray[0]) poolArray.append(lineArray[0]) except Exception as e: pass x = x + 1 ssh.close() poolVals = "" #print(len(poolVals)) #print (len(poolArray)) for pool in poolArray: ssh = paramiko.client.SSHClient() ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) #cmd_to_execute = '"show security nat resource-usage source-pool ' + pool + "\"" cmd_to_execute = "show security nat resource-usage source-pool " + pool #print(cmd_to_execute) ssh.connect(server, username=un, password=pw) ssh_stdin, ssh_stdout, ssh_stderr = ssh.exec_command(cmd_to_execute) #print(ssh_stdout) x =1 for line in ssh_stdout: lineArray = line.strip().split() if "%" in line and "-" not in line: if int(lineArray[6].replace("%","")) > 10: print (pool + ": " + str(x) + " " + line.strip()) y = str(pool) + ": " + str(x) + " " + str(line) poolVals = poolVals + y x = x + 1 ssh.close() print(len(poolVals)) if len(poolVals) > 1: print("dump") print (poolVals) print("end")