Only check duplicate IPs within poller group when auto-adding devices

I’d like to be able to auto-add devices reachable from separate pollers with the same IP address.

I currently have a distributed poller setup with multiple remote pollers in different geographies monitoring my networks. In these separate regions, I’d like my remote pollers to be able to auto-add devices across a number of specified subnets. However, across these networks, I reuse private subnets for my infrastructure (ex. all non-participating infra on 100.60.0.0/16).

Because these subnets are re-used, devices can share the same IP address and might not be added during a scan if the IP already exists (ex. with snmp-scan.py). I can force-add, but I still want the scan to respect the duplicate IP check within the poller group so that the poller doesn’t add the same device twice.

I’m imagining that the change might involve updating addHost in functions.php to have an optional $check_poller_group flag. If it’s flipped to true, then we add the poller group details to the query:

        $ip_address = \App\Models\Ipv4Address::query()
            ->where('ipv4_address', $ip)
            ->with('port.device')
            ->first();

We can then refactor any relevant callers (e.g. addHost.php/snmp-scan.py) to pass in that flag from the top. Not sure if this is it, but looks like devices have a poller_group FK, so I could just add ->where('port.device.poller_group', $poller_group) to the query and pass in $poller_group to device_has_ip.

Happy to pick up this change if people are busy/it makes sense to implement, but it seems to touch a pretty important function so I might need some guidance here.

Never mind, looked into the code some more. I think we’ll actually just want to check $ip_address->device->poller_group to see if it matches given that the extra flag is set. We’ll also want to add a check for the overwrite IP in host_exists, as well as a check for poller_group if the extra flag is set. I’ll actually go ahead and implement it/get a PR up, although I’m not sure how useful it’ll be long-term since we’re planning on removing the overwrite IP.