device_lldp_neighbors.html 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. {% extends '_base.html' %}
  2. {% block title %}{{ device }} - LLDP Neighbors{% endblock %}
  3. {% block content %}
  4. {% include 'dcim/inc/device_header.html' with active_tab='lldp-neighbors' %}
  5. <div class="panel panel-default">
  6. <div class="panel-heading">
  7. <strong>LLDP Neighbors</strong>
  8. </div>
  9. <table class="table table-hover panel-body">
  10. <thead>
  11. <tr>
  12. <th>Interface</th>
  13. <th>Configured Device</th>
  14. <th>Configured Interface</th>
  15. <th>LLDP Device</th>
  16. <th>LLDP Interface</th>
  17. </tr>
  18. </thead>
  19. <tbody>
  20. {% for iface in interfaces %}
  21. <tr id="{{ iface }}">
  22. <td>{{ iface }}</td>
  23. {% if iface.connection %}
  24. {% with iface.connected_interface as connected_iface %}
  25. <td class="configured_device" data="{{ connected_iface.device }}">
  26. <a href="{% url 'dcim:device' pk=connected_iface.device.pk %}">{{ connected_iface.device }}</a>
  27. </td>
  28. <td class="configured_interface" data="{{ connected_iface }}">
  29. <span title="{{ connected_iface.get_form_factor_display }}">{{ connected_iface }}</span>
  30. </td>
  31. {% endwith %}
  32. {% else %}
  33. <td colspan="2">None</td>
  34. {% endif %}
  35. <td class="device"></td>
  36. <td class="interface"></td>
  37. </tr>
  38. {% endfor %}
  39. </tbody>
  40. </table>
  41. </div>
  42. {% endblock %}
  43. {% block javascript %}
  44. <script type="text/javascript">
  45. $(document).ready(function() {
  46. $.ajax({
  47. url: "{% url 'dcim-api:device_lldp-neighbors' pk=device.pk %}",
  48. dataType: 'json',
  49. success: function(json) {
  50. $.each(json, function(i, neighbor) {
  51. var row = $('#' + neighbor['local-interface'].replace(/(\/)/g, "\\$1"));
  52. var configured_device = row.children('td.configured_device').attr('data');
  53. var configured_interface = row.children('td.configured_interface').attr('data');
  54. // Add LLDP neighbors to table
  55. row.children('td.device').html(neighbor['name']);
  56. row.children('td.interface').html(neighbor['remote-interface']);
  57. // Apply colors to rows
  58. if (!configured_device && neighbor['name']) {
  59. row.addClass('info');
  60. } else if (configured_device == neighbor['name'] && configured_interface == neighbor['remote-interface']) {
  61. row.addClass('success');
  62. } else {
  63. row.addClass('danger');
  64. }
  65. });
  66. }
  67. });
  68. });
  69. </script>
  70. {% endblock %}