ntc-templates
ntc-templates copied to clipboard
Get a duplicated key and their attributes
So I have a case where the output from a cmd 'show runing' in a nexus give me something like this:
snmp-server host 10.140.300.200 traps version 2c ldldo-1ldd
snmp-server host 10.140.300.200 use-vrf management
snmp-server host 10.132.300.101 traps version 2c oelee-doeoel
snmp-server host 10.132.300.101 use-vrf management
snmp-server host 10.132.300.101 source-interface kedl1
snmp-server host 10.151.230.230 traps version 2c SNMP1sAPain
snmp-server host 10.105.10.104 traps version 2c oelee-doeoel
snmp-server host 10.105.10.104 use-vrf management
snmp-server host 10.105.10.104 source-interface kedl1
The template that i started was:
Value host (\S+)
Value version (\S+)
Value community (\S+)
Value vrf (\S+)
Value source_interface (\S+)
Start
^snmp-server\s+host\s+${host}\s+traps\s+version\s+${version}\s+${community}
^snmp-server\s+host\s+${host}\s+use-vrf\s+${vrf}
^snmp-server\s+host\s+${host}\s+source-interface\s+${source_interface} -> Record
I know with this template i only get the values from hosts like '10.132.300.101', '10.105.10.104'. But the challenge here is how can i capture the hosts ('10.140.300.200', '10.151.230.230') where misses one or even the two last lines of the template?
I tried an infinitude of solutions/combinations, but maybe I didn't catch the textFSM essence.
Anyone can help me with this?
I think you want to use a list https://github.com/google/textfsm/wiki/Code-Lab#using-list
@diogopxosys
Ah, in your example raw output the hosts that don't match do not have a source-interface
line.
:arrow_forward: Running config (or sections of it) is probably going to be harder to parse than normal show command output. When I get to the CLI of a Nexus switch I will look and see if show snmp
is going to be better to parse and yet contain the information you seek.
NX-OS show snmp
command reference
Minor item. :smile: Please capitalize the capture group names in templates to adhere with ntc-templates project standards which aids in the readability of the template. :sunglasses:
Example:
Value HOST (\S+)
Value VERSION (\S+)
Value COMMUNITY (\S+)
Value VRF (\S+)
Value SOURCE_INTERFACE (\S+)
Start
^snmp-server\s+host\s+${HOST}\s+traps\s+version\s+${VERSION}\s+${COMMUNITY}
^snmp-server\s+host\s+${HOST}\s+use-vrf\s+${VRF}
^snmp-server\s+host\s+${HOST}\s+source-interface\s+${SOURCE_INTERFACE} -> Record
@mjbear
Appreciate your answer! 😄
@diogopxosys
So far it looks like most of the information you seek is included in show snmp
on nxos. The downside is that it isn't in a single table -- meaning there are multiple sections. As in a section on general info (contact, location, packets in/out), communities (SNMPv1/v2c), users (SNMPv3), contexts (instance, vrf, topology, vlan, MST).
Each of those "sections" will be independent of one another in the sense that TextFSM won't match up items from disparate sections. I'll have to set up some trap config and see what the output looks like.
Ah, this may require parsing several commands (multiple templates) to get all the information. It would be really great if we could find all this information in the output from a single command! :laughing:
show snmp source-interface
show snmp community
show snmp host
show snmp user
Though it does look like show snmp
without any modifiers contains most of the output from several of those commands...
@diogopxosys
Did you end up working a template together for cisco_nxos_show_snmp
?