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

Get a duplicated key and their attributes #1612

Open
diogopxosys opened this issue Feb 9, 2024 · 4 comments
Open

Get a duplicated key and their attributes #1612

diogopxosys opened this issue Feb 9, 2024 · 4 comments

Comments

@diogopxosys
Copy link

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?

@jmcgill298
Copy link
Contributor

I think you want to use a list https://github.com/google/textfsm/wiki/Code-Lab#using-list

@mjbear
Copy link
Contributor

mjbear commented Mar 11, 2024

@diogopxosys

Ah, in your example raw output the hosts that don't match do not have a source-interface line.

▶️ 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. 😄 Please capitalize the capture group names in templates to adhere with ntc-templates project standards which aids in the readability of the template. 😎

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

@diogopxosys
Copy link
Author

@mjbear

Appreciate your answer! 😄

@mjbear
Copy link
Contributor

mjbear commented Mar 12, 2024

@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! 😆
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...

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

No branches or pull requests

3 participants