通过Zabbix批量监控 web url,脚本借鉴其他博友的,测试完全ok。自定义的key需要一台服务器部署,这边是放在zabbix_server端。
监控脚本如下:
# cat web_site_code_status.sh
#!/bin/bash
# function:monitor tcp connect status from zabbix
source /etc/bashrc >/dev/null 2>&1
source /etc/profile >/dev/null 2>&1
#/usr/bin/curl -o /dev/null -s -w %{http_code} $1/
web_site_discovery () {
WEB_SITE=($(cat /usr/local/zabbix/share/zabbix/alertscripts/WEB.txt|grep -v "^#"))
printf '{\n'
printf '\t"data":[\n'
for((i=0;i<${#WEB_SITE[@]};++i))
{
num=$(echo $((${#WEB_SITE[@]}-1)))
if [ "$i" != ${num} ];
then
printf "\t\t{ \n"
printf "\t\t\t\"{#SITENAME}\":\"${WEB_SITE[$i]}\"},\n"
else
printf "\t\t{ \n"
printf "\t\t\t\"{#SITENAME}\":\"${WEB_SITE[$num]}\"}]}\n"
fi
}
}
web_site_code () {
/usr/bin/curl -o /dev/null -s -w %{http_code} $1
}
case "$1" in
web_site_discovery)
web_site_discovery
;;
web_site_code)
web_site_code $2
;;
*)
echo "Usage:$0 {web_site_discovery|web_site_code [URL]}"
;;
esac
zabbix_agentd.conf文件添加如下2行:
cat /usr/local/zabbix/etc/zabbix_agentd.conf
UserParameter=web.site.discovery,/usr/local/zabbix/share/zabbix/alertscripts/web_site_code_status.sh web_site_discovery
UserParameter=web.site.code[*],/usr/local/zabbix/share/zabbix/alertscripts/web_site_code_status.sh web_site_code $1
脚本调用的web url文件,竖列写:
cat /usr/local/zabbix/share/zabbix/alertscripts/WEB.txt
重启zabbix_agentd服务:
/etc/init.d/zabbix_agentd restart
通过zabbix_get去获取自定义的key:
/usr/local/zabbix/bin/zabbix_get -p 10050 -s 10.10.254.25 -k web.site.discovery
/usr/local/zabbix/bin/zabbix_get -p 10050 -s 10.10.254.25 -k web.site.code[]
具体的操作过程如下:
创建发现规则:
过滤配置:
监控原型:
触发器原型:
一些Zabbix相关教程集合:
Ubuntu 14.04下Zabbix2.4.5 源码编译安装 .com/Linux/2015-05/117657.htm
CentOS 6.3下Zabbix安装部署