Skip to content

Instantly share code, notes, and snippets.

@v-zhuravlev
Last active November 8, 2023 17:14
Show Gist options
  • Save v-zhuravlev/a7a862c4627634af064af8de2c68ea81 to your computer and use it in GitHub Desktop.
Save v-zhuravlev/a7a862c4627634af064af8de2c68ea81 to your computer and use it in GitHub Desktop.
Various example of using ping from Zabbix agent
UserParameter=u.ping[*],/bin/ping -c 1 -W 1 -q -n $1 &> /dev/null && echo 1 || echo 0
UserParameter=u.ping.avg[*],/bin/ping -c $2 -s $3 -W 1 -q -n $1 | tail -1 | awk -F '/' '{print $$5}'
UserParameter=u.ping.loss[*],/bin/ping -c $2 -s $3 -W 1 -q -n $1 | grep -oP '[0-9]+% packet loss' | cut -d'%' -f1
#sample key:
#u.ping.loss[10.77.248.165,5,100]
#Last octet only
#example keys:
#ssk.ping.loss[10.77.51.66,73,5,100]
#ssk.ping.avg[10.77.51.66,73,5,100]
UserParameter=ssk.ping[*],/bin/ping -c 1 -W 1 -q -n `echo $1 | awk '{split($$0,a,"."); print a[1]"."a[2]"."a[3]"."$2}'` &> /dev/null && echo 1 || echo 0
UserParameter=ssk.ping.avg[*],/bin/ping -c $3 -s $4 -W 1 -q -n `echo $1 | awk '{split($$0,a,"."); print a[1]"."a[2]"."a[3]"."$2}'` | tail -1 | awk -F '/' '{print $$5}'
UserParameter=ssk.ping.loss[*],/bin/ping -c $3 -s $4 -W 1 -q -n `echo $1 | awk '{split($$0,a,"."); print a[1]"."a[2]"."a[3]"."$2}'` | grep -oP '[0-9]+% packet loss' | cut -d'%' -f1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment