networktocode / ntc-templates

TextFSM templates for parsing show commands of network devices
https://ntc-templates.readthedocs.io/
Other
1.1k stars 721 forks source link

Show Cisco IOS Show Interface Link template placing uptime in downtime column #1852

Closed paulbauer1 closed 3 weeks ago

paulbauer1 commented 4 weeks ago
ISSUE TYPE
TEMPLATE USING

cisco_ios_show_interface_link.textfsm

Value PORT (\S+)
Value NAME (.*?)
Value DOWNTIME ((00:00:00)|(([0-9]{1,2} year[s]? , )?([0-9]{1,2} week[s]?, )?([0-9]{1,2} day[s]?, )?([0-9]{1,2} hour[s]?, )?([0-9]{1,2} minute[s]? )?([0-9]{1,2} secs))|((([0-9]{1,2}y)?([0-9]{1,2}w)?([0-9]{1,2}d)([0-9]{1,2}h)?|[0-9]{1,2}:[0-9]{1,2}:[0-9]{1,2})))
Value SINCE (.+?)
Value UPTIME ((([0-9]{1,2}m)?([0-9]{1,2}w)?([0-9]{1,2}d)|[0-9]{1,2}:[0-9]{1,2}:[0-9]{1,2}))

Start
  ^\s*\^\s* -> EOF
  ^.*Invalid input detected.* -> EOF
  ^Load\s+for\s+
  # Capture time-stamp if vty line has command time-stamping turned on
  ^Time\s+source\s+is
  ^-+\s*$$
  ^\s*Port\s+Name\s+Down Time\s+Down Since\s*$$ -> DownSince
  ^\s*Port\s+Name\s+Down Time\s+Up Time\s*$$ -> UpTime
  ^\s*$$
  ^. -> Error

DownSince
  ^\s*${PORT}\s+${DOWNTIME}\s*$$ -> Record
  ^\s*${PORT}\s+${DOWNTIME}\s*${SINCE}\s*$$ -> Record
  ^\s*${PORT}\s+${NAME}\s*${DOWNTIME}\s*$$ -> Record
  ^\s*${PORT}\s+${NAME}\s*${DOWNTIME}\s+${SINCE}\s*$$ -> Record
  ^\s*$$
  ^. -> Error

UpTime
  ^\s*${PORT}\s+${NAME}\s+00:00:00\s+${UPTIME}?\s*$$ -> Record
  ^\s*${PORT}\s+${DOWNTIME}\s+${UPTIME}?\s*$$ -> Record
  ^\s*${PORT}\s+${NAME}\s+${DOWNTIME}\s*$$ -> Record
  ^\s*$$
  ^. -> Error
SAMPLE COMMAND OUTPUT
show interface link
Port            Name                         Down Time      Up Time
Gi1/0/1                                           00:00:00         12w5d
Gi1/0/2                                          21w2d
Gi1/0/3        PACS Computer       00:00:00         3d07h
Gi1/0/4        imaging equipment  00:00:00         21w2d
SUMMARY

The pattern I have been able to discern is that when the uptime value is a period of days the uptime value is placed in the downtime field and the 00:00:00 downtime value is appended to the name value.

STEPS TO REPRODUCE
from ntc_templates.parse import parse_output
vlan_output = (
        "Port           Name               Down Time      Up Time\n "
        "Gi1/0/1                          00:00:00       1w0d\n"
        "Gi1/0/2                          21w2d\n"
        "Gi1/0/3       PACS Computer      00:00:00       3d07h\n"
        "Gi1/0/4       imaging equipment  00:00:00       21w2d\n"
    )
vlan_parsed = parse_output(platform="cisco_ios", command="show interface link", data=vlan_output)
print(vlan_parsed)
EXPECTED RESULTS

[{'port': 'Gi1/0/1', 'name': ' ', 'downtime': '', 'since': '', 'uptime': '1w0d'}, {'port': 'Gi1/0/2', 'name': ' ', 'downtime': '21w2d', 'since': '', 'uptime': ''}, {'port': 'Gi1/0/3', 'name': 'PACS Computer', 'downtime': '00:00:00', 'since': '', 'uptime': '3d07h'}, {'port': 'Gi1/0/4', 'name': 'imaging equipment', 'downtime': '', 'since': '', 'uptime': '21w2d'}]

ACTUAL RESULTS

[{'port': 'Gi1/0/1', 'name': ' ', 'downtime': '', 'since': '', 'uptime': '1w0d'}, {'port': 'Gi1/0/2', 'name': ' ', 'downtime': '21w2d', 'since': '', 'uptime': ''}, {'port': 'Gi1/0/3', 'name': 'PACS Computer 00:00:00', 'downtime': '3d07h', 'since': '', 'uptime': ''}, {'port': 'Gi1/0/4', 'name': 'imaging equipment', 'downtime': '', 'since': '', 'uptime': '21w2d'}]

jmcgill298 commented 4 weeks ago

@paulbauer1 thanks for reporting this, are you able to put in a PR with the fix?

paulbauer1 commented 4 weeks ago

@jmcgill298

I believe I have determined a fix and would be happy to create a PR for that. Should I just clone the repo and create a new branch from master branch named something like ios-show-interface-link? Make the change to the template, push that change to the repo and then create a PR for ios-show-interface-link -> master?

jmcgill298 commented 4 weeks ago

I think only contributors can push up branches, so you would need to fork the repo and push a branch to your fork

mjbear commented 3 weeks ago

resolved by #1855