1、Zabbix 客户端配置
Zabbix 客户端配置语句如下:
shell# egrep -v "(#|^$)" /etc/zabbix/zabbix_agentd.confLogFile=/var/log/zabbix/zabbix_agentd.log
Server=127.0.0.1
Include=/etc/zabbix/zabbix_agentd.conf.d/ #子配置文件路径
UnsafeUserParameters=1 #自定义的Key中可以包括特殊字符
2、编写自动发现脚本
(1)Shell脚本shell#cat /etc/zabbix/scripts/web_site_code_status
#!/bin/bash
# function:monitor web status from zabbix
# License: GPL
# mail:itnihao@qq.com
# version:1.0 date:2012-12-09
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 /etc/zabbix/scripts/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
(2)域名文件
shell# cat /etc/zabbix/scripts/Web.txt
http://www.itnihao.com
http://www.baidu.com
http://www.weibo.com
(3)测试脚本执行成功与否:
shell# sh web_site_code_status web_site_discovery
{
“data”:[
{
“{#SITENAME}”:”www.itnihao.com”},
{
“{#SITENAME}”:”www.baidu.com”},
{
“{#SITENAME}”:”www.weibo.com”}]}
3、自定义key配置文件
shell# cat /etc/zabbix/zabbix_agentd.conf.d/web_site_discovery.confUserParameter=web.site.discovery,/etc/zabbix/scripts/web_site_code_status web_site_discovery
UserParameter=web.site.code[*],/etc/zabbix/scripts/web_site_code_status web_site_code $1
4、测试语句
shell# zabbix_get -s 127.0.0.1 -k web.site.discovery{
“data”:[
{
“{#SITENAME}”:”www.itnihao.com”},
{
“{#SITENAME}”:”www.baidu.com”},
{
“{#SITENAME}”:”www.weibo.com”}]}
shell# zabbix_get -s 127.0.0.1 -k web.site.code[www.itnihao.com]
200
shell# zabbix_get -s 127.0.0.1 -k web.site.code[www.baidu.com]
200
shell# zabbix_get -s 127.0.0.1 -k web.site.code[www.weibo.com]
200
5、对以上修改的文件列个清单,具体如下:
/etc/zabbix/zabbix_agentd.conf #Agent配置文件
/etc/zabbix/scripts/web_site_code_status #权限755
/etc/zabbix/scripts/Web.txt #网站URL存放文件
/etc/zabbix/zabbix_agentd.conf.d/web_site_discovery.conf#子配置文件
6、Web 页面添加
(1)创建templates
(2)创建Application
(3)创建Discovery rules
注意:宏(Macro)中的{#SITENAME}来自自动发现脚本中的变量{#SITENAME}
(4)创建Item prototypes
$1 代表我们检测出来的URL,web.site.code[{#SITENAME}] 中的变量会依次检测这几个URL
(5)创建Trigger prototypes
(6)设置多梯度告警检测
设置不同周期的告警:2 分钟、10 分钟、15 分钟三种不同故障级别的告警。
Last of(T)设置时间或者次数,Time shift设置时间偏移。如,last()表示最后一次,last(#3,120)表示2分钟内所有数据的第3次数据。
(7)创建Graph prototypes
(8)添加模板到主机
(9)查看图形数据