From aeaa8d8d14d22cf2a063ac188faa6d79d0c1e7f4 Mon Sep 17 00:00:00 2001 From: nick Date: Tue, 26 Jun 2018 16:38:50 -0400 Subject: [PATCH] WIP #1, updated parser --- plugins/filter/filter.py | 17 +++++++++++------ tests/test_iosxr_ospf_neighbor.yml | 6 +++--- tests/test_nxos_ospf_neighbor.yml | 6 +++--- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/plugins/filter/filter.py b/plugins/filter/filter.py index 9546bbc..141e7fc 100644 --- a/plugins/filter/filter.py +++ b/plugins/filter/filter.py @@ -179,7 +179,7 @@ def nxos_ospf_neighbor(text): (?P\d+)\s+ (?P\w+)/\s* (?P[A-Z-]+)\s+ - (?P[0-9:]+)\s+ + (?P[0-9:hdwy]+)\s+ (?P\d+\.\d+\.\d+\.\d+)\s+ (?P[0-9A-Za-z./-]+) """ @@ -510,7 +510,7 @@ def iosxr_ospf_neighbor(text): (?P[A-Z-]+)\s+ (?P[0-9:]+)\s+ (?P\d+\.\d+\.\d+\.\d+)\s+ - (?P[0-9:]+)\s+ + (?P[0-9:hdwy]+)\s+ (?P[0-9A-Za-z./-]+) """ return FilterModule._ospf_neighbor( @@ -541,10 +541,15 @@ def _ospf_neighbor(pattern, text, time_keys=None): # the math to convert hh:mm:ss to an integer of summed seconds. if time_keys: for k in time_keys: - times = gdict[k].split(':') - parts = [FilterModule._try_int(t) for t in times] - totalsec = parts[0] * 3600 + parts[1] * 60 + parts[2] - gdict.update({k + '_sec': totalsec}) + if gdict[k].count(':') == 2: + times = gdict[k].split(':') + parts = [FilterModule._try_int(t) for t in times] + secsum = parts[0] * 3600 + parts[1] * 60 + parts[2] + gdict.update({k + '_sec': secsum}) + else: + # Issue #1, short term fix, static value of 0. + # This information isn't used anywhere yet. + gdict.update({k + '_sec': 0}) ospf_neighbors.append(gdict) diff --git a/tests/test_iosxr_ospf_neighbor.yml b/tests/test_iosxr_ospf_neighbor.yml index 662c374..007df0e 100644 --- a/tests/test_iosxr_ospf_neighbor.yml +++ b/tests/test_iosxr_ospf_neighbor.yml @@ -8,7 +8,7 @@ Area 0 Neighbor ID Pri State Dead Time Address Up Time Interface - 192.168.0.11 0 FULL/DR 00:00:32 192.168.1.11 00:18:57 Gi0/0/0/0.511 + 192.168.0.11 0 FULL/DR 00:00:32 192.168.1.11 1y1w4d2h Gi0/0/0/0.511 192.168.0.12 1 FULL/ - 00:01:32 192.168.1.12 01:18:57 Gi1/2/3/4.512 Area 51 @@ -34,8 +34,8 @@ - "data[0].deadtime == '00:00:32'" - "data[0].deadtime_sec == 32" - "data[0].peer == '192.168.1.11'" - - "data[0].uptime == '00:18:57'" - - "data[0].uptime_sec == 1137" + - "data[0].uptime == '1y1w4d2h'" + - "data[0].uptime_sec == 0" # issue #1 - "data[0].intf | lower == 'gi0/0/0/0.511'" msg: "parsing problem. see JSON dump from previous task" diff --git a/tests/test_nxos_ospf_neighbor.yml b/tests/test_nxos_ospf_neighbor.yml index 8e9d44f..fd78a02 100644 --- a/tests/test_nxos_ospf_neighbor.yml +++ b/tests/test_nxos_ospf_neighbor.yml @@ -5,7 +5,7 @@ OSPF Process ID 1 VRF default Total number of neighbors: 2 Neighbor ID Pri State Up Time Address Interface - 2.2.2.2 1 FULL/ - 00:06:47 192.168.0.2 Eth1/43 + 2.2.2.2 1 FULL/ - 1y2w3d4h 192.168.0.2 Eth1/43 2.255.2.0 255 2WAY/BDR 21:01:05 10.192.17.6 Port-Cha1 - name: "Perform parsing" @@ -24,8 +24,8 @@ - "data[0].priority == 1" - "data[0].state == 'full'" - "data[0].role == '-'" - - "data[0].uptime == '00:06:47'" - - "data[0].uptime_sec == 407" + - "data[0].uptime == '1y2w3d4h'" + - "data[0].uptime_sec == 0" # issue #1 - "data[0].peer == '192.168.0.2'" - "data[0].intf == 'eth1/43'"