]> git.ipfire.org Git - ipfire-2.x.git/commitdiff
zabbix_agentd: Fix gateway ping errorhandling
authorRobin Roevens <robin.roevens@disroot.org>
Fri, 5 Jun 2026 21:28:30 +0000 (23:28 +0200)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 8 Jun 2026 09:34:26 +0000 (09:34 +0000)
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>
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
config/zabbix_agentd/userparameter_gateway.conf

index cfae001ae492371a9729e9ac0c9de90feb27438f..6f8d84c7b8f5b0eaf2087396e4601b5e6b8993eb 100644 (file)
@@ -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 $?