From 1daf7f8e2bca2b787b0411eaeba734007cdb220d Mon Sep 17 00:00:00 2001 From: Marc Heckmann Date: Fri, 5 Oct 2018 14:30:54 -0400 Subject: [PATCH] Sanitize hostname and port values returned through LLDP If hostname or port are null set to empty string (""). This avoids breaking the LLDP neighbors (NAPALM) view --- netbox/templates/dcim/device_lldp_neighbors.html | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/netbox/templates/dcim/device_lldp_neighbors.html b/netbox/templates/dcim/device_lldp_neighbors.html index c0c82f459..d4fbcbc79 100644 --- a/netbox/templates/dcim/device_lldp_neighbors.html +++ b/netbox/templates/dcim/device_lldp_neighbors.html @@ -64,8 +64,10 @@ $(document).ready(function() { } // 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 + var neighbor_host = neighbor['hostname'] || ""; // sanitize hostname if it's null to avoid breaking the split func + var neighbor_port = neighbor['port'] || ""; // sanitize port if it's null to avoid breaking the split func + var lldp_device = neighbor_host.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(lldp_device);