环境:Centos 6.6
Zabbix自动发现WEB站点:
[root@Centos ~]# tail -3 /etc/zabbix/zabbix_agentd.conf
UserParameter=web.site_discovery,/etc/zabbix/scripts/discovery_web_site.sh web_site_discovery
UserParameter=web.site_code[*],/etc/zabbix/scripts/discovery_web_site.sh web_site_code $1
UserParameter=memory.free,free -m|grep Mem |awk ‘{print $4}‘
[root@Centos ~]#
[root@Centos ~]# cat /etc/zabbix/scripts/WEB.txt
www.baidu.com
www.qq.com
www.51cto.com
[root@Centos ~]#
[root@Centos ~]# zabbix_get -s 192.168.31.160 -k web.site_discovery[root@Centos ~]# zabbix_get -s 192.168.31.160 -k web.site_code[www.baidu.com] 200 [root@Centos ~]#
创建web_monitor的模版,Configuration---Templates:
Configuration---Templates(web_status_code_monitor)---discovery---create discovery rule:
Configuration---Templates(web_status_code_monitor)---discovery(1)---Item prototypes (0)---create item prototype:
Configuration---Templates(web_status_code_monitor)---discovery(1)---Trigger prototypes (0)---Create Trigger prototype:
Configuration---Templates(web_status_code_monitor)---discovery(1)---Graph prototypes (0)---Create Graph prototype:
Configuration---Host---Zabbix server---Templates---Add:
Configuration---Host---“Zabbix Server”---Discovery(1):
脚本返回的值必须是json格式的
[root@Centos ~]# cat /etc/zabbix/scripts/discovery_web_site.sh
#######cat /etc/zabbix/scripts/web_site_code_status########
#!/bin/bash
#function:monitor tcp connect status from zabbix
#license:GPL
#version:1.0
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_dir="/etc/zabbix/scripts"
WEB_SITE_discovery () {
WEB_SITE=($(cat "$Web_dir"/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
[root@Centos ~]#本文出自 “鹏城-酱油瓶” 博客,谢绝转载!
【8】、Low Level Discovery发现实现实时监控
原文地址:http://yfshare.blog.51cto.com/8611708/1774965