aboutsummaryrefslogtreecommitdiff
path: root/api/netbird-nft-sets.nu
diff options
context:
space:
mode:
authorSupremist <sergkarv@gmail.com>2026-07-09 18:23:11 +0300
committerSupremist <sergkarv@gmail.com>2026-07-09 18:23:11 +0300
commite3012776a657e7a1d84f6c77f57a7730480597ca (patch)
tree1b3c51de8497679e5df6e0ede36b23eecf05d18c /api/netbird-nft-sets.nu
parentf0aaa78ab5c49d3a6c702cc58e8b4983855c836e (diff)
downloadnetbird-e3012776a657e7a1d84f6c77f57a7730480597ca.tar.xz
netbird-e3012776a657e7a1d84f6c77f57a7730480597ca.zip
Update netbird ips in nft sets on monitor events
Diffstat (limited to 'api/netbird-nft-sets.nu')
-rw-r--r--api/netbird-nft-sets.nu46
1 files changed, 0 insertions, 46 deletions
diff --git a/api/netbird-nft-sets.nu b/api/netbird-nft-sets.nu
deleted file mode 100644
index 2187aa6..0000000
--- a/api/netbird-nft-sets.nu
+++ /dev/null
@@ -1,46 +0,0 @@
-# Usage:
-# ^nft --json list sets | nu --stdin api/netbird-nft-sets.nu
-# open --raw test-data/nft-sets.json | nu --stdin api/netbird-nft-sets.nu
-
-use netbird-api.nu
-
-def mangle-name [prefix: string, name: string] {
- $prefix + ($name
- | str replace -ar '\s+' '_'
- | str replace -ar '\W' '')
-}
-
-def find-changed-sets [] {
- let sets = $in # nft_sets
- | rename --column { name: nft_name }
- let peers = netbird-api peers list
- | insert nft_name { mangle-name 'nbp_' $in.name | str downcase }
- | insert new_elem { [$in.ip] }
- let groups = netbird-api groups list
- | where peers != null
- | each { update peers { select id | join $peers id } }
- | insert nft_name { mangle-name 'nbg_' $in.name } # allow uppercase
- | insert new_elem { $in.peers.ip }
-
- let set_changes = [$peers, $groups] | flatten
- | join $sets nft_name
- | where { $in.new_elem != $in.elem }
- return $set_changes
-}
-
-def generate-nft-commands [] {
-# nft add talbe inet <name> # ignore if table already exists
-# nft destroy table inet <name> # ignore if table already removed
- let set_changes = $in
- for $s in $set_changes {
- let path = [$s.family $s.table $s.nft_name] | str join ' '
- print $"flush set ($path)"
- print $"add element ($path) { ($s.new_elem | str join ', ') }"
- }
-}
-
-def main [] {
- $in | from json | get nftables | skip 1 | get set
- | find-changed-sets
- | generate-nft-commands
-}