通过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} http://$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} http://$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 www.baidu.com www.qq.com
重启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[www.baidu.com]
具体的操作过程如下:
创建发现规则:
过滤配置:
监控原型:
触发器原型:
本文出自 “LINUX Super梦” 博客,请务必保留此出处http://215687833.blog.51cto.com/6724358/1886671
原文地址:http://215687833.blog.51cto.com/6724358/1886671