Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Could not parse line:" error for Standard ACL entries containing 1 match. #972

Closed
mitchell-foxworth opened this issue Aug 30, 2021 · 0 comments · Fixed by #973
Closed

Comments

@mitchell-foxworth
Copy link
Contributor

ISSUE TYPE
  • Bug Report
TEMPLATE USING
Value Required,Filldown ACL_TYPE (Standard|Extended)
Value Required,Filldown ACL_NAME (\S+)
Value LINE_NUM (\d+)
Value ACTION (permit|deny)
Value PROTOCOL (\S+)
Value SRC_HOST (\d+\.\d+\.\d+\.\d+)
Value SRC_ANY (any)
Value SRC_NETWORK (\d+\.\d+\.\d+\.\d+)
Value SRC_WILDCARD (\d+\.\d+\.\d+\.\d+)
Value SRC_PORT_MATCH (eq|neq|precedence|range|tos|lt|gt)
Value SRC_PORT ((?<!range\s).+?)
Value SRC_PORT_RANGE_START ((?<=range\s)\S+)
Value SRC_PORT_RANGE_END (\S+)
Value DST_HOST (\d+\.\d+\.\d+\.\d+)
Value DST_ANY (any)
Value DST_NETWORK (\d+\.\d+\.\d+\.\d+)
Value DST_WILDCARD (\d+\.\d+\.\d+\.\d+)
Value DST_PORT_MATCH (eq|neq|precedence|range|tos|lt|gt)
Value DST_PORT ((?<!range\s).+?)
Value DST_PORT_RANGE_START ((?<=range\s)\S+)
Value DST_PORT_RANGE_END (\S+)
Value FLAGS_MATCH (match-all|match-any)
Value TCP_FLAG (((\+|-|)ack(\s*?)|(\+|-|)established(\s*?)|(\+|-|)fin(\s*?)|(\+|-|)fragments(\s*?)|(\+|-|)psh(\s*?)|(\+|-|)rst(\s*?)|(\+|-|)syn(\s*?)|urg(\s*?))+)
Value LOG (log-input|log)
Value LOG_TAG (\S+)
Value ICMP_TYPE (administratively-prohibited|echo|echo-reply|mask-request|packet-too-big|parameter-problem|port-unreachable|redirect|router-advertisement|router-solicitation|time-exceeded|ttl-exceeded|unreachable)
Value TIME (\S+)
Value STATE (inactive|active)
Value MATCHES (\d+)

Start
  ^(Standard|Extended) -> Continue.Clearall
  ^${ACL_TYPE}\s+IP\s+access\s+list\s+${ACL_NAME}\s* -> Record
  ^\s+${LINE_NUM}\s+${ACTION}\s+${PROTOCOL}\s+(host\s+${SRC_HOST}|${SRC_ANY}|${SRC_NETWORK}\s+${SRC_WILDCARD})(\s+${SRC_PORT_MATCH}\s+|)(${SRC_PORT_RANGE_START}\s+${SRC_PORT_RANGE_END}|${SRC_PORT}|)\s+(host\s+${DST_HOST}|${DST_ANY}|${DST_NETWORK}\s+${DST_WILDCARD})(\s+${DST_PORT_MATCH}\s+(${DST_PORT_RANGE_START}\s+${DST_PORT_RANGE_END}|${DST_PORT}|)|\s+(${FLAGS_MATCH}\s+|)${TCP_FLAG}|)(\s+${ICMP_TYPE}|)(\s+${LOG}|)(\s+time-range\s+${TIME}\s+\(${STATE}\)|)(?:\s+\(${MATCHES}\s+\S+\)|)(\s+\(tag\s+=\s+${LOG_TAG}\)|)\s*$$ -> Record
  ^\s+${LINE_NUM}\s+${ACTION}\s+(${SRC_NETWORK},\s+wildcard\s+bits\s+${SRC_WILDCARD}|${SRC_HOST}|${SRC_ANY})(\s+${LOG}|)(\s+time-range\s+${TIME}\s+\(${STATE}\)|)(?:\s+\(${MATCHES}\s+matches\)|)(\s+\(tag\s+=\s+${LOG_TAG}\)|)\s*$$ -> Record
  ^\s*$$
  # Capture time-stamp if vty line has command time-stamping turned on
  ^Load\s+for\s+
  ^Time\s+source\s+is
  ^.* -> Error "Could not parse line:"

EOF

SAMPLE COMMAND OUTPUT
Standard IP access list Routes-To-Carrier
    10 permit 10.163.244.32 (1 match)
SUMMARY

Standard ACL entries with "(1 match)" at the end of the string fail to parse.

  File "/home/mitchf/.cache/pypoetry/virtualenvs/ntc-templates-mltuM8_k-py3.8/lib/python3.8/site-packages/textfsm/parser.py", line 1021, in _Operations
    raise TextFSMError('Error: %s. Rule Line: %s. Input Line: %s.'
textfsm.parser.TextFSMError: Error: "Could not parse line:". Rule Line: 40. Input Line:     10 permit 10.163.244.32 (1 match).
STEPS TO REPRODUCE

For a file containing the output for a standard ACL from "show ip access-lists" where 1 or more ACL entries contains " (1 match)" at the end of the line, and the file is named "tests/cisco_ios/show_ip_access-lists/cisco_ios_show_ip_access-lists_970.raw":

from ntc_templates.parse import parse_output
raw_data_file = open("tests/cisco_ios/show_ip_access-lists/cisco_ios_show_ip_access-lists_970.raw", "r")
raw_data = raw_data_file.read()
parsed_acls = parse_output(platform="cisco_ios", command="show ip access-lists", data=raw_data)
EXPECTED RESULTS

The script should parse all ACL entries into a list of dicts.

ACTUAL RESULTS
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/mitchf/sandbox/ntc-templates/ntc_templates/parse.py", line 57, in parse_output
    cli_table.ParseCmd(data, attrs)
  File "/home/mitchf/.cache/pypoetry/virtualenvs/ntc-templates-mltuM8_k-py3.8/lib/python3.8/site-packages/textfsm/clitable.py", line 282, in ParseCmd
    self.table = self._ParseCmdItem(self.raw, template_file=template_files[0])
  File "/home/mitchf/.cache/pypoetry/virtualenvs/ntc-templates-mltuM8_k-py3.8/lib/python3.8/site-packages/textfsm/clitable.py", line 315, in _ParseCmdItem
    for record in fsm.ParseText(cmd_input):
  File "/home/mitchf/.cache/pypoetry/virtualenvs/ntc-templates-mltuM8_k-py3.8/lib/python3.8/site-packages/textfsm/parser.py", line 895, in ParseText
    self._CheckLine(line)
  File "/home/mitchf/.cache/pypoetry/virtualenvs/ntc-templates-mltuM8_k-py3.8/lib/python3.8/site-packages/textfsm/parser.py", line 944, in _CheckLine
    if self._Operations(rule, line):
  File "/home/mitchf/.cache/pypoetry/virtualenvs/ntc-templates-mltuM8_k-py3.8/lib/python3.8/site-packages/textfsm/parser.py", line 1021, in _Operations
    raise TextFSMError('Error: %s. Rule Line: %s. Input Line: %s.'
textfsm.parser.TextFSMError: Error: "Could not parse line:". Rule Line: 40. Input Line:     10 permit 10.163.244.32 (1 match).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant