♻️ refactor(podkop): enhance check_nft function for domain-specific set statistics

This commit is contained in:
Ivan K
2025-05-21 09:48:53 +03:00
parent 05a551e5e3
commit bcab66f88c

View File

@@ -1890,10 +1890,35 @@ check_nft() {
return 1 return 1
fi fi
# List of possible sets local found_hetzner=0
local found_ovh=0
check_domain_list_contains() {
local section="$1"
config_get_bool domain_list_enabled "$section" "domain_list_enabled" "0"
if [ "$domain_list_enabled" -eq 1 ]; then
config_list_foreach "$section" "domain_list" check_domain_value
fi
}
check_domain_value() {
local domain_value="$1"
if [ "$domain_value" = "hetzner" ]; then
found_hetzner=1
elif [ "$domain_value" = "ovh" ]; then
found_ovh=1
fi
}
config_foreach check_domain_list_contains
if [ "$found_hetzner" -eq 1 ] || [ "$found_ovh" -eq 1 ]; then
local sets="podkop_subnets podkop_domains interfaces podkop_discord_subnets localv4" local sets="podkop_subnets podkop_domains interfaces podkop_discord_subnets localv4"
echo "Sets statistics:" nolog "Sets statistics:"
for set_name in $sets; do for set_name in $sets; do
if nft list set inet PodkopTable $set_name >/dev/null 2>&1; then if nft list set inet PodkopTable $set_name >/dev/null 2>&1; then
# Count elements using grep to count commas and add 1 (last element has no comma) # Count elements using grep to count commas and add 1 (last element has no comma)
@@ -1902,8 +1927,7 @@ check_nft() {
fi fi
done done
echo "" nolog "Chain configurations:"
echo "Chain configurations:"
# Create a temporary file for processing # Create a temporary file for processing
local tmp_file=$(mktemp) local tmp_file=$(mktemp)
@@ -1915,6 +1939,11 @@ check_nft() {
# Clean up # Clean up
rm -f "$tmp_file" rm -f "$tmp_file"
else
# Simple view as originally implemented
nolog "Sets configuration:"
nft list table inet PodkopTable
fi
nolog "NFT check completed" nolog "NFT check completed"
} }
@@ -2389,11 +2418,7 @@ global_check() {
print_global "━━━━━━━━━━━━━━━━━━━━━━━━━━━" print_global "━━━━━━━━━━━━━━━━━━━━━━━━━━━"
print_global "🧱 NFT table" print_global "🧱 NFT table"
if ! nft list table inet PodkopTable >/dev/null 2>&1; then
print_global "❌ PodkopTable not found"
else
check_nft check_nft
fi
print_global "━━━━━━━━━━━━━━━━━━━━━━━━━━━" print_global "━━━━━━━━━━━━━━━━━━━━━━━━━━━"
print_global "📄 WAN config" print_global "📄 WAN config"