码迷,mamicode.com
首页 > 其他好文 > 详细

【8】、Low Level Discovery发现实现实时监控

时间:2016-05-19 13:27:57      阅读:271      评论:0      收藏:0      [点我收藏+]

标签:zabbix   low level discovery   

环境: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发现实现实时监控

标签:zabbix   low level discovery   

原文地址:http://yfshare.blog.51cto.com/8611708/1774965

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!