Skip to content

Instantly share code, notes, and snippets.

@qiwichupa
Last active January 18, 2024 16:51
Show Gist options
  • Save qiwichupa/39e47db270a070e1dafa2eb14033d1c5 to your computer and use it in GitHub Desktop.
Save qiwichupa/39e47db270a070e1dafa2eb14033d1c5 to your computer and use it in GitHub Desktop.
check server availability from zabbix proxies
#!/bin/bash
# Usage: ./zabbix_check_availability.sh my-server.local
#
# If you run it as root:
# You need to have "zabbix_get" executable binary on each proxy
# in the /root dir, and set passwordless ssh authentication.
# v. 20240118
# https://gist.github.com/qiwichupa/39e47db270a070e1dafa2eb14033d1c5
PROXYLIST=(zabbix-proxy1.local
zabbix-proxy2.local
zabbix-proxy3.local)
R='\033[0;31m'
G='\033[0;32m'
N='\033[0m'
check_agent_port() {
proxy=$1
server=$2
port=$3
echo -n "${port}: "
r=$(ssh $proxy "timeout 3 ./zabbix_get -k agent.version -p $port -s $server > /tmp/zget_resp 2>&1 && echo open || if [[ "\$?" == "124" ]]; then echo timeout > /tmp/zget_resp; echo failed, \$(cat /tmp/zget_resp); else echo failed, \$(cat /tmp/zget_resp); fi;")
if [[ "$r" == "open" ]];
then
echo -e ${G}${r}, $(ssh $proxy "timeout 3 ./zabbix_get -k agent.version -p $port -s $server "), $(ssh $proxy "timeout 3 ./zabbix_get -k system.uname -p $port -s $server")${N}
else
echo -e ${R}${r}${N}
fi
}
echo $server
echo ---------------------------------
for PRX in ${PROXYLIST[@]}; do
echo ${PRX}:
echo -n "ping: "
r=$(ssh $PRX "timeout 3 ping -c 2 $server > /dev/null 2>&1 && echo ok || echo failed")
if [[ "$r" == "ok" ]];
then
echo -e ${G}${r}${N}
else
echo -e ${R}${r}${N}
fi
check_agent_port "${PRX}" "$server" "10050"
# custom port check:
# check_agent_port "${PRX}" "$server" "10060"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment