#!/bin/bash
set +e
nice -n 15 /usr/local/sbin/wpmm-watchdog --report | python3 -c '
import json,sys
d=json.load(sys.stdin);s=d.get("sockets",{});l=d.get("listeners",{})
print(json.dumps({"checked_at":d.get("checked_at"),"severity":d.get("severity"),"warnings":d.get("warnings"),"abnormal":{"syn":s.get("SYN-RECV",0),"close":s.get("CLOSE-WAIT",0),"last":s.get("LAST-ACK",0),"unexpected_established":s.get("ESTABLISHED-UNEXPECTED",0)},"non_http_established":s.get("ESTABLISHED-NON-HTTP",0),"non_http_top":s.get("top_non_http_established_sources",[])[:3],"unexpected_listeners":l.get("unexpected",[]),"services":d.get("services")},ensure_ascii=False))
'
echo "rpcbind_service=$(systemctl is-active rpcbind.service 2>/dev/null || true) rpcbind_socket=$(systemctl is-active rpcbind.socket 2>/dev/null || true)"
echo "port111_listeners=$(ss -H -lntup 2>/dev/null | awk '$5 ~ /:111$/ {n++} END {print n+0}') port111_established=$(ss -Htan state established 2>/dev/null | awk '$4 ~ /:111$/ || $5 ~ /:111$/ {n++} END {print n+0}')"
echo "port111_guard=$(systemctl is-active wpmm-port111-guard.service 2>/dev/null)"
echo "timer=$(systemctl is-active wpmm-watchdog.timer 2>/dev/null)"