oxidized-web
oxidized-web copied to clipboard
Numeric ordering for devices names
https://github.com/ytti/oxidized/issues/34
The webinterface's ordering seems wrong:
sw1.foo
sw10.bar
sw11.quux
sw2.quuux
Wheras it should be ordered like so:
sw1.foo
sw2.quuux
sw10.bar
sw11.quux
There are a lot of ways you can look at this. You can argue that the order should be as you stated, but maybe I prefer the sorting to be in "reverse" order. In other words, I want to sort by the root down to the leaf. This would make your example look like this:
sw10.bar
sw1.foo
sw2.quuux
sw11.quux
This has obvious benefits: you could group devices by location if you're using subdomains. Example list:
sw3.jfk.example.com
sw10.sfo.example.com
sw2.jfk.example.com
sw2.sfo.example.com
By your desired example ouput, it would look like this:
sw2.jfk.example.com
sw2.sfo.example.com
sw3.jfk.example.com
sw10.sfo.example.com
Sorting by root, it would look like this:
sw2.jfk.example.com
sw3.jfk.example.com
sw2.sfo.example.com
sw10.sfo.example.com
I don't see much point in pursuing this because everyone will have a different opinion on how to sort their nodes.
And sorting by root has its own problems--if you're using IP addresses instead of hostnames (because you don't have the DNS infrastructure or some other reason), sorting by root won't work because it was sort IPs by their last octect, which is the reverse grouping of root-based hostname sorting.
As is see all of them as valid, why not just toss a sorting function in there and let the user click through them as well as configure a default?
Unfortunately, it isn't quite that easy. The sorting is handled by a JavaScript library called DataTables. The way the sorting works is by defining a type and applying that type to a column. You then sort by using either the built-in sorters or by writing a sorting plugin.
A plugin exists for the IP address type, but not for the root-to-leaf hostname sorting. A plugin also exists for natural sorting (which would solve your use case), but it wouldn't solve sorting for IP addresses or root-to-leaf sorting. Plugins can't be combined, tables can't be instantiated more than once (to the best of my knowledge), and I don't know if you can modify the type of a column after its instantiation.
If you want to look into this and possibly provide a pull request, that would be awesome. Otherwise, I'm going to defer the issue until an extensible (and non-hacky) way to satisfy at least the following three requirements is determined:
- Sort hostname as IP address
- Sort hostname using natural sorting (see first comment of this issue for an example)
- Sort hostname using root-to-leaf algorithm with natural sorting at each node