Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fixes javascript error for LLDP neighbor view #5515

Merged
merged 4 commits into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions changes/5515.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed javascript exception thrown in the Device LLDP neighbors view for neighbors without configured devices/interfaces.
16 changes: 12 additions & 4 deletions nautobot/dcim/templates/dcim/device/lldp_neighbors.html
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@
}
};

function getAttribute(node, querySelector, attribute) {
if (node === null or node.querySelector(querySelector) === null) {
return "";
}
return node.querySelector(querySelector).getAttribute(attribute) || "";
}

ready(() => {
fetch("{% url 'dcim-api:device-napalm' pk=object.pk %}?method=get_lldp_neighbors_detail")
.then((response) => {
Expand All @@ -80,10 +87,10 @@
// var row = $('*[data-interface-name="' + iface.split(".")[0].replace(/([\/:])/g, "\\$1") + '"]');

// Glean configured hostnames/interfaces from the DOM
const configured_device = row.querySelector('td.configured_device').getAttribute('data');
const configured_chassis = row.querySelector('td.configured_device').getAttribute('data-chassis');
const configured_interface = row.querySelector('td.configured_interface').getAttribute('data-interface-name').toLowerCase();
const configured_mac_address = row.querySelector('td.configured_mac').getAttribute('data-mac-address').toLowerCase();
const configured_device = getAttribute(row, 'td.configured_device', 'data');
const configured_chassis = getAttribute(row, 'td.configured_device', 'data-chassis');
const configured_interface = getAttribute(row, 'td.configured_interface', 'data-interface-name').toLowerCase();
const configured_mac_address = getAttribute(row, 'td.configured_mac', 'data-mac-address').toLowerCase();
let configured_interface_short = null;
if (configured_interface) {
// Match long-form IOS names against short ones (e.g. Gi0/1 == GigabitEthernet0/1).
Expand Down Expand Up @@ -122,5 +129,6 @@
}
});
});

</script>
{% endblock %}