fix(netbox-agent): batch requests filtering on interfaces
All checks were successful
build configuration / build_web02 (push) Successful in 1m16s
build configuration / build_storage01 (push) Successful in 1m18s
build configuration / build_compute01 (push) Successful in 1m21s
build configuration / build_vault01 (push) Successful in 1m22s
build configuration / build_web01 (push) Successful in 1m38s
lint / check (push) Successful in 25s
build configuration / build_rescue01 (push) Successful in 56s
build configuration / push_to_cache (push) Successful in 2m13s

Re-enable the service on vault01 now that it works
This commit is contained in:
Tom Hubrecht 2024-05-07 13:29:43 +02:00
parent 3494f609bb
commit 2c88c2bad7
4 changed files with 45 additions and 2 deletions

View file

@ -11,7 +11,6 @@ lib.extra.mkConfig {
"k-radius" "k-radius"
"networking" "networking"
"ups" "ups"
"netbox-agent-disable"
]; ];
extraConfig = { extraConfig = {

View file

@ -1 +0,0 @@
{ dgn-netbox-agent.enable = false; }

View file

@ -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
]))

View file

@ -14,9 +14,19 @@ in
default = true; default = true;
}; };
}; };
config = lib.mkIf config.dgn-netbox-agent.enable { 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 = { services.netbox-agent = {
enable = true; enable = true;
settings = { settings = {
netbox.url = "https://netbox.dgnum.eu/"; netbox.url = "https://netbox.dgnum.eu/";
network.ignore_interfaces = "(lo|dummy.*|docker.*|podman.*)"; network.ignore_interfaces = "(lo|dummy.*|docker.*|podman.*)";