def test_all_total_memory_percent_util(dev): parser = jxmlease.EtreeParser() res = parser(dev.rpc.get_route_engine_information()) # The 80% threshold is arbitrary and you might want to set different number in your env. # Also consider checking control and data plane memory utilization separately return int(res["route-engine-information"]["route-engine"] ["memory-system-total-util"]) < 80
def check_ospf_full_adjacencies(dev, neighbor_count): full_count = 0 parser = jxmlease.EtreeParser() res = parser(dev.rpc.get_ospf_neighbor_information()) for neighbor_data in res["ospf-neighbor-information"]["ospf-neighbor"]: if neighbor_data["ospf-neighbor-state"] == "Full": full_count += 1 else: return False return full_count == neighbor_count
def test_R1_arp_gateway(dev): R1_GW_CORRECT_ARP_ENTRY = { 'arp-table-entry-flags': { 'none': '' }, 'hostname': '10.10.0.1', 'interface-name': 'ge-0/0/3.0', 'ip-address': '10.10.0.1', 'mac-address': '00:0c:29:60:25:80' } parser = jxmlease.EtreeParser() res = parser(dev.rpc.get_arp_table_information()) # You can use res.prettyprint() to see the whole data structure for item in res['arp-table-information']['arp-table-entry']: if item == R1_GW_CORRECT_ARP_ENTRY: return True return False
def main(): """Main Program""" args = create_arg() csvfile = open(args.ping_result_file, 'w') fieldnames = ['user-name', 'session-id', 'ip-address', 'probes-sent', 'responses-received', 'packet-loss', 'rtt-minimum', 'rtt-average', 'rtt-maximum', 'rtt-stddev'] writer = csv.DictWriter(csvfile, fieldnames=fieldnames) writer.writeheader() parser = jxmlease.EtreeParser() dev = connect(args.host, args.username, args.password, args.port) for item in parse_csv_input_file(args.ping_input_file): if item['ip_address']: ping_result = parser(do_ping(dev, item['ip_address'], item['routing_instance'], args.count, args.rapid)) ping_ok, parse_summmary_dict = parse_summary(ping_result) if ping_ok: print_summary(parse_summmary_dict) # add username & ip address to dict. parse_summmary_dict['user-name'] = item['user_name'] parse_summmary_dict['session-id'] = item['session_id'] parse_summmary_dict['ip-address'] = item['ip_address'] writer.writerow(parse_summmary_dict) else: print("Ping failed to this session: {} reason: " "{}").format(item['session_id'], parse_summmary_dict.strip()) else: print(parse_summmary_dict) print("Skipping session-id: {} " "for missing ip address".format(item['session_id'])) # close dev dev.close() # close csv file csvfile.close()
def test_vsrx_SYSTEM_junos_version_193r1______(dev): parser = jxmlease.EtreeParser() res = parser(dev.rpc.get_software_information()) return res["software-information"]["junos-version"] == "19.3R1.8"
present, but is now not present. """ import sys import getpass import jxmlease from jnpr.junos import Device from jnpr.junos.utils.config import Config import jnpr.junos.exception TEMPLATE_PATH = 'interface_descriptions_template.xml' # Create a jxmlease parser with desired defaults. parser = jxmlease.EtreeParser() class DoneWithDevice(Exception): pass def main(): """The main loop. Prompt for a username and password. Loop over each device specified on the command line. Perform the following steps on each device: 1) Get LLDP information from the current device state. 2) Get interface descriptions from the device configuration. 3) Compare the LLDP information against the previous snapshot of LLDP