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

Template help for multiple states #737

Closed
georgesnow opened this issue Jun 3, 2020 · 2 comments
Closed

Template help for multiple states #737

georgesnow opened this issue Jun 3, 2020 · 2 comments

Comments

@georgesnow
Copy link
Contributor

ISSUE TYPE
  • Template Creation Help
    Looking for some input or direction
TEMPLATE USING
Value ITEM (\S*\s{1}\d+|Routing\s*Engine\s*\d+|\S*)
Value VERSION (REV\s*\S*|\s*)
Value PART_NUMBER (NON-JNPR|BUILTIN|\d{3}-\d+|\s*)
Value SERIAL_NUMBER (\S*)
Value DESCRIPTION (\S*)
# Value ROUTING_ENGINE (\w+\s{1}\S*\s{1}\d+)

Start
  ^[Hh]ardware\s*[Ii]nventory:
  ^[Ii]tem\s*[Vv]ersion\s*[Pp]art\s*[Nn]umber\s*[Ss]erial [Nn]umber\s*[Dd]escription
  ^${ITEM}\s*${SERIAL_NUMBER}\s*${DESCRIPTION}\s* -> Continue.Record
  ^\S*\s*\S*\s*\S* -> NextItem
  ^\s*$$
  ^. -> Error

NextItem
  ^\s*${ITEM}\s*${VERSION}\s*${PART_NUMBER}\s*${SERIAL_NUMBER}\s*${DESCRIPTION}\s*.* -> Continue.Record
  ^\S*\s*\S*\s*\S*
  ^[Rr]outing\s*[Ee]ngine\s*\S* -> Slots
  ^\s*$$
  ^. -> Error
  
Slots
  # ^[Rr]outing\s*[Ee]ngine\s*\S*
  ^\s*${ITEM}\s*${VERSION}${PART_NUMBER}\s*${SERIAL_NUMBER}\s*${DESCRIPTION}\s*$$ -> Continue.Record
  ^\s*{ITEM}\s*${VERSION}\s*${PART_NUMBER}\s*${SERIAL_NUMBER}\s*${DESCRIPTION} -> Continue.Record
  # ^[Pp]ower\s*[Ss]upply\s*\d+\s*\S* -> Power
  ^\s*$$
  ^. -> Error
#
# Power
#   ^[Pp]ower\s*[Ss]upply\s*\d+\s*\S*
#   ^\s*${ITEM}\s*\s*${DESCRIPTION}\s*\S* -> Record
#   ^\s*$$
#   ^. -> Error
SAMPLE COMMAND OUTPUT
Hardware inventory:
Item             Version  Part number  Serial number     Description
Chassis                                A1111             MX104
Midplane         REV 49   750-044219   CADS6304          MX104
PEM 0            REV 04   740-045933   1H394958039       AC Power Entry Module
PEM 1            REV 04   740-045933   1H171234566       AC Power Entry Module
Routing Engine 0 REV 07   750-053342   CAD01234          RE-MX-104
AFEB 0                    BUILTIN      BUILTIN           Forwarding Engine Processor
FPC 0                     BUILTIN      BUILTIN           MPC BUILTIN
  MIC 0          REV 25   750-028380   ABCV1234          3D 2x 10GE XFP
    PIC 0                 BUILTIN      BUILTIN           1x 10GE XFP
      Xcvr 0     REV 01   740-014279   EOXH27123456      XFP-10G-LR
    PIC 1                 BUILTIN      BUILTIN           1x 10GE XFP
      Xcvr 0     REV 01   740-014279   EOXH27123456      XFP-10G-LR
  MIC 1          REV 25   750-028380   ABCV8956          3D 2x 10GE XFP
    PIC 2                 BUILTIN      BUILTIN           1x 10GE XFP
      Xcvr 0     REV 01   740-014279   EOXH27123456      XFP-10G-LR
    PIC 3                 BUILTIN      BUILTIN           1x 10GE XFP
      Xcvr 0              NON-JNPR     AA12BK0AA         XFP-10G-SR
SUMMARY

Looking for some assistance on how to create the capture group so the lower FPC,MIC,PIC, XCVR etc...
are lists of lists?
Since there is 4 - Xcvr 0s the output needs to show the relationship to its respective hierarchy.
Example:
Xcvr 0 -> PIC 3 -> MIC 1 -> FPC 0
Xcvr 0 -> PIC 1 -> MIC 0 -> FPC 0

EXPECTED RESULTS

Not sure what the results should look like.
List of a list?

ACTUAL RESULTS
[{'item': 'Chassis', 'version': '', 'part_number': '', 'serial_number': 'A1111', 'description': 'MX104'}, {'item': 'Midplane', 'version': 'REV 49', 'part_number': '750-044219', 'serial_number': 'CADS6304', 'description': 'MX104'}, {'item': 'PEM 0', 'version': 'REV 04', 'part_number': '740-045933', 'serial_number': '1H394958039', 'description': 'AC'}, {'item': 'PEM 1', 'version': 'REV 04', 'part_number': '740-045933', 'serial_number': '1H171234566', 'description': 'AC'}, {'item': 'Routing Engine 0', 'version': 'REV 07', 'part_number': '750-053342', 'serial_number': 'CAD01234', 'description': 'RE-MX-104'}, {'item': 'AFEB 0', 'version': '', 'part_number': 'BUILTIN', 'serial_number': 'BUILTIN', 'description': 'Forwarding'}, {'item': 'FPC 0', 'version': '', 'part_number': 'BUILTIN', 'serial_number': 'BUILTIN', 'description': 'MPC'}, {'item': 'MIC 0', 'version': 'REV 25', 'part_number': '750-028380', 'serial_number': 'ABCV1234', 'description': '3D'}, {'item': 'PIC 0', 'version': '', 'part_number': 'BUILTIN', 'serial_number': 'BUILTIN', 'description': '1x'}, {'item': 'Xcvr 0', 'version': 'REV 01', 'part_number': '740-014279', 'serial_number': 'EOXH27123456', 'description': 'XFP-10G-LR'}, {'item': 'PIC 1', 'version': '', 'part_number': 'BUILTIN', 'serial_number': 'BUILTIN', 'description': '1x'}, {'item': 'Xcvr 0', 'version': 'REV 01', 'part_number': '740-014279', 'serial_number': 'EOXH27123456', 'description': 'XFP-10G-LR'}, {'item': 'MIC 1', 'version': 'REV 25', 'part_number': '750-028380', 'serial_number': 'ABCV8956', 'description': '3D'}, {'item': 'PIC 2', 'version': '', 'part_number': 'BUILTIN', 'serial_number': 'BUILTIN', 'description': '1x'}, {'item': 'Xcvr 0', 'version': 'REV 01', 'part_number': '740-014279', 'serial_number': 'EOXH27123456', 'description': 'XFP-10G-LR'}, {'item': 'PIC 3', 'version': '', 'part_number': 'BUILTIN', 'serial_number': 'BUILTIN', 'description': '1x'}, {'item': 'Xcvr 0', 'version': '', 'part_number': 'NON-JNPR', 'serial_number': 'AA12BK0AA', 'description': 'XFP-10G-SR'}]
@FragmentedPacket
Copy link
Contributor

@georgesnow This one is kind of hard. Maybe you would need to capture them as separate values if you're wanting some kind of relationship with them, but this project is mainly for just parsing the data and keeping that logic outside of the templates.

I think a good way to do it is to just add them as separate values:

Value ITEM Filldown (\S*\s{1}\d+|Routing\s*Engine\s*\d+|\S*)
Value MIC (MIC\s\d+)
Value PIC (PIC\s\d+)
Value XCVR (Xcvr\s\d+)

EXAMPLE_STATE
  ^\s+${MIC} the rest of what you need to capture
  .. rest of the new values ...

@FragmentedPacket
Copy link
Contributor

I'm going to close this issue as we're looking to move helping with templates, etc. into a real-time platform and use our NTC Slack for help.

You can sign up via https://slack.networktocode.com and ask for help in our #networktocode channel.

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

2 participants