In WebUI, sort Devices by sysName instead of hostname

Tags: #<Tag:0x00007f064119a250>

Currently in LibreNMS, when viewing a list of devices and clicking on the Device column header, the sorting is done by the hostname field. For those who use FQDNs when adding devices, this makes perfect sense and should work as expected.

However, for those who add devices by IP address, such as those of us using it in environs where DNS names don’t exist or we can’t rely on them, this fails miserably. First, the sort is done alphanumerically, meaning devices IP addresses show up sorted such as

10.10.10.1
10.10.10.11
10.10.10.12
10.10.10.2

instead of

10.10.10.1
10.10.10.2
10.10.10.11
10.10.10.12

Second, even if we have SNMP data such that sysName is akin to an FQDN (in my case, Cisco gear where I’ve set the hostname and domain-name so that the returned sysName does come back as such) AND we modify config.php with the line

$config[‘force_ip_to_sysname’] = true;

based on the info on the Configuration page which reads, in part,

When using IP addresses as a hostname you can instead represent the devices on the WebUI by its SNMP sysName resulting in an easier to read overview of your network. This would apply on networks where you don’t have DNS records for most of your devices.

Source: http://docs.librenms.org/Support/Configuration/#webui-settings

while we get to see the sysName in bigger text, clicking the Device column header causes confusion all around for users. It’s not sorted (properly) by IP, nor is it alphabetical by sysName.

It would be nice to either have a setting which lets us choose how things are sorted via the Device column, or better, since the above setting specifically makes sysName how devices are represented, automatically change the sort mechanism to sort by sysName instead of hostname.

Digging under the hood in the database (MariaDB in my case), I know I can easily do things like

select * from devices order by INET_ATON(hostname);

in order to get the order I want. But noting the table structures, I also understand it might be difficult to have the Device column sorted properly by IP since you have no way of knowing whether users added devices by FQDN or IP, and so hostname values could be a mix in the devices table. So being able to properly sort hostnames when they’re all IPs might require a global setting that the admin is responsible for setting. Or it may not be possible, since the INET_ATON() function is for MariaDB/MySQL, but users may be using other DBMS.

But if the admin has configured LibreNMS with the setting mentioned above in config.php, making sysName more prominent than hostname in the Devices column, odds are they’ll want to sort the devices by sysName as well.

5 Likes

Sorting does seem to be very inconsistent throughout the UI in this and other areas. A couple of examples:

From the top level Ports -> All Ports menu, the dropdown list for All Devices is sorted by IP address, but in the method stated in the original post (eg 10.10.X.X is before 10.2.X.X) and is further complicated when using the config.php setting ‘force_ip_to_sysname’, so it shows a hostname list sorted by the string version of the underlying IP addresses.

If I then select one device from Ports -> All Ports -> All Devices -> [Search] and sort the ‘Port’ column I get the same kind of sorting, eg Fa0/10 is before Fa0/2. However, if I use global search to find the device, then click the Ports submenu I get a correctly sorted list of ports (eg Fa0/1, Fa0/2 etc). Unfortunately the column I’m interested in (‘Status Changed’) is unavailable in this view (that’s an issue for another feature request, I guess).

I understand that the UI is being redone and these are the type of “quality of life” improvements it would be nice to see.