Created
October 4, 2017 20:11
-
-
Save trwatson/179724e366dd3f4bd52fd711219597ea to your computer and use it in GitHub Desktop.
Zabbix Agent Restart via zabbix_get
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
agentAddr="$1" | |
#use zabbix server address here if you're not in aws using an ENI | |
eniAddr=10.10.10.5 | |
sanityCheck=$(zabbix_get -s ${agentAddr} -k system.run["service zabbix-agent status"] -I ${eniAddr} 2>&1) | |
isSane=$(echo "$sanityCheck" | grep ZBX_NOTSUPPORTED | wc -l) | |
if [ $isSane -lt 1 ] | |
then | |
agentRestart=$(zabbix_get -s ${agentAddr} -k system.run["service zabbix-agent restart",nowait] -I ${eniAddr} && sleep 2) | |
isRunning=$(zabbix_get -s ${agentAddr} -k system.run["service zabbix-agent status"] -I ${eniAddr} 2>/dev/null) | |
runningCheck=$(echo "$isRunning" | grep -i "running" | wc -l) | |
if [ $runningCheck -gt 0 ]; | |
then | |
echo "Zabbix restarted." | |
exit 0 | |
else | |
echo "Fail - Checks Failed - ${agentAddr} - $isRunning" | |
exit 1 | |
fi | |
else | |
echo "Fail - Sanity Check Failed - ${agentAddr} - ${sanityCheck}" | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment