So it doesn't look like we can realistically find a way to counter duplicate devices being added when people are using a mix of hostnames, shortnames and IPs. This PR will now disable the auto discovery of devices via IP. You will need to enable the support via a config option. Adding devices via IP via cli/webui/api is still possible as this is manually fed.
Updated to disable auto-discovery by ip
Auto-Deploy finished, Test PR at http://2182.ci.librenms.org or https://2182.ci.librenms.org
Seems reasonable to me 👍
It looks like a workaround, not like a real fix i guess. Why to not check if same IP is already in database instead?
Not a work around imho. Duplicate device detection when using IPs just isn't possible with the way things are today.
Can`t you just check if this returns values?
SELECT hostname FROM devices GROUP BY hostname HAVING count(*) > 1;
And if yes, disable autodiscovery/adding same device?
? That is simply returning a list of hostnames that are duplicated in the DB. We already do a distinct check on hostnames so you can't add the same hostname twice. The issue is when the same device is added by hostname, shortname and IP.
@laf i dont understand that. I have devices added with exactly same IP, they dont have different hostnames or shortname. So it looks like that distinct check should be also on IPs, not only on hostnames. Am i right?
t understand that. I have devices added with exactly same IP, they don
I can't see how that's possible from the code.
However this PR is not about duplicates for the same hostname, can you create a separate issue with information showing this please.
@paszczus You can't guarantee that the same IP will not be present on multiple devices in a network. e.g. In my last job, every remote site server had an interface on 192.168.1.0/24 to talk to its local ADSL modem, but the LAN interface was how the server was identified, and that was unique.
I think this is about the best we can do; it's an unfortunate artefact of supporting those LibreNMS users who don't want to give all devices a unique hostname.
@laf I think it might be worth adding a warning to the documentation about it that it can result in duplicate devices under some circumstances.
It also doesn't seem to address what I had in my issue: #1846
I had both duplicate hostname entries as well as multiple unique hostnames, but the same physical device (router, for instance with maybe twenty different IPs, but all the same device).
@MHammett PR #2189 fixes duplicate hostnames.
As for the same device being added multiple times with different hostnames, we can't fix that. It's the same issue as trying to detect based on IP alone. the only real way are things like serial numbers but these just aren't available to us until after a full poll at which point it's too late.