From 92a30913b4985eba53c8ce11c613911c30ef886e Mon Sep 17 00:00:00 2001 From: Christoffer Martinsson Date: Thu, 4 Dec 2025 15:33:43 +0100 Subject: [PATCH] Add debug logging and fix chain end detection for nftables - Detect chain end with closing brace - Add debug logging to trace nft command execution and port collection - Update version to v0.1.250 --- Cargo.lock | 6 +++--- agent/Cargo.toml | 2 +- agent/src/collectors/systemd.rs | 16 ++++++++++++---- dashboard/Cargo.toml | 2 +- shared/Cargo.toml | 2 +- 5 files changed, 18 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a2e062a..99e9e1e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -279,7 +279,7 @@ checksum = "a1d728cc89cf3aee9ff92b05e62b19ee65a02b5702cff7d5a377e32c6ae29d8d" [[package]] name = "cm-dashboard" -version = "0.1.248" +version = "0.1.249" dependencies = [ "anyhow", "chrono", @@ -301,7 +301,7 @@ dependencies = [ [[package]] name = "cm-dashboard-agent" -version = "0.1.248" +version = "0.1.249" dependencies = [ "anyhow", "async-trait", @@ -325,7 +325,7 @@ dependencies = [ [[package]] name = "cm-dashboard-shared" -version = "0.1.248" +version = "0.1.249" dependencies = [ "chrono", "serde", diff --git a/agent/Cargo.toml b/agent/Cargo.toml index 28bde9d..070c5f8 100644 --- a/agent/Cargo.toml +++ b/agent/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cm-dashboard-agent" -version = "0.1.249" +version = "0.1.250" edition = "2021" [dependencies] diff --git a/agent/src/collectors/systemd.rs b/agent/src/collectors/systemd.rs index 588f9ca..7e9855c 100644 --- a/agent/src/collectors/systemd.rs +++ b/agent/src/collectors/systemd.rs @@ -920,12 +920,18 @@ impl SystemdCollector { let output = match output { Ok(out) if out.status.success() => out, - _ => return (String::new(), String::new()), + _ => { + debug!("Failed to run nft list ruleset"); + return (String::new(), String::new()); + } }; let output_str = match String::from_utf8(output.stdout) { Ok(s) => s, - Err(_) => return (String::new(), String::new()), + Err(_) => { + debug!("Failed to parse nft output as UTF-8"); + return (String::new(), String::new()); + } }; let mut tcp_ports = std::collections::HashSet::new(); @@ -945,8 +951,8 @@ impl SystemdCollector { continue; } - // Reset when entering other chains - if line.starts_with("chain ") && !line.contains("input_wan") { + // Reset when exiting chain (closing brace) or entering other chains + if line == "}" || (line.starts_with("chain ") && !line.contains("input_wan")) { in_wan_chain = false; continue; } @@ -985,6 +991,8 @@ impl SystemdCollector { let tcp_str = tcp_vec.iter().map(|p| p.to_string()).collect::>().join(", "); let udp_str = udp_vec.iter().map(|p| p.to_string()).collect::>().join(", "); + debug!("nftables WAN ports - TCP: '{}', UDP: '{}'", tcp_str, udp_str); + (tcp_str, udp_str) } diff --git a/dashboard/Cargo.toml b/dashboard/Cargo.toml index 8877d0a..be60960 100644 --- a/dashboard/Cargo.toml +++ b/dashboard/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cm-dashboard" -version = "0.1.249" +version = "0.1.250" edition = "2021" [dependencies] diff --git a/shared/Cargo.toml b/shared/Cargo.toml index 04a9945..d0ad55d 100644 --- a/shared/Cargo.toml +++ b/shared/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cm-dashboard-shared" -version = "0.1.249" +version = "0.1.250" edition = "2021" [dependencies]