Skip to content

Commit

Permalink
#1621: Allow for loose matching of short-form IOS interface names whe…
Browse files Browse the repository at this point in the history
…n validating LLDP neighbors
  • Loading branch information
jeremystretch committed Oct 19, 2017
1 parent 515645b commit 81ca6f7
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions netbox/templates/dcim/device_lldp_neighbors.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,27 @@
$.each(json['get_lldp_neighbors'], function(iface, neighbors) {
var neighbor = neighbors[0];
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_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
row.children('td.device').html(neighbor['hostname']);
row.children('td.interface').html(neighbor['port']);
row.children('td.device').html(lldp_device);
row.children('td.interface').html(lldp_interface);

// Apply colors to rows
if (!configured_device && neighbor['hostname']) {
if (!configured_device && lldp_device) {
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');
} else {
row.addClass('danger');
Expand Down

0 comments on commit 81ca6f7

Please sign in to comment.