Skip to content

Instantly share code, notes, and snippets.

@julcap
Created August 3, 2016 09:54
Show Gist options
  • Save julcap/268a4338594038fc79674d60139ad4ea to your computer and use it in GitHub Desktop.
Save julcap/268a4338594038fc79674d60139ad4ea to your computer and use it in GitHub Desktop.
# The purpose of this script is to help push monitoring information gathered using other scripts to all zabbix servers
# example of usage script
# ******
# send="/etc/zabbix/zabbix_sender.sh"
# value=$(/script/to/fetch/value.py)
# if [ -z "$value" ];then value=Null;fi
# $send {zabbix.key} $value 2>&1 >/dev/null
# *******
#!/bin/bash
#required args:
# $1=item key
# $2=item key value
sender=/usr/bin/zabbix_sender
cfg=/etc/zabbix/zabbix_agentd.conf
hostname=$(cat ${cfg} | egrep '^[[:space:]]*Hostname=' | cut -d= -f2)
test "z${hostname}" == "z" && hostname=`hostname -s`
sport=10051
servers=`grep -im1 ^ServerActive= ${cfg} | cut -f2 -d= | sed 's/,/ /g'`
#sendvalue $servers $sender $sport $hostname $1 $2
for i in $servers; do
$sender -vv -z $i -p $sport -s $hostname -k $1 -o $2 2>&1 >>/dev/null
echo "[$(date)]: $sender -z $i -p $sport -s $hostname -k $1 -o $2" >>/var/log/zabbix/zabbix_sender.log
done
@julcap
Copy link
Author

julcap commented Aug 3, 2016

This script allows to gather multiple values using one some script (e.g full MySQL status) and send the values to the server keys efficiently.
Eliminates unnecessary queries and preserves system resources in Zabbix server.
Requires active checks to be enabled.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment