Skip to content

Commit

Permalink
WIP #1, updated parser
Browse files Browse the repository at this point in the history
  • Loading branch information
nickrusso42518 committed Jun 26, 2018
1 parent 571079e commit aeaa8d8
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
17 changes: 11 additions & 6 deletions plugins/filter/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ def nxos_ospf_neighbor(text):
(?P<priority>\d+)\s+
(?P<state>\w+)/\s*
(?P<role>[A-Z-]+)\s+
(?P<uptime>[0-9:]+)\s+
(?P<uptime>[0-9:hdwy]+)\s+
(?P<peer>\d+\.\d+\.\d+\.\d+)\s+
(?P<intf>[0-9A-Za-z./-]+)
"""
Expand Down Expand Up @@ -510,7 +510,7 @@ def iosxr_ospf_neighbor(text):
(?P<role>[A-Z-]+)\s+
(?P<deadtime>[0-9:]+)\s+
(?P<peer>\d+\.\d+\.\d+\.\d+)\s+
(?P<uptime>[0-9:]+)\s+
(?P<uptime>[0-9:hdwy]+)\s+
(?P<intf>[0-9A-Za-z./-]+)
"""
return FilterModule._ospf_neighbor(
Expand Down Expand Up @@ -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)

Expand Down
6 changes: 3 additions & 3 deletions tests/test_iosxr_ospf_neighbor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"

Expand Down
6 changes: 3 additions & 3 deletions tests/test_nxos_ospf_neighbor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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'"

Expand Down

0 comments on commit aeaa8d8

Please sign in to comment.