Do you use Zabbix for monitoring devices? Is there a device you’d like to monitor that you just can’t manage to install the Zabbix agent on? This was the situation I found myself in, when trying to fill a gap in wi-fi coverage with a spare TL-WA801ND access point. While I could and did put OpenWRT on it, there was just not enough space left for either zabbix_agentd or zabbix_sender.

Luckily, Zabbix’s data format is regular old json and the transmission protocol is simple and documented, so you can put together an alternative to zabbix_sender in shell script that takes up 100 times fewer precious bytes.

help="Usage: <-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
                h)echo $help;exit 0;;

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)))"

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

It’s not a complete replacement, but it covers the essentials. Well, unless you count TLS support among essentials. TLS support can be added by replacing nc with TLS-capable ncat, but the mammoth 208kB size of that is far beyond what my humble TL-WA801ND can accomodate.

I would like to figure out how to emulate zabbix_agentd with this method, but the OpenWRT image for devices with 4MB of storage comes with busybox that only implements nc sending and ommits listening funcionality, so it appears complicated, if not impossible. If you have any ideas on how to do that, please send them to ‘comments’ at this domain.