mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Updated LLDP neighbors view to use NAPALM API
This commit is contained in:
@ -3,64 +3,66 @@
|
|||||||
{% block title %}{{ device }} - LLDP Neighbors{% endblock %}
|
{% block title %}{{ device }} - LLDP Neighbors{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
{% include 'dcim/inc/device_header.html' with active_tab='lldp-neighbors' %}
|
{% include 'inc/ajax_loader.html' %}
|
||||||
<div class="panel panel-default">
|
{% include 'dcim/inc/device_header.html' with active_tab='lldp-neighbors' %}
|
||||||
<div class="panel-heading">
|
<div class="panel panel-default">
|
||||||
<strong>LLDP Neighbors</strong>
|
<div class="panel-heading">
|
||||||
</div>
|
<strong>LLDP Neighbors</strong>
|
||||||
<table class="table table-hover panel-body">
|
</div>
|
||||||
<thead>
|
<table class="table table-hover panel-body">
|
||||||
<tr>
|
<thead>
|
||||||
<th>Interface</th>
|
<tr>
|
||||||
<th>Configured Device</th>
|
<th>Interface</th>
|
||||||
<th>Configured Interface</th>
|
<th>Configured Device</th>
|
||||||
<th>LLDP Device</th>
|
<th>Configured Interface</th>
|
||||||
<th>LLDP Interface</th>
|
<th>LLDP Device</th>
|
||||||
</tr>
|
<th>LLDP Interface</th>
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
{% for iface in interfaces %}
|
|
||||||
<tr id="{{ iface }}">
|
|
||||||
<td>{{ iface }}</td>
|
|
||||||
{% if iface.connection %}
|
|
||||||
{% with iface.connected_interface as connected_iface %}
|
|
||||||
<td class="configured_device" data="{{ connected_iface.device }}">
|
|
||||||
<a href="{% url 'dcim:device' pk=connected_iface.device.pk %}">{{ connected_iface.device }}</a>
|
|
||||||
</td>
|
|
||||||
<td class="configured_interface" data="{{ connected_iface }}">
|
|
||||||
<span title="{{ connected_iface.get_form_factor_display }}">{{ connected_iface }}</span>
|
|
||||||
</td>
|
|
||||||
{% endwith %}
|
|
||||||
{% else %}
|
|
||||||
<td colspan="2">None</td>
|
|
||||||
{% endif %}
|
|
||||||
<td class="device"></td>
|
|
||||||
<td class="interface"></td>
|
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
</thead>
|
||||||
</tbody>
|
<tbody>
|
||||||
</table>
|
{% for iface in interfaces %}
|
||||||
</div>
|
<tr id="{{ iface.name }}">
|
||||||
|
<td>{{ iface }}</td>
|
||||||
|
{% if iface.connection %}
|
||||||
|
{% with iface.connected_interface as connected_iface %}
|
||||||
|
<td class="configured_device" data="{{ connected_iface.device }}">
|
||||||
|
<a href="{% url 'dcim:device' pk=connected_iface.device.pk %}">{{ connected_iface.device }}</a>
|
||||||
|
</td>
|
||||||
|
<td class="configured_interface" data="{{ connected_iface }}">
|
||||||
|
<span title="{{ connected_iface.get_form_factor_display }}">{{ connected_iface }}</span>
|
||||||
|
</td>
|
||||||
|
{% endwith %}
|
||||||
|
{% else %}
|
||||||
|
<td colspan="2">None</td>
|
||||||
|
{% endif %}
|
||||||
|
<td class="device"></td>
|
||||||
|
<td class="interface"></td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block javascript %}
|
{% block javascript %}
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: "{% url 'dcim-api:device-lldp-neighbors' pk=device.pk %}",
|
url: "{% url 'dcim-api:device-napalm' pk=device.pk %}?method=get_lldp_neighbors",
|
||||||
dataType: 'json',
|
dataType: 'json',
|
||||||
success: function(json) {
|
success: function(json) {
|
||||||
$.each(json, function(i, neighbor) {
|
$.each(json['get_lldp_neighbors'], function(iface, neighbors) {
|
||||||
var row = $('#' + neighbor['local-interface'].replace(/(\/)/g, "\\$1"));
|
var neighbor = neighbors[0];
|
||||||
|
var row = $('#' + iface.replace(/(\/)/g, "\\$1"));
|
||||||
var configured_device = row.children('td.configured_device').attr('data');
|
var configured_device = row.children('td.configured_device').attr('data');
|
||||||
var configured_interface = row.children('td.configured_interface').attr('data');
|
var configured_interface = row.children('td.configured_interface').attr('data');
|
||||||
// Add LLDP neighbors to table
|
// Add LLDP neighbors to table
|
||||||
row.children('td.device').html(neighbor['name']);
|
row.children('td.device').html(neighbor['hostname']);
|
||||||
row.children('td.interface').html(neighbor['remote-interface']);
|
row.children('td.interface').html(neighbor['port']);
|
||||||
// Apply colors to rows
|
// Apply colors to rows
|
||||||
if (!configured_device && neighbor['name']) {
|
if (!configured_device && neighbor['hostname']) {
|
||||||
row.addClass('info');
|
row.addClass('info');
|
||||||
} else if (configured_device == neighbor['name'] && configured_interface == neighbor['remote-interface']) {
|
} else if (configured_device == neighbor['hostname'] && configured_interface == neighbor['port']) {
|
||||||
row.addClass('success');
|
row.addClass('success');
|
||||||
} else {
|
} else {
|
||||||
row.addClass('danger');
|
row.addClass('danger');
|
||||||
|
Reference in New Issue
Block a user