Skip to content
New issue

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

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

Already on GitHub? # to your account

textfsm.parser.TextFSMError: State Error raised. Rule Line: 15. Input Line: show ip arp #686

Closed
moderatelo opened this issue May 5, 2020 · 6 comments

Comments

@moderatelo
Copy link

I ran into similar issue here.
which appears to be related to "show ip arp" template on Cisco IOS platform
When I run it with text-FSM enabled i get this error
Traceback (most recent call last):
File "./doConfigs.py", line 200, in
Run_show_Commands_TextFSM(connectToSW)
File "./doConfigs.py", line 123, in Run_show_Commands_TextFSM
output = connected_to.send_command('show ip arp', delay_factor=1, max_loops=40, strip_prompt=False, strip_command=False,use_textfsm=True )
File "C:\Users\skononets\AppData\Local\Programs\Python\Python37-32\lib\site-packages\netmiko\utilities.py", line 347, in wrapper_decorator
return func(self, *args, **kwargs)
File "C:\Users\skononets\AppData\Local\Programs\Python\Python37-32\lib\site-packages\netmiko\base_connection.py", line 1447, in send_command
template=textfsm_template,
File "C:\Users\skononets\AppData\Local\Programs\Python\Python37-32\lib\site-packages\netmiko\utilities.py", line 280, in get_structured_data
return _textfsm_parse(textfsm_obj, raw_output, attrs)
File "C:\Users\skononets\AppData\Local\Programs\Python\Python37-32\lib\site-packages\netmiko\utilities.py", line 252, in _textfsm_parse
textfsm_obj.ParseCmd(raw_output, attrs)
File "C:\Users\skononets\AppData\Local\Programs\Python\Python37-32\lib\site-packages\netmiko_textfsm_clitable.py", line 272, in ParseCmd
self.table = self._ParseCmdItem(self.raw, template_file=template_files[0])
File "C:\Users\skononets\AppData\Local\Programs\Python\Python37-32\lib\site-packages\netmiko_textfsm_clitable.py", line 303, in _ParseCmdItem
for record in fsm.ParseText(cmd_input):
File "C:\Users\skononets\AppData\Local\Programs\Python\Python37-32\lib\site-packages\textfsm\parser.py", line 895, in ParseText
self._CheckLine(line)
File "C:\Users\skononets\AppData\Local\Programs\Python\Python37-32\lib\site-packages\textfsm\parser.py", line 944, in _CheckLine
if self._Operations(rule, line):
File "C:\Users\skononets\AppData\Local\Programs\Python\Python37-32\lib\site-packages\textfsm\parser.py", line 1025, in _Operations
% (rule.line_num, line))
textfsm.parser.TextFSMError: State Error raised. Rule Line: 15. Input Line: show ip arp

When i run it without text-FSM parsing then it works fine.
My modules are mostly up to date and I dont have those issues with other template commands

C:\Users\xxxxxxxxxx>pip list textfsm
Package Version

asn1crypto 0.24.0
bcrypt 3.1.7
cffi 1.12.3
ciscoconfparse 1.5.1
colorama 0.4.3
cryptography 2.7
dnspython 1.16.0
future 0.17.1
netmiko 3.1.0
ntc-templates 1.4.0
paramiko 2.6.0
passlib 1.7.2
pip 20.0.2
pycparser 2.19
PyNaCl 1.3.0
pyserial 3.4
scp 0.13.2
setuptools 40.8.0
six 1.12.0
terminal 0.4.0
textfsm 1.1.0

any help would be appreciated.

Thank you.

@FragmentedPacket
Copy link
Contributor

This is most likely to the command being in the output. Do you mind providing the output and the relevant part of the script? I believe we have version 1.4.1 available as well if you want to try that, but not sure that will help.

@itdependsnetworks
Copy link
Contributor

Would need output to continue, feel free to reopen ticket if you add that output to the issue.

@moderatelo
Copy link
Author

So the original output is the Error I had received which I provided.
when it works the output is what normal "show ip arp" command provides on the routes which is IP to MAC address table.
here is the original template itself

Value Required PROTOCOL (\S+)
Value Required ADDRESS (\d+.\d+.\d+.\d+)
Value Required AGE (\S+)
Value Required MAC (\S+)
Value Required TYPE (\S+)
Value INTERFACE (\S+)

Start
^Protocol\s+Address\s+Age\s*(min)\s+Hardware Addr\s+Type\s+Interface
^${PROTOCOL}\s+${ADDRESS}\s+${AGE}\s+${MAC}\s+${TYPE}\s+${INTERFACE} -> Record
^${PROTOCOL}\s+${ADDRESS}\s+${AGE}\s+${MAC}\s+${TYPE} -> Record

Capture time-stamp if vty line has command time-stamping turned on

^Load\s+for\s+
^Time\s+source\s+is
^. -> Error

What I did is removed very last line of this template. I have seen similar issues on the github with NTC templates and they had to remove or change last line.
So i after removing that last line everything works fine.
Here is the template with removed last line ( ^. -> Error )

Value Required PROTOCOL (\S+)
Value Required ADDRESS (\d+.\d+.\d+.\d+)
Value Required AGE (\S+)
Value Required MAC (\S+)
Value Required TYPE (\S+)
Value INTERFACE (\S+)

Start
^Protocol\s+Address\s+Age\s*(min)\s+Hardware Addr\s+Type\s+Interface
^${PROTOCOL}\s+${ADDRESS}\s+${AGE}\s+${MAC}\s+${TYPE}\s+${INTERFACE} -> Record
^${PROTOCOL}\s+${ADDRESS}\s+${AGE}\s+${MAC}\s+${TYPE} -> Record

Capture time-stamp if vty line has command time-stamping turned on

^Load\s+for\s+
^Time\s+source\s+is

Any particular reason why it errors out with that line?

Here is the function that does all the job.

def Run_show_Commands_TextFSM(connected_to):
i = 1
global aa
global bb
global cc
global dd
ws['A1'] = "Hostname"
ws['B1'] = "IP Address"
ws['C1'] = "MAC Address"
ws['D1'] = "Interface"

for comand in CFG_to_push:
    if connected_to == None: 
        print("Not Connected to devide: --> Finished")
        break
    connected_to.clear_buffer()
    #progress(i, the_device_list.__len__(),status="\n Running Commands!!! ")
    output = connected_to.send_command('show ip arp', delay_factor=1, max_loops=40, strip_prompt=False, strip_command=False,use_textfsm=True )
    #   use_textfsm=True
    #print (output)

    New_output = [interface for interface in output if interface['interface']=='BDI600']    # only arp entries for BDI600 PCCS vlan
    #print (New_output)
    print ("How many client BDI600 IP's: ", len(New_output) - 1)
    f_log.write("\nHow Many client BDI600 IP's: " + str(len(New_output) - 1))
    #if len(New_output) == 1:
     #   for key in New_output.keys():

    if len(New_output) == 1 :
        for each_list_of_dict in New_output:      # for each list of dictionary overall
            print (each_list_of_dict)
            A = "A" + str(aa)   #print (A)
            ws[A] = connectedto_host              # hostname
            for key in each_list_of_dict.keys():
                if key == 'address':
                    B = "B" + str(bb)
                    IP_address = each_list_of_dict['address']          # IP address
                    ws[B] = IP_address; f_log.write("\n IP Address - " + IP_address)
                    C = "C" + str(cc)
                    MAC_address = each_list_of_dict['mac']             # MAC Address
                    ws[C] = MAC_address; f_log.write("   MAC Address - " + MAC_address)
                    D = "D" + str(dd)
                    int = each_list_of_dict['interface']
                    ws[D] = int; f_log.write("    Interface - " + int)
            aa += 1
            bb += 1
            cc += 1
            dd += 1

@FragmentedPacket
Copy link
Contributor

@moderatelo Try changing strip_command to True or omitting as I believe True is the default.

@jmcgill298
Copy link
Contributor

@moderatelo The . -> Error line is there to ensure that we are capture all of the data. If that line did not exist, then a change in the output would mean that the template would incorrectly report the results. The Error it raises does tell you what line of output it failed to parse, so it is easy enough to update the template for the additional output.

As @FragmentedPacket mentioned, and as the error shows (State Error raised. Rule Line: 15. Input Line: show ip arp), this is caused by inclusion of the prompt in the output. If you remove the prompt, then it is likely this will work for you.

@FragmentedPacket
Copy link
Contributor

@moderatelo I'm going to close this issue as @jmcgill298 has provided sufficient explanation of your issue.

If you need further help, we're available on our public Slack in the #networktocode channel.

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

4 participants