{%- if filetype_loop == 0 %}VRF,Address Family,Instance,Router ID,Area,Area Transit,Area Type,Summary,NSSA,Enabled,Interface Count,SPF Last Executed,Total SPF,Area LSA Count,Auto Cost Enable,Reference Bandwidth,BFD Enabled,Elapsed Time,Event Log Enabled,Graceful Restart Type,Graceful Restart Enabled,LLS,NSR Enable,External LSA,Total Areas,Total Normal Areas,Total NSSA Areas,Total Stub Areas
{%-     for vrf in to_parse_ip_ospf %}
{%-         for address_family in to_parse_ip_ospf[vrf].address_family %}
{%-             for instance in to_parse_ip_ospf[vrf].address_family[address_family].instance %}
{%-                 for area in to_parse_ip_ospf[vrf].address_family[address_family].instance[instance].areas %}
{%-                     for graceful_restart in to_parse_ip_ospf[vrf].address_family[address_family].instance[instance].graceful_restart %}
{{ vrf }},{{ address_family }},{{ instance }},{{ to_parse_ip_ospf[vrf].address_family[address_family].instance[instance].router_id }},{{ area }},{{ to_parse_ip_ospf[vrf].address_family[address_family].instance[instance].area_transit }},{{ to_parse_ip_ospf[vrf].address_family[address_family].instance[instance].areas[area].area_type }},{{ to_parse_ip_ospf[vrf].address_family[address_family].instance[instance].areas[area].summary }},{{ to_parse_ip_ospf[vrf].address_family[address_family].instance[instance].nssa }},{{ to_parse_ip_ospf[vrf].address_family[address_family].instance[instance].enable }},{{ to_parse_ip_ospf[vrf].address_family[address_family].instance[instance].areas[area].statistics.interfaces_count }},{{ to_parse_ip_ospf[vrf].address_family[address_family].instance[instance].areas[area].statistics.spf_last_executed }},{{ to_parse_ip_ospf[vrf].address_family[address_family].instance[instance].areas[area].statistics.spf_runs_count }},{{ to_parse_ip_ospf[vrf].address_family[address_family].instance[instance].areas[area].statistics.area_scope_lsa_count }},{{ to_parse_ip_ospf[vrf].address_family[address_family].instance[instance].auto_cost.enable }},{{ to_parse_ip_ospf[vrf].address_family[address_family].instance[instance].auto_cost.reference_bandwidth }},{{ to_parse_ip_ospf[vrf].address_family[address_family].instance[instance].bfd.enable }},{{ to_parse_ip_ospf[vrf].address_family[address_family].instance[instance].elapsed_time }},{% if to_parse_ip_ospf[vrf].address_family[address_family].instance[instance].event_log is defined %}YES{% else %}NO{% endif %},{{ graceful_restart }},{{ to_parse_ip_ospf[vrf].address_family[address_family].instance[instance].graceful_restart[graceful_restart].enable }},{{ to_parse_ip_ospf[vrf].address_family[address_family].instance[instance].lls }},{{ to_parse_ip_ospf[vrf].address_family[address_family].instance[instance].nsr.enable }},{{ to_parse_ip_ospf[vrf].address_family[address_family].instance[instance].numbers.external_lsa }},{{ to_parse_ip_ospf[vrf].address_family[address_family].instance[instance].total_areas }},{{ to_parse_ip_ospf[vrf].address_family[address_family].instance[instance].total_normal_areas }},{{ to_parse_ip_ospf[vrf].address_family[address_family].instance[instance].total_nssa_areas }},{{ to_parse_ip_ospf[vrf].address_family[address_family].instance[instance].total_stub_areas }}
{%-                     endfor %}
{%-                 endfor %}
{%-             endfor %}
{%-         endfor %}
{%-     endfor %}
{%- else %}
{%-     if filetype_loop == 1 %}
# Show IP OPSF 
| VRF | Address Family | Instance | Router ID | Area | Area Transit | Area Type | Summary | NSSA | Enabled | Interface Count | SPF Last Executed | Total SPF | Area LSA Count | Auto Cost Enable | Reference Bandwidth | BFD Enabled | Elapsed Time | Event Log Enabled | Graceful Restart Type | Graceful Restart Enabled | LLS | NSR Enable | External LSA | Total Areas | Total Normal Areas | Total NSSA Areas | Total Stub Areas |
| --- | -------------- | -------- | --------- | ---- | ------------ | --------- | ------- | ---- | ------- | --------------- | ----------------- | --------- | -------------- | ---------------- | ------------------- | ----------- | ------------ | ----------------- | --------------------- | ------------------------ | --- | ---------- | ------------ | ----------- | ------------------ | ---------------- | ---------------- |
{%-         for vrf in to_parse_ip_ospf %}
{%-             for address_family in to_parse_ip_ospf[vrf].address_family %}
{%-                 for instance in to_parse_ip_ospf[vrf].address_family[address_family].instance %}
{%-                     for area in to_parse_ip_ospf[vrf].address_family[address_family].instance[instance].areas %}
{%-                         for graceful_restart in to_parse_ip_ospf[vrf].address_family[address_family].instance[instance].graceful_restart %}
| {{ vrf }} | {{ address_family }} | {{ instance }} | {{ to_parse_ip_ospf[vrf].address_family[address_family].instance[instance].router_id }} | {{ area }} | {{ to_parse_ip_ospf[vrf].address_family[address_family].instance[instance].area_transit }} | {{ to_parse_ip_ospf[vrf].address_family[address_family].instance[instance].areas[area].area_type }} | {{ to_parse_ip_ospf[vrf].address_family[address_family].instance[instance].areas[area].summary }} | {{ to_parse_ip_ospf[vrf].address_family[address_family].instance[instance].nssa }} | {{ to_parse_ip_ospf[vrf].address_family[address_family].instance[instance].enable }} | {{ to_parse_ip_ospf[vrf].address_family[address_family].instance[instance].areas[area].statistics.interfaces_count }} | {{ to_parse_ip_ospf[vrf].address_family[address_family].instance[instance].areas[area].statistics.spf_last_executed }} | {{ to_parse_ip_ospf[vrf].address_family[address_family].instance[instance].areas[area].statistics.spf_runs_count }} | {{ to_parse_ip_ospf[vrf].address_family[address_family].instance[instance].areas[area].statistics.area_scope_lsa_count }} | {{ to_parse_ip_ospf[vrf].address_family[address_family].instance[instance].auto_cost.enable }} | {{ to_parse_ip_ospf[vrf].address_family[address_family].instance[instance].auto_cost.reference_bandwidth }} | {{ to_parse_ip_ospf[vrf].address_family[address_family].instance[instance].bfd.enable }} | {{ to_parse_ip_ospf[vrf].address_family[address_family].instance[instance].elapsed_time }} | {% if to_parse_ip_ospf[vrf].address_family[address_family].instance[instance].event_log is defined %}YES{% else %}NO{% endif %} | {{ graceful_restart }} | {{ to_parse_ip_ospf[vrf].address_family[address_family].instance[instance].graceful_restart[graceful_restart].enable }} | {{ to_parse_ip_ospf[vrf].address_family[address_family].instance[instance].lls }} | {{ to_parse_ip_ospf[vrf].address_family[address_family].instance[instance].nsr.enable }} | {{ to_parse_ip_ospf[vrf].address_family[address_family].instance[instance].numbers.external_lsa }} | {{ to_parse_ip_ospf[vrf].address_family[address_family].instance[instance].total_areas }} | {{ to_parse_ip_ospf[vrf].address_family[address_family].instance[instance].total_normal_areas }} | {{ to_parse_ip_ospf[vrf].address_family[address_family].instance[instance].total_nssa_areas }} | {{ to_parse_ip_ospf[vrf].address_family[address_family].instance[instance].total_stub_areas }} |
{%-                         endfor %}
{%-                     endfor %}
{%-                 endfor %}
{%-             endfor %}
{%-         endfor %}
{%-     else %}
{%-         if filetype_loop == 2 %}
<html>
<head>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
    <script src="https://cdn.datatables.net/1.11.4/js/jquery.dataTables.min.js"></script>
    <script src="https://cdn.datatables.net/buttons/2.0.0/js/dataTables.buttons.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.1.3/jszip.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.53/pdfmake.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.53/vfs_fonts.js"></script>
    <script src="https://cdn.datatables.net/buttons/2.0.0/js/buttons.html5.min.js"></script>
    <script src="https://cdn.datatables.net/buttons/2.0.0/js/buttons.print.min.js"></script>
    <script src="https://cdn.datatables.net/colreorder/1.5.4/js/dataTables.colReorder.min.js"></script>
    <script src="https://cdn.datatables.net/buttons/2.0.0/js/buttons.colVis.min.js"></script>
    <script src="https://cdn.datatables.net/keytable/2.6.4/js/dataTables.keyTable.min.js"></script>
    <script src="https://cdn.datatables.net/select/1.3.3/js/dataTables.select.min.js"></script>
    <script src="https://cdn.datatables.net/fixedheader/3.1.9/js/dataTables.fixedHeader.min.js"></script>
    <link rel="stylesheet" href="https://cdn.datatables.net/fixedheader/3.1.9/css/fixedHeader.dataTables.min.css">
    <link rel="stylesheet" href="https://cdn.datatables.net/select/1.3.3/css/select.dataTables.min.css">
    <link rel="stylesheet" href="https://cdn.datatables.net/keytable/2.6.4/css/keyTable.dataTables.min.css">
    <link rel="stylesheet" href="https://cdn.datatables.net/1.11.4/css/jquery.dataTables.min.css">
</head>
<body>
<h1>Show IP OSPF </h1>
<table id = "ospf">
  <thead>
  <tr>
    <th>VRF</th>
    <th>Address Family</th>
    <th>Instance</th>
    <th>Router ID</th>
    <th>Neighbor</th>
    <th>Area</th>
    <th>Area Transit</th>
    <th>Area Type</th>
    <th>Summary</th>
    <th>NSSA</th>
    <th>Enabled</th>
    <th>Interface Count</th>
    <th>SPF Last Executed</th>
    <th>Total SPF</th>
    <th>Area LSA Count</th>
    <th>Auto Cost Enable</th>
    <th>Reference Bandwidth</th>
    <th>BFD Enabled</th>
    <th>Elapsed Time</th>
    <th>Event Log Enabled</th>
    <th>Graceful Restart Type</th>
    <th>Graceful Restart Enabled</th>
    <th>LLS</th>
    <th>NSR Enable</th>
    <th>External LSA</th>
    <th>Total Areas</th>
    <th>Total Normal Areas</th>
    <th>Total NSSA Areas</th>
    <th>Total Stub Areas</th>
  </tr>
  </thead>
  <tbody>
{%-             for vrf in to_parse_ip_ospf %}
{%-                 for address_family in to_parse_ip_ospf[vrf].address_family %}
{%-                     for instance in to_parse_ip_ospf[vrf].address_family[address_family].instance %}
{%-                         for area in to_parse_ip_ospf[vrf].address_family[address_family].instance[instance].areas %}
{%-                             for graceful_restart in to_parse_ip_ospf[vrf].address_family[address_family].instance[instance].graceful_restart %}
<tr>
    <td>{{ vrf }}</td>
    <td>{{ address_family }}</td>
    <td>{{ instance }}</td>
    <td>{{ to_parse_ip_ospf[vrf].address_family[address_family].instance[instance].router_id }}</td>
    <td>{{ area }}</td>
    <td>{{ to_parse_ip_ospf[vrf].address_family[address_family].instance[instance].area_transit }}</td>
    <td>{{ to_parse_ip_ospf[vrf].address_family[address_family].instance[instance].areas[area].area_type }}</td>
    <td>{{ to_parse_ip_ospf[vrf].address_family[address_family].instance[instance].areas[area].summary }}</td>
    <td>{{ to_parse_ip_ospf[vrf].address_family[address_family].instance[instance].nssa }}</td>
    <td>{{ to_parse_ip_ospf[vrf].address_family[address_family].instance[instance].enable }}</td>
    <td>{{ to_parse_ip_ospf[vrf].address_family[address_family].instance[instance].areas[area].statistics.interfaces_count }}</td>
    <td>{{ to_parse_ip_ospf[vrf].address_family[address_family].instance[instance].areas[area].statistics.spf_last_executed }}</td>
    <td>{{ to_parse_ip_ospf[vrf].address_family[address_family].instance[instance].areas[area].statistics.spf_runs_count }}</td>
    <td>{{ to_parse_ip_ospf[vrf].address_family[address_family].instance[instance].areas[area].statistics.area_scope_lsa_count }}</td>
    <td>{{ to_parse_ip_ospf[vrf].address_family[address_family].instance[instance].auto_cost.enable }}</td>
    <td>{{ to_parse_ip_ospf[vrf].address_family[address_family].instance[instance].auto_cost.reference_bandwidth }}</td>
    <td>{{ to_parse_ip_ospf[vrf].address_family[address_family].instance[instance].bfd.enable }}</td>
    <td>{{ to_parse_ip_ospf[vrf].address_family[address_family].instance[instance].elapsed_time }}</td>
    <td>{% if to_parse_ip_ospf[vrf].address_family[address_family].instance[instance].event_log is defined %}YES{% else %}NO{% endif %}</td>
    <td>{{ graceful_restart }}</td>
    <td>{{ to_parse_ip_ospf[vrf].address_family[address_family].instance[instance].graceful_restart[graceful_restart].enable }}</td>
    <td>{{ to_parse_ip_ospf[vrf].address_family[address_family].instance[instance].lls }}</td>
    <td>{{ to_parse_ip_ospf[vrf].address_family[address_family].instance[instance].nsr.enable }}</td>
    <td>{{ to_parse_ip_ospf[vrf].address_family[address_family].instance[instance].numbers.external_lsa }}</td>
    <td>{{ to_parse_ip_ospf[vrf].address_family[address_family].instance[instance].total_areas }}</td>
    <td>{{ to_parse_ip_ospf[vrf].address_family[address_family].instance[instance].total_normal_areas }}</td>
    <td>{{ to_parse_ip_ospf[vrf].address_family[address_family].instance[instance].total_nssa_areas }}</td>
    <td>{{ to_parse_ip_ospf[vrf].address_family[address_family].instance[instance].total_stub_areas }}</td>
  </tr>
{%-                             endfor %}
{%-                         endfor %}
{%-                     endfor %}
{%-                 endfor %}
{%-             endfor %}
  </tbody>
</table>
<script type = "text/javascript">
  $(document).ready(function(){
    $('#ospf thead tr')
    .clone(true)
    .addClass('filters')
    .appendTo('#ospf thead');

    var table = $('#ospf').DataTable({
        keys: true,
        dom: 'Bfrtip',
        lengthMenu: [
            [ 10, 25, 50, -1 ],
            [ '10 rows', '25 rows', '50 rows', 'Show all' ]
        ],
        buttons: [
        'pageLength','colvis','copy', 'csv', 'excel', 'pdf', 'print'
        ],
        colReorder: true,
        select: true,            
        orderCellsTop: true,
        fixedHeader: true,
        initComplete: function () {
        var api = this.api();

        // For each column
        api
            .columns()
            .eq(0)
            .each(function (colIdx) {
                // Set the header cell to contain the input element
                var cell = $('.filters th').eq(
                    $(api.column(colIdx).header()).index()
                );
                var title = $(cell).text();
                $(cell).html('<input type="text" placeholder="' + title + '" />');

                // On every keypress in this input
                $(
                    'input',
                    $('.filters th').eq($(api.column(colIdx).header()).index())
                )
                    .off('keyup change')
                    .on('keyup change', function (e) {
                        e.stopPropagation();

                        // Get the search value
                        $(this).attr('title', $(this).val());
                        var regexr = '({search})'; //$(this).parents('th').find('select').val();

                        var cursorPosition = this.selectionStart;
                        // Search the column for that value
                        api
                            .column(colIdx)
                            .search(
                                this.value != ''
                                    ? regexr.replace('{search}', '(((' + this.value + ')))')
                                    : '',
                                this.value != '',
                                this.value == ''
                            )
                            .draw();

                        $(this)
                            .focus()[0]
                            .setSelectionRange(cursorPosition, cursorPosition);
                    });
            });
    },
});
});        
</script>
</body></html>
{%-         else %}
# Show IP OSPF
{%-             for vrf in to_parse_ip_ospf %}
{%-                 for address_family in to_parse_ip_ospf[vrf].address_family %}
## {{ vrf }} - {{ address_family }}
{%-                     for instance in to_parse_ip_ospf[vrf].address_family[address_family].instance %}
### {{ instance }}
#### Router ID: {{ to_parse_ip_ospf[vrf].address_family[address_family].instance[instance].router_id }}
#### Area Transit: {{ to_parse_ip_ospf[vrf].address_family[address_family].instance[instance].area_transit }}
#### NSSA: {{ to_parse_ip_ospf[vrf].address_family[address_family].instance[instance].nssa }}
#### Enabled: {{ to_parse_ip_ospf[vrf].address_family[address_family].instance[instance].enable }}
#### Auto Cost
##### Enabled: {{ to_parse_ip_ospf[vrf].address_family[address_family].instance[instance].auto_cost.enable }}
##### Reference Bandwidth: {{ to_parse_ip_ospf[vrf].address_family[address_family].instance[instance].auto_cost.reference_bandwidth }}
#### BFD Enabled: {{ to_parse_ip_ospf[vrf].address_family[address_family].instance[instance].bfd.enable }}
#### Elapsed Time: {{ to_parse_ip_ospf[vrf].address_family[address_family].instance[instance].elapsed_time }}
#### LLS: {{ to_parse_ip_ospf[vrf].address_family[address_family].instance[instance].lls }}
#### NSR Enabled: {{ to_parse_ip_ospf[vrf].address_family[address_family].instance[instance].nsr.enable }}
#### External LSA: {{ to_parse_ip_ospf[vrf].address_family[address_family].instance[instance].numbers.external_lsa }}
{%-                     if to_parse_ip_ospf[vrf].address_family[address_family].instance[instance].event_log is defined %}
#### Event Log: Enabled
{%-                     endif %}
#### Areas
##### Normal: {{ to_parse_ip_ospf[vrf].address_family[address_family].instance[instance].total_normal_areas }}
##### NSSA: {{ to_parse_ip_ospf[vrf].address_family[address_family].instance[instance].total_nssa_areas }}
##### Stub: {{ to_parse_ip_ospf[vrf].address_family[address_family].instance[instance].total_stub_areas }}
##### Total: {{ to_parse_ip_ospf[vrf].address_family[address_family].instance[instance].total_areas }}
{%-                         for area in to_parse_ip_ospf[vrf].address_family[address_family].instance[instance].areas %}
##### {{ area }}
###### Area Scope LSA Count: {{ to_parse_ip_ospf[vrf].address_family[address_family].instance[instance].areas[area].statistics.area_scope_lsa_count }}
###### Area Type: {{ to_parse_ip_ospf[vrf].address_family[address_family].instance[instance].areas[area].area_type }}
###### Summary: {{ to_parse_ip_ospf[vrf].address_family[address_family].instance[instance].areas[area].summary }}
###### Interface Count: {{ to_parse_ip_ospf[vrf].address_family[address_family].instance[instance].areas[area].statistics.interfaces_count }}
###### SPF Last Executed: {{ to_parse_ip_ospf[vrf].address_family[address_family].instance[instance].areas[area].statistics.spf_last_executed }}
###### SPF Runs Counter: {{ to_parse_ip_ospf[vrf].address_family[address_family].instance[instance].areas[area].statistics.spf_runs_count }}
{%-                         endfor %}
#### Graceful Restart
{%-                         for graceful_restart in to_parse_ip_ospf[vrf].address_family[address_family].instance[instance].graceful_restart %}
##### {{ graceful_restart }}
###### Enabled: {{ to_parse_ip_ospf[vrf].address_family[address_family].instance[instance].graceful_restart[graceful_restart].enable }}
{%-                         endfor %}
{%-                     endfor %}
{%-                 endfor %}
{%-             endfor %}
{%-         endif %}
{%-     endif %}
{%- endif %}