{%- if filetype_loop == 0 %}Insight ID,Insight Type,Average Update Frequency,Last Updated,Number of Updates,Link Status,Start Device Hostname,ID,IP Address,End Device Hostname,End Device ID,IP Address,Start Port Name,ID,Address,Mask,Speed,Duplex,PEP ID,Allowed VLAN IDs,Native VLAN,End Port Name,ID,Address,Mask,Speed,Duplex,PEP ID,Allowed VLAN IDs,Native VLAN,Instance ID,Instance Tenant ID
{%-   for insight in insightVLAN if device.hostname == insight.startDeviceHostName or insight.endDeviceHostName %}
{{ insight.id }},{{ insight.type }},{{ insight.avgUpdateFrequency }},{{ insight.lastUpdated }},{{ insight.numUpdates }},{{ insight.linkStatus }},{{ insight.startDeviceHostName }},{{ insight.startDeviceId }},{{ insight.startDeviceIpAddress }},{{ insight.endDeviceHostName }},{{ insight.endDeviceId }},{{ insight.endDeviceIpAddress }},{{ insight.startPortName }},{{ insight.startPortId }},{{ insight.startPortAddress }},{{ insight.startPortMask }},{{ insight.startPortSpeed }},{{ insight.startPortDuplex }},{{ insight.startPortPepId }},{{ insight.startPortAllowedVlanIds }},{{ insight.startPortNativeVlanId }},{{ insight.endPortName }},{{ insight.endPortId }},{{ insight.endPortAddress }},{{ insight.endPortMask }},{{ insight.endPortSpeed }},{{ insight.endPortDuplex }},{{ insight.endPortPepId }},{{ insight.endPortAllowedVlanIds }},{{ insight.endPortNativeVlanId }},{{ insight.instanceUuid }},{{ insight.instanceTenantId }}
{%-   endfor %}
{%- else %}
{%-     if filetype_loop == 1 %}
# Insights - VLAN Mismatch
| Insight ID | Insight Type | Average Update Frequency | Last Updated | Number of Updates | Link Status | Start Device Hostname | ID | IP Address | End Device Hostname | End Device ID | IP Address | Start Port Name | ID | Address | Mask | Speed | Duplex | PEP ID | Allowed VLAN IDs | Native VLAN | End Port Name | ID | Address | Mask | Speed | Duplex | PEP ID | Allowed VLAN IDs | Native VLAN | Instance ID | Instance Tenant ID |
| ---------- | ------------ | ------------------------ | ------------ | ----------------- | ----------- | --------------------- | -- | ---------- | ------------------- | ------------- | ---------- | --------------- | -- | ------- | ---- | ----- | ------ | ------ | ---------------- | ----------- | ------------- | -- | ------- | ---- | ----- | ------ | ------ | ---------------- | ----------- | ----------- | ------------------ |
{%-   for insight in insightVLAN if device.hostname == insight.startDeviceHostName or insight.endDeviceHostName %}
| {{ insight.id }} | {{ insight.type }} | {{ insight.avgUpdateFrequency }} | {{ insight.lastUpdated }} | {{ insight.numUpdates }} | {{ insight.linkStatus }} | {{ insight.startDeviceHostName }} | {{ insight.startDeviceId }} | {{ insight.startDeviceIpAddress }} | {{ insight.endDeviceHostName }} | {{ insight.endDeviceId }} | {{ insight.endDeviceIpAddress }} | {{ insight.startPortName }} | {{ insight.startPortId }} | {{ insight.startPortAddress }} | {{ insight.startPortMask }} | {{ insight.startPortSpeed }} | {{ insight.startPortDuplex }} | {{ insight.startPortPepId }} | {{ insight.startPortAllowedVlanIds }} | {{ insight.startPortNativeVlanId }} | {{ insight.endPortName }} | {{ insight.endPortId }} | {{ insight.endPortAddress }} | {{ insight.endPortMask }} | {{ insight.endPortSpeed }} | {{ insight.endPortDuplex }} | {{ insight.endPortPepId }} | {{ insight.endPortAllowedVlanIds }} | {{ insight.endPortNativeVlanId }} | {{ insight.instanceUuid }} | {{ insight.instanceTenantId }} |
{%-   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>Insights - VLAN Mismatch </h1>
<table id = "vlan">
  <thead>
    <tr>
      <th>Insight ID</th>
      <th>Insight Type</th>
      <th>Average Update Frequency</th>
      <th>Last Updated</th>
      <th>Number of Updates</th>
      <th>Link Status</th>
      <th>Start Device Hostname</th>
      <th>ID</th>
      <th>IP Address</th>
      <th>End Device Hostname</th>
      <th>End Device ID</th>
      <th>IP Address</th>
      <th>Start Port Name</th>
      <th>ID</th>
      <th>Address</th>
      <th>Mask</th>
      <th>Speed</th>
      <th>Duplex</th>
      <th>PEP ID</th>
      <th>Allowed VLAN IDs</th>
      <th>Native VLAN</th>
      <th>End Port Name</th>
      <th>ID</th>
      <th>Address</th>
      <th>Mask</th>
      <th>Speed</th>
      <th>Duplex</th>
      <th>PEP ID</th>
      <th>Allowed VLAN IDs</th>
      <th>Native VLAN</th>
      <th>Instance ID</th>
      <th>Instance Tenant ID</th>
    </tr>
  </thead>
  <tbody>
{%-   for insight in insightVLAN if device.hostname == insight.startDeviceHostName or insight.endDeviceHostName %}
<tr>
    <td>{{ insight.id }}</td>
    <td>{{ insight.type }}</td>
    <td>{{ insight.avgUpdateFrequency }}</td>
    <td>{{ insight.lastUpdated }}</td>
    <td>{{ insight.numUpdates }}</td>
    <td>{{ insight.linkStatus }}</td>
    <td>{{ insight.startDeviceHostName }}</td>
    <td>{{ insight.startDeviceId }}</td>
    <td>{{ insight.startDeviceIpAddress }}</td>
    <td>{{ insight.endDeviceHostName }}</td>
    <td>{{ insight.endDeviceId }}</td>
    <td>{{ insight.endDeviceIpAddress }}</td>
    <td>{{ insight.startPortName }}</td>
    <td>{{ insight.startPortId }}</td>
    <td>{{ insight.startPortAddress }}</td>
    <td>{{ insight.startPortMask }}</td>
    <td>{{ insight.startPortSpeed }}</td>
    <td>{{ insight.startPortDuplex }}</td>
    <td>{{ insight.startPortPepId }}</td>
    <td>{{ insight.startPortAllowedVlanIds }}</td>
    <td>{{ insight.startPortNativeVlanId }}</td>
    <td>{{ insight.endPortName }}</td>
    <td>{{ insight.endPortId }}</td>
    <td>{{ insight.endPortAddress }}</td>
    <td>{{ insight.endPortMask }}</td>
    <td>{{ insight.endPortSpeed }}</td>
    <td>{{ insight.endPortDuplex }}</td>
    <td>{{ insight.endPortPepId }}</td>
    <td>{{ insight.endPortAllowedVlanIds }}</td>
    <td>{{ insight.endPortNativeVlanId }}</td>
    <td>{{ insight.instanceUuid }}</td>
    <td>{{ insight.instanceTenantId }}</td>
  </tr>
{%-   endfor %}
  </tbody>
</table>
<script type = "text/javascript">
  $(document).ready(function(){
    $('#vlan thead tr')
    .clone(true)
    .addClass('filters')
    .appendTo('#vlan thead');

    var table = $('#vlan').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 %}
# Insights
## Link Mismatch - VLANs
{%-         for insight in insightVLAN if device.hostname == insight.startDeviceHostName or insight.endDeviceHostName %}
### ID: {{ insight.id }}
#### Type: {{ insight.type }}
#### Average Update Frequency: {{ insight.avgUpdateFrequency }}
#### Last Updated: {{ insight.lastUpdated }}
#### Number of Updates: {{ insight.numUpdates }}
#### Link Status: {{ insight.linkStatus }}
#### Start Device
##### {{ insight.startDeviceHostName }}
##### ID: {{ insight.startDeviceId }}
##### IP Address: {{ insight.startDeviceIpAddress }}
#### End Device
##### {{ insight.endDeviceHostName }}
##### End Device ID: {{ insight.endDeviceId }}
##### IP Address: {{ insight.endDeviceIpAddress }}
#### Start Port
##### {{ insight.startPortName }}
##### ID: {{ insight.startPortId }}
##### Address: {{ insight.startPortAddress }}
##### Mask: {{ insight.startPortMask }}
##### Speed: {{ insight.startPortSpeed }}
##### Duplex: {{ insight.startPortDuplex }}
##### PEP ID: {{ insight.startPortPepId }}
##### Allowed VLAN IDs: {{ insight.startPortAllowedVlanIds }}
##### Native VLAN: {{ insight.startPortNativeVlanId }}
#### End Port
##### {{ insight.endPortName }}
##### ID: {{ insight.endPortId }}
##### Address: {{ insight.endPortAddress }}
##### Mask: {{ insight.endPortMask }}
##### Speed: {{ insight.endPortSpeed }}
##### Duplex: {{ insight.endPortDuplex }}
##### PEP ID: {{ insight.endPortPepId }}
##### Allowed VLAN IDs: {{ insight.endPortAllowedVlanIds }}
##### Native VLAN: {{ insight.endPortNativeVlanId }}
#### Instance Info
##### ID: {{ insight.instanceUuid }}
##### Tenant ID: {{ insight.instanceTenantId }}
{%-         endfor %}
{%-         endif %}
{%-     endif %}
{%- endif %}