networktocode / ntc-templates

TextFSM templates for parsing show commands of network devices
https://ntc-templates.readthedocs.io/
Other
1.11k stars 729 forks source link

Add cisco_ios_show_wireless_tag_policy_summary #1826

Closed alexblaeuer closed 2 months ago

alexblaeuer commented 2 months ago

Environment

Proposed Functionality

Adding new textfsm template for show wireless tag policy summary Cisco WLC running Cisco IOS XE

Use Case

Catch the configured Policy Tags on Cisco WLC

TEMPLATE USING
Value Required POLICY_TAG_NAME (\S+)
Value DESCRIPTION (.+)

Start
  # Skip the header lines
  ^Number of Policy Tags:.*
  ^Policy Tag Name\s+Description
  # Start capturing output
  ^-+ -> PolicyTag
  # Capture time-stamp if vty line has command time-stamping turned on
  ^Load\s+for\s+
  ^Time\s+source\s+is
  # Match blank lines
  ^\s*$$
  # Error out if raw data does not match any above rules.
  ^. -> Error

PolicyTag
  ^${POLICY_TAG_NAME}\s+${DESCRIPTION} -> Record
  # Handle cases where the description is missing
  ^${POLICY_TAG_NAME} -> Record
  # Match blank lines
  ^\s*$$
  # Error out if raw data does not match any above rules.
  ^. -> Error

EOF
SAMPLE COMMAND OUTPUT

Number of Policy Tags: 10

Policy Tag Name                   Description
------------------------------------------------------------------------
PT_VIP                            PT_VIP
PT_Test                           PT_Test
PT_Mgmt
PT_Media                          PT_Media
PT_Default                        PT_Default
PT_Extra
PT_Hallway                        PT_Hallway
default-policy-tag                default policy-tag
RESULTS
---
parsed_sample:
  - description: "PT_VIP"
    policy_tag_name: "PT_VIP"
  - description: "PT_Test"
    policy_tag_name: "PT_Test"
  - description: ""
    policy_tag_name: "PT_Mgmt"
  - description: "PT_Media"
    policy_tag_name: "PT_Media"
  - description: "PT_Default"
    policy_tag_name: "PT_Default"
  - description: ""
    policy_tag_name: "PT_Extra"
  - description: "PT_Hallway"
    policy_tag_name: "PT_Hallway"
  - description: "default policy-tag"
    policy_tag_name: "default-policy-tag"
mjbear commented 2 months ago

@alexblaeuer Do you have [sanitized] raw cli output for the tag policy summary? (sanitized to remove any potentially sensitive information)

alexblaeuer commented 2 months ago

This would be the "SAMPLE COMMAND OUTPUT". I just remove the command itself.

Here with command:

cisco-wlc-1#show wireless tag policy summary

Number of Policy Tags: 10

Policy Tag Name                   Description
------------------------------------------------------------------------
PT_VIP                            PT_VIP
PT_Test                           PT_Test
PT_Mgmt
PT_Media                          PT_Media
PT_Default                        PT_Default
PT_Extra
PT_Hallway                        PT_Hallway
default-policy-tag                default policy-tag
jmcgill298 commented 2 months ago

@alexblaeuer can you make this a pull request?

mjbear commented 2 months ago

This would be the "SAMPLE COMMAND OUTPUT". I just remove the command itself.

@alexblaeuer There are times when a person should turn in for the night and sleep rather than ask something silly. That was me, I should have looked at this issue today. :neutral_face: (My apologies.) :sweat_smile:

  1. Since there's only tag name and description in that raw output you could drop the policy word off the front. That's a preference thing though (and I'm not hard set on that suggestion either).

  2. Excellent catch on handling the missing description!

  3. Since this template is be pretty simple, you could avoid adding an extra State altogether. It reduces a few duplicate lines for the blank lines and error directive.

For example:

Value Required POLICY_TAG_NAME (\S+)
Value DESCRIPTION (.*)

Start
  # Skip the header lines
  ^Number of Policy Tags:.*
  ^Policy Tag Name\s+Description
  ^-+
  # Start capturing output
  # Capture time-stamp if vty line has command time-stamping turned on
  ^Load\s+for\s+
  ^Time\s+source\s+is
  ^${POLICY_TAG_NAME}\s+${DESCRIPTION} -> Record
  # Handle cases where the description is missing
  ^${POLICY_TAG_NAME} -> Record
  # Match blank lines
  ^\s*$$
  # Error out if raw data does not match any above rules.
  ^. -> Error

EOF

And yeah, you've done all the hard work on the template. Next steps would be to fork, branch, create the files and then run the project tests against your test data (and the rest of the project's test data).

From there like @jmcgill298 says, a PR is next. Congrats!

alexblaeuer commented 2 months ago

@mjbear Thank you very much for the inputs, much appreciated 🙏🏼. PR is in the making.