When using show commands in a Netpicker Python rule, the output of these show commands will be plain text, like in this rule:
medium(
name='rule_fsm_example',
platform=['cisco_ios'],
commands=dict(arp='show ip arp')
)
def rule_fsm_example(commands):
print(commmands.arp)
Which will give this plain text output:
show ip arp:
Protocol Address Age (min) Hardware Addr Type Interface
Internet 192.168.60.2 117 000c.292e.36b6 ARPA Ethernet0/3
Internet 192.168.60.3 8 000c.2962.ba5e ARPA Ethernet0/3
Internet 192.168.60.32 15 000c.2987.5096 ARPA Ethernet0/3
Internet 192.168.60.128 2 000c.2939.45ea ARPA Ethernet0/3
Internet 192.168.60.201 - aabb.cc02.f030 ARPA Ethernet0/3
But did you know that Netpicker can automatically parse this text using TextFSM? You just have to add the .fsm
suffix:
medium(
name='rule_fsm_example',
platform=['cisco_ios'],
commands=dict(arp='show ip arp')
)
def rulefsm_examplecommands):
print(commands.arp.fsm)
Which will output:
[
{
"protocol":"Internet",
"ip_address":"192.168.60.2",
"age":"117",
"mac_address":"000c.292e.36b6",
"type":"ARPA",
"interface":"Ethernet0/3"
},
{
"protocol":"Internet",
"ip_address":"192.168.60.3",
"age":"8",
"mac_address":"000c.2962.ba5e",
"type":"ARPA",
"interface":"Ethernet0/3"
},
...
]
Netpicker uses the Network to Code NTC Templates library for the parsing. So if the command you want to parse isn’t there yet, feel free to contribute to their repository.
P.S. Did you know that you can parse the real-time command output as well, using device.cli('show ip arp').fsm
?