mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
#1621: Allow for loose matching of short-form IOS interface names when validating LLDP neighbors
This commit is contained in:
@ -54,15 +54,27 @@ $(document).ready(function() {
|
|||||||
$.each(json['get_lldp_neighbors'], function(iface, neighbors) {
|
$.each(json['get_lldp_neighbors'], function(iface, neighbors) {
|
||||||
var neighbor = neighbors[0];
|
var neighbor = neighbors[0];
|
||||||
var row = $('#' + iface.split(".")[0].replace(/(\/)/g, "\\$1"));
|
var row = $('#' + iface.split(".")[0].replace(/(\/)/g, "\\$1"));
|
||||||
|
|
||||||
|
// Glean configured hostnames/interfaces from the DOM
|
||||||
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');
|
||||||
|
if (configured_interface) {
|
||||||
|
// Match long-form IOS names against short ones (e.g. Gi0/1 == GigabitEthernet0/1).
|
||||||
|
configured_interface = configured_interface.replace(/^([A-Z][a-z])[^0-9]*([0-9\/]+)$/, "$1$2");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clean up hostnames/interfaces learned via LLDP
|
||||||
|
var lldp_device = neighbor['hostname'].split(".")[0]; // Strip off any trailing domain name
|
||||||
|
var lldp_interface = neighbor['port'].split(".")[0]; // Strip off any trailing subinterface ID
|
||||||
|
|
||||||
// Add LLDP neighbors to table
|
// Add LLDP neighbors to table
|
||||||
row.children('td.device').html(neighbor['hostname']);
|
row.children('td.device').html(lldp_device);
|
||||||
row.children('td.interface').html(neighbor['port']);
|
row.children('td.interface').html(lldp_interface);
|
||||||
|
|
||||||
// Apply colors to rows
|
// Apply colors to rows
|
||||||
if (!configured_device && neighbor['hostname']) {
|
if (!configured_device && lldp_device) {
|
||||||
row.addClass('info');
|
row.addClass('info');
|
||||||
} else if (configured_device == neighbor['hostname'] && configured_interface == neighbor['port'].split(".")[0]) {
|
} else if (configured_device == lldp_device && configured_interface == lldp_interface) {
|
||||||
row.addClass('success');
|
row.addClass('success');
|
||||||
} else {
|
} else {
|
||||||
row.addClass('danger');
|
row.addClass('danger');
|
||||||
|
Reference in New Issue
Block a user