pub fn count_blocks(log: &str, ports: &[u16]) -> BTreeMap<String, u64>Expand description
Count, per port of the plan, the [UFW BLOCK] lines of a kernel log that name it as
the destination. Pure.
use majordomus_cli::mesh::firewall::count_blocks;
let log = "[UFW BLOCK] IN=eth0 SRC=192.168.7.11 DST=239.255.77.77 PROTO=UDP SPT=7741 DPT=7741 LEN=430\n\
[UFW BLOCK] IN=eth0 SRC=192.168.7.11 DST=192.168.7.10 PROTO=TCP SPT=57168 DPT=8791 WINDOW=65535\n\
[UFW BLOCK] IN=eth0 SRC=192.168.7.11 DST=192.168.7.10 PROTO=TCP SPT=57169 DPT=8791 WINDOW=65535\n\
[UFW BLOCK] IN=eth0 SRC=1.2.3.4 DST=192.168.7.10 PROTO=TCP SPT=1 DPT=22 WINDOW=1\n\
perf: interrupt took too long\n";
let counts = count_blocks(log, &[7741, 8791]);
assert_eq!(counts.get("7741"), Some(&1));
assert_eq!(counts.get("8791"), Some(&2));
assert_eq!(counts.get("22"), None);