device_lldp_neighbors.html 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. {% extends '_base.html' %}
  2. {% block title %}{{ device }} - LLDP Neighbors{% endblock %}
  3. {% block content %}
  4. {% include 'inc/ajax_loader.html' %}
  5. {% include 'dcim/inc/device_header.html' with active_tab='lldp-neighbors' %}
  6. <div class="panel panel-default">
  7. <div class="panel-heading">
  8. <strong>LLDP Neighbors</strong>
  9. </div>
  10. <table class="table table-hover panel-body">
  11. <thead>
  12. <tr>
  13. <th>Interface</th>
  14. <th>Configured Device</th>
  15. <th>Configured Interface</th>
  16. <th>LLDP Device</th>
  17. <th>LLDP Interface</th>
  18. </tr>
  19. </thead>
  20. <tbody>
  21. {% for iface in interfaces %}
  22. <tr id="{{ iface.name }}">
  23. <td>{{ iface }}</td>
  24. {% if iface.connection %}
  25. {% with iface.connected_interface as connected_iface %}
  26. <td class="configured_device" data="{{ connected_iface.device }}">
  27. <a href="{% url 'dcim:device' pk=connected_iface.device.pk %}">{{ connected_iface.device }}</a>
  28. </td>
  29. <td class="configured_interface" data="{{ connected_iface }}">
  30. <span title="{{ connected_iface.get_form_factor_display }}">{{ connected_iface }}</span>
  31. </td>
  32. {% endwith %}
  33. {% else %}
  34. <td colspan="2">None</td>
  35. {% endif %}
  36. <td class="device"></td>
  37. <td class="interface"></td>
  38. </tr>
  39. {% endfor %}
  40. </tbody>
  41. </table>
  42. </div>
  43. {% endblock %}
  44. {% block javascript %}
  45. <script type="text/javascript">
  46. $(document).ready(function() {
  47. $.ajax({
  48. url: "{% url 'dcim-api:device-napalm' pk=device.pk %}?method=get_lldp_neighbors",
  49. dataType: 'json',
  50. success: function(json) {
  51. $.each(json['get_lldp_neighbors'], function(iface, neighbors) {
  52. var neighbor = neighbors[0];
  53. var row = $('#' + iface.split(".")[0].replace(/(\/)/g, "\\$1"));
  54. // Glean configured hostnames/interfaces from the DOM
  55. var configured_device = row.children('td.configured_device').attr('data');
  56. var configured_interface = row.children('td.configured_interface').attr('data');
  57. if (configured_interface) {
  58. // Match long-form IOS names against short ones (e.g. Gi0/1 == GigabitEthernet0/1).
  59. configured_interface = configured_interface.replace(/^([A-Z][a-z])[^0-9]*([0-9\/]+)$/, "$1$2");
  60. }
  61. // Clean up hostnames/interfaces learned via LLDP
  62. var lldp_device = neighbor['hostname'].split(".")[0]; // Strip off any trailing domain name
  63. var lldp_interface = neighbor['port'].split(".")[0]; // Strip off any trailing subinterface ID
  64. // Add LLDP neighbors to table
  65. row.children('td.device').html(lldp_device);
  66. row.children('td.interface').html(lldp_interface);
  67. // Apply colors to rows
  68. if (!configured_device && lldp_device) {
  69. row.addClass('info');
  70. } else if (configured_device == lldp_device && configured_interface == lldp_interface) {
  71. row.addClass('success');
  72. } else {
  73. row.addClass('danger');
  74. }
  75. });
  76. },
  77. error: function(xhr) {
  78. alert(xhr.responseText);
  79. }
  80. });
  81. });
  82. </script>
  83. {% endblock %}