Skip to content

Instantly share code, notes, and snippets.

@CHERTS
Created November 15, 2019 11:36
Show Gist options
  • Save CHERTS/91325166da1a6c0a32ab02cb58363eed to your computer and use it in GitHub Desktop.
Save CHERTS/91325166da1a6c0a32ab02cb58363eed to your computer and use it in GitHub Desktop.
Zabbix-sender on bash
#!/bin/ash
help="Usage: zabbix_sender.sh <-z zabbix server> [-p server port] [-s host name] <-k key name> <-o key value>"
while getopts "z:p:s:k:o:h" c; do
case $c in
z)z=${OPTARG};;
p)p=${OPTARG};;
s)s=${OPTARG};;
k)k=${OPTARG};;
o)o=${OPTARG};;
h)echo $help;exit 0;;
esac
done
data='{"request":"sender data","data":[{"host":"'${s:-$HOSTNAME}'","key":"'${k:?$help}'","value":"'${o:?$help}'"}]}'
for i in `seq 0 7` ; do
#Works in busybox. GNU printf needs the format string to be '\\x%x' instead.
length="$length$(printf '\x%x' $(((${#data}/256**$i)%256)))"
done
resp=$(echo -n -e 'ZBXD\x01'$length$data | nc ${z:?$help} ${p:-10051})
if [ -z "${resp##*failed\:\ 1*}" ] ; then
>&2 echo "Err: sending failed"
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment