Question

Iterative Parsing inside Paragraph Parser

  • 20 March 2024
  • 2 replies
  • 55 views

  • New Participant
  • 0 replies

Description:

We are creating a Paragraph parser.  There are variables we want to store inside the paragraph; however, we’re only seeing a way to store the first instance as a variable.  

Here’s an example of our command output:

 Addresses, Flags: Is-Preferred Is-Primary

        Destination: 1.2.3.4, Local: 1.2.3.4, Broadcast: Unspecified, Generation: 1

      Addresses, Flags: None

        Destination: Unspecified, Local: 1.2.3.4, Broadcast: Unspecified, Generation: 1

      Addresses, Flags: Is-Preferred

        Destination: 1.2.3.4, Local: 1.2.3.4, Broadcast: Unspecified, Generation: 1

      Addresses, Flags: None

        Destination: Unspecified, Local: 1.2.3.4, Broadcast: Unspecified, Generation: 1


Question:

Our paragraph identifier starts above with “Logical Interface”.  In output we’re sharing (above) we want to store each Address and Destinastion as a variable; however, we want them tied to that logical interface.  Would this need to be done through a script (regex compile) or can we iterate over these lines simply using regex?  If this is a script...are there any examples of scripting structure we can reference?

Thank you,

djps


2 replies

Userlevel 1

You can nest a paragraph parser inside a paragraph parser.   

I have done this with parsing “show interface” on a Cisco NXOS device.  

Top Paragraph ID line:   I name the paragraph parser “interface”

^Ethernet$string:interface is $string:intState

the ^ makes it the immediate start of line.   ill “^ “ if the line is indented.     

Then if I want the TX and RX I make a paragraph for them, with the parent being the “interface” paragraph parser.  

My ID line for TX is:

^ TX

Then create the variable lines under that.   Then repeat for RX.   

 

For the 2 load intervals (not really necessary as not sure where ill use them in intents)

I made 1 start line that covers both:

parent: interface
^ Load-Interval #$int:loadInt: $mstring:intervalTime

 


Ethernet1/1 is up
admin state is up, Dedicated Interface
  Belongs to Po101
  Hardware: 100/1000/10000/25000 Ethernet, address: 7cad.4f2c.4928 (bia 7cad.4f2c.4928)
--lines removed---
  Load-Interval #1: 30 seconds
    30 seconds input rate 371526688 bits/sec, 43726 packets/sec
    30 seconds output rate 314560896 bits/sec, 43254 packets/sec
    input rate 371.53 Mbps, 43.73 Kpps; output rate 314.56 Mbps, 43.25 Kpps
  Load-Interval #2: 5 minute (300 seconds)
    300 seconds input rate 164223712 bits/sec, 22189 packets/sec
    300 seconds output rate 192161568 bits/sec, 25325 packets/sec
    input rate 164.22 Mbps, 22.19 Kpps; output rate 192.16 Mbps, 25.33 Kpps
  RX
    2664904160324 unicast packets  17863660 multicast packets  51437005 broadcast packets
    2664973460989 input packets  3031259334607730 bytes
    1820548907227 jumbo packets  0 storm suppression bytes
    0 runts  0 giants  0 CRC  0 no buffer
    0 input error  0 short frame  0 overrun   0 underrun  0 ignored
    0 watchdog  0 bad etype drop  0 bad proto drop  0 if down drop
    0 input with dribble  0 input discard
    0 Rx pause
  TX
    2281219747004 unicast packets  3073381690 multicast packets  605299103 broadcast packets
    2284898933388 output packets  2233006021804295 bytes
    1310147992086 jumbo packets
    505591 output error  0 collision  0 deferred  0 late collision
    0 lost carrier  0 no carrier  0 babble  7231 output discard
    0 Tx pause

This is pretty much the same as the above solution worded differently.  Create a new visual parser and add the first paragraph ID line for Logical Interface and create a variable(s) for whatever comes after Logical Interface on the same line.

Then create a second paragraph for the Address Flags with a variable for the flags after that (It looks like that needs to be an mstring since you can have more than one flag).

Then add in a Variable Line Pattern however you want it to parse the Destination line.

Then add the Logical Interface paragraph to the Address Flags paragraph as a parent. It should parse correctly but I am not sure how it will handle the second “Addresses, Flags: None” if it occurs under the same Logical Interface. All I can say is give it a try. 

I could think of a couple other ways without writing a Regex, but this seems to be the most direct.

 

Reply


Community |  Ideas

Facebook |  Instagram |  Youtube |  Twitter |  LinkedIn
Privacy & Security Statement  |  Terms & Conditions |  Impressum  |  UK Modern Slavery Statement