zabbix_agentd: Fix gateway ping errorhandling

Message ID 20260605212830.1067298-1-robin.roevens@disroot.org
State New
Headers
Series zabbix_agentd: Fix gateway ping errorhandling |

Commit Message

Robin Roevens 5 Jun 2026, 9:28 p.m. UTC
Fixed gateway ping items:
 * ipfire.net.gateway.pingtime: now always returns 0 when fping does not return the expected stats
  * ipfire.net.gateway.ping: prevent possible stderr messages from slipping in the output
  * ipfire.net.gateway.arpingtime: now always return 0 when arping does not return the expected stats.
  * ipfire.net.gateway.arping: now effectively returns 0 when arping fails. Previously this returned the arping error making Zabbix fail to detect gateway down events.

Signed-off-by: Robin Roevens <robin.roevens@disroot.org>
---
 config/zabbix_agentd/userparameter_gateway.conf | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
  

Patch

diff --git a/config/zabbix_agentd/userparameter_gateway.conf b/config/zabbix_agentd/userparameter_gateway.conf
index cfae001ae..6f8d84c7b 100644
--- a/config/zabbix_agentd/userparameter_gateway.conf
+++ b/config/zabbix_agentd/userparameter_gateway.conf
@@ -2,11 +2,11 @@ 
 #
 # ICMP Ping
 # Internet Gateway ping timings, can be used to measure "Internet Line Quality"
-UserParameter=ipfire.net.gateway.pingtime,sudo /usr/sbin/fping -c 3 gateway 2>&1 | tail -n 1 | awk '{print $NF}' | cut -d '/' -f2
+UserParameter=ipfire.net.gateway.pingtime,output=$(sudo /usr/sbin/fping -c 3 gateway 2>&1) && echo "$output" | tail -n 1 | grep -q "xmt/rcv/%loss" && echo "$output" | tail -n 1 | awk '{print $NF}' | cut -d '/' -f2 || echo "0"
 # Internet Gateway availability, can be used to check Internet connection
-UserParameter=ipfire.net.gateway.ping,sudo /usr/sbin/fping -q -r 3 gateway; [ ! $? == 0 ]; echo $?
+UserParameter=ipfire.net.gateway.ping,sudo /usr/sbin/fping -q -r 3 gateway 2>/dev/null; [ ! $? == 0 ]; echo $?
 # ARP Ping
 # Internet Gateway ping timings, can be used to measure "Internet Line Quality" when ICMP ping is not available
-UserParameter=ipfire.net.gateway.arpingtime,sudo /usr/sbin/arping -i red0 -c 3 gateway | awk 'match($0, /time=([0-9\.]+) (\w+)$/, arr) { n++; if (arr[2] == "usec") { arr[1]/=1000; }; sum+=arr[1] } END { print sum / n }'
+UserParameter=ipfire.net.gateway.arpingtime,sudo /usr/sbin/arping -i red0 -c 3 gateway 2>/dev/null | awk 'match($0, /time=([0-9\.]+) (\w+)$/, arr) { n++; if (arr[2] == "usec") { arr[1]/=1000; }; sum+=arr[1] } END { if (n > 0) print sum / n; else print "0" }'
 # Internet Gateway availability, can be used to check Internet connection when ICMP ping is not available
-UserParameter=ipfire.net.gateway.arping,sudo /usr/sbin/arping -q -c 3 gateway; [ ! $? == 0 ]; echo $?
+UserParameter=ipfire.net.gateway.arping,sudo /usr/sbin/arping -q -c 3 gateway 2>/dev/null; [ ! $? == 0 ]; echo $?