diff --git a/napalm/ios/ios.py b/napalm/ios/ios.py index c70d81a8f..3deff8c0e 100644 --- a/napalm/ios/ios.py +++ b/napalm/ios/ios.py @@ -1902,6 +1902,41 @@ def process_mac_fields(vlan, mac, mac_type, interface): return mac_address_table + def get_probes_config(self): + probes = {} + probes_regex = r"ip\s+sla\s+(?P\d+)\n" \ + "\s+(?P\S+)\s+(?P.*\n).*" \ + "\s+tag\s+(?P\S+)\n.*" \ + "\s+history\s+buckets-kept\s+(?P\d+)\n.*" \ + "\s+frequency\s+(?P\d+)$" + probe_args = { + 'icmp-echo': r"^(?P\S+)\s+source-(?:ip|interface)\s+(?P\S+)$" + } + probe_type_map = { + 'icmp-echo': 'icmp-ping', + } + command = "show run | include ip sla [0-9]" + output = self._send_command(command) + for match in re.finditer(probes_regex, output, re.M): + probe = match.groupdict() + if probe["probe_type"] not in probe_args: + # Probe type not supported yet + continue + probe_args_match = re.match(probe_args[probe["probe_type"]], + probe["probe_args"]) + probe_data = probe_args_match.groupdict() + probes[probe["id"]] = { + probe["name"]: { + 'probe_type': probe_type_map[probe["probe_type"]], + 'target': probe_data["target"], + 'source': probe_data["source"], + 'probe_count': int(probe["probe_count"]), + 'test_interval': int(probe["interval"]) + } + } + + return probes + def get_snmp_information(self): """ Returns a dict of dicts diff --git a/test/ios/mocked_data/test_get_probes_config/normal/expected_result.json b/test/ios/mocked_data/test_get_probes_config/normal/expected_result.json new file mode 100644 index 000000000..76935ad9c --- /dev/null +++ b/test/ios/mocked_data/test_get_probes_config/normal/expected_result.json @@ -0,0 +1,20 @@ +{ + "1": { + "test-google-8": { + "source": "Loopback0", + "probe_type": "icmp-ping", + "target": "8.8.8.8", + "test_interval": 3, + "probe_count": 20 + } + }, + "2": { + "test-google-4": { + "source": "1.1.1.1", + "probe_type": "icmp-ping", + "target": "8.8.4.4", + "test_interval": 3, + "probe_count": 20 + } + } +} diff --git a/test/ios/mocked_data/test_get_probes_config/normal/show_run___include_ip_sla__0_9_.txt b/test/ios/mocked_data/test_get_probes_config/normal/show_run___include_ip_sla__0_9_.txt new file mode 100644 index 000000000..f778ecef4 --- /dev/null +++ b/test/ios/mocked_data/test_get_probes_config/normal/show_run___include_ip_sla__0_9_.txt @@ -0,0 +1,14 @@ +ip sla 1 + icmp-echo 8.8.8.8 source-interface Loopback0 + tag test-google-8 + history lives-kept 1 + history buckets-kept 20 + timeout 2000 + frequency 3 +ip sla 2 + icmp-echo 8.8.4.4 source-ip 1.1.1.1 + tag test-google-4 + history lives-kept 1 + history buckets-kept 20 + timeout 2000 + frequency 3 \ No newline at end of file