diff --git a/machines/vault01/_configuration.nix b/machines/vault01/_configuration.nix index 7fccd2b..f55bb8e 100644 --- a/machines/vault01/_configuration.nix +++ b/machines/vault01/_configuration.nix @@ -11,7 +11,6 @@ lib.extra.mkConfig { "k-radius" "networking" "ups" - "netbox-agent-disable" ]; extraConfig = { diff --git a/machines/vault01/netbox-agent-disable.nix b/machines/vault01/netbox-agent-disable.nix deleted file mode 100644 index 7b4e4aa..0000000 --- a/machines/vault01/netbox-agent-disable.nix +++ /dev/null @@ -1 +0,0 @@ -{ dgn-netbox-agent.enable = false; } diff --git a/modules/dgn-netbox-agent/01-batch-filter.patch b/modules/dgn-netbox-agent/01-batch-filter.patch new file mode 100644 index 0000000..1d6df7e --- /dev/null +++ b/modules/dgn-netbox-agent/01-batch-filter.patch @@ -0,0 +1,35 @@ +diff --git a/netbox_agent/network.py b/netbox_agent/network.py +index 673dfc1..8ef60aa 100644 +--- a/netbox_agent/network.py ++++ b/netbox_agent/network.py +@@ -1,7 +1,7 @@ + import logging + import os + import re +-from itertools import chain ++from itertools import chain, islice + + import netifaces + from netaddr import IPAddress +@@ -413,11 +413,17 @@ class Network(object): + + # delete IP on netbox that are not known on this server + if len(nb_nics): +- netbox_ips = nb.ipam.ip_addresses.filter( +- **{self.intf_type: [x.id for x in nb_nics]} +- ) ++ ++ def batched(it, n): ++ while batch := tuple(islice(it, n)): ++ yield batch ++ ++ netbox_ips = [] ++ for ids in batched((x.id for x in nb_nics), 25): ++ netbox_ips += list( ++ nb.ipam.ip_addresses.filter(**{self.intf_type: ids}) ++ ) + +- netbox_ips = list(netbox_ips) + all_local_ips = list(chain.from_iterable([ + x['ip'] for x in self.nics if x['ip'] is not None + ])) diff --git a/modules/dgn-netbox-agent/default.nix b/modules/dgn-netbox-agent/default.nix index 49dcbe4..40b4239 100644 --- a/modules/dgn-netbox-agent/default.nix +++ b/modules/dgn-netbox-agent/default.nix @@ -14,9 +14,19 @@ in default = true; }; }; + config = lib.mkIf config.dgn-netbox-agent.enable { + nixpkgs.overlays = [ + (_: super: { + netbox-agent = super.netbox-agent.overrideAttrs (old: { + patches = (old.patches or [ ]) ++ [ ./01-batch-filter.patch ]; + }); + }) + ]; + services.netbox-agent = { enable = true; + settings = { netbox.url = "https://netbox.dgnum.eu/"; network.ignore_interfaces = "(lo|dummy.*|docker.*|podman.*)";