參考 :
http://blog.csdn.net/qq942477618/article/details/53928951
http://hao360.blog.51cto.com/5820068/1653638/
說明:zabbix版本用的是2.4的版本
一 zabbix 客戶端配置
1 寫一個自動發現腳本 ,腳本的目錄在/usr/local/zabbix/scripts/web_site_code_status.sh (,腳本的名字自定義)
cat web_site_code_status.sh
#!/bin/bash
# function:monitor web site code status from zabbix
# License: GPL
# mail:admin#itnihao.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 /home/usr/local/zabbix/scripts/WEB1.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 http://$1ttp://$1ttp://$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 同樣的在/usr/local/zabbix/scripts/WEB1.txt下面建立一個文件裏面寫上你要監控網站的url ##域名前面不需要加http
www.ihnhlife.com
m.ihnhlife.com
s.ihnhlife.com
www.baidu.com
www.qq.com
3 編輯zabbix_agentd配置文件,自定義key
UserParameter=web.site.discovery,/usr/local/zabbix/scripts/web_site_code_status.sh web_site_discovery
UserParameter=web.site.code[*],/usr/local/zabbix/scripts/web_site_code_status.sh web_site_code $1
4 服務端測試 ,在服務端輸入 zabbix_get -s 192.168.127.130 -k web.site.discovery,返回下面的內容即爲正常。(130是客戶端Ip)
zabbix_get -s 192.168.127.130 -k web.site.discovery
{
"data":[
{
"{#SITENAME}":"www.baidu.com"},
{
"{#SITENAME}":"www.qq.com"},
{
"{#SITENAME}":"www.ihnhlife.com"},
{
"{#SITENAME}":"s.ihnhlife.com"},
{
"{#SITENAME}":"m.ihnhlife.com"}]}
5 在服務端測試
zabbix_get -s 192.168.127.130 -k web.site.codewww.baidu.com]
200
第二種寫法:
/home/usr/local/zabbix/bin/zabbix_get -s 127.0.0.1 -p 10050 -k web.site.code[http://58.116.122.250/op/generate.aspx]
200
二 web頁面操作
1 創建模板
2 點擊application ,然後單擊create application
設置組的名稱爲web_site_code_status
3 單擊discovery rules,然後create discovery rule
4)添加items, 注意:(在自動發現規則裏面添加)單擊item prototypes----create item prototype
5 創建trigger 單擊trigger prototypes
點擊add之後會出現下面的這個
6 創建圖像單擊graph prototypes---create graph prototype
到此,模板創建完成了,然後給相應的主機倒入模板即可
如果你還想監控別的網站,在客戶端裏面的WEB1.txt裏面直接添加網址即可。
如果有現成的模板直接導入即可。