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

Question on how to parse this output #124

Open
evilmonkey19 opened this issue Jun 12, 2024 · 1 comment
Open

Question on how to parse this output #124

evilmonkey19 opened this issue Jun 12, 2024 · 1 comment

Comments

@evilmonkey19
Copy link

Hi!

I'm currently using TextFSM in NTC_Templates and so far has been an awesome experience. Thanks for the awesome project!

I would like to ask about a specific problem i came across from a CLI output. Basically I want to be able to parse the data using different templates or whatever. The thing I would love is to be able to parse this output in just one single object:

  -----------------------------------------------------------------------------
  FEC upstream switch :Disable
  OMCC Encrypt switch :On
  Qos mode            :Pq
  Mapping mode        :Vlan
  Tr069 management    :Disable
  -----------------------------------------------------------------------------
  Notes: * indicates Discrete TCONT(TCONT Unbound)
  -----------------------------------------------------------------------------
  <T-CONT   0>          DBA Profile-ID:1
  <T-CONT   1>          DBA Profile-ID:2
  <T-CONT   4>          DBA Profile-ID:5
    <Gem Index 126>
    ------------------------------------------------------------------------
    |Serv-Type:ETH |Encrypt:off |Cascade:off |GEM-CAR:-            |
    |Upstream-priority-queue:-  |Downstream-priority-queue:-       |
    ------------------------------------------------------------------------
     Mapping VLAN  Priority Port   Port  Bundle  Flow  Transparent
     index                  type   ID    ID      CAR
    ------------------------------------------------------------------------
     0       500   -        -      -     -       -     -         
    ------------------------------------------------------------------------

The output should be something as follows:

[{
   "fec_upstream_switch": "Disable",
   "omcc_encrypt_switch": "On",
   "qos_mode": "pq",
   "mapping_mode": "vlan",
   "tr069_management": "disable",
   "t-conts": [
      {
          "t_cont_id": 0,
          "dba_profile_id": 1,
      },
      {
          "t_cont_id": 1,
          "dba_profile_id": 2,
      },
      {
           "t_cont_id":4,
           "dba_profile_id":5,
       }
   ],
   "gems": [
      {
         "gem_index": 126,
         "t_cont_id": 4,
         "serv-type": "eth",
         "encrypt": "off",
         "gem_car": "",
         "upstream_priority_queue": "",
         "downstream_priority_queue": "",
      } 
  "gem_mappings": [
     {
        "gem_index": 126,
       "mapping_index": 0,
       "vlan": 500,
       "priority": "",
        "port_type": "",
         "bundle_id": "",
        "flow_car": "",
        "transparent": "",
     }
   ]
}]

I accept any other suggestion as well! I suggest to reuse the id and index as a way to connect each part, but if it can nested inside even better instead of relating using the indexes. Thanks!

@mjbear
Copy link

mjbear commented Jul 28, 2024

To close the loop for the broader community, there is a thread over at ntc-templates.

The summary of that thread being TextFSM is not set up for providing (deeply?) nested data. If nested data is required, maybe modify it after textfsm parsing (post-parse) or there might be another project that does this out-of-the-box. There's an awesome network automation list that might help show possibilities.

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