zabbix的discovery自动发现功能,要求版本在2.0以上,包括服务器端和客户端:
zabbix客户端的配置:
编辑自动发现脚本:路径自己决定: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
/etc/zabbix/sbin/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
chmod +x web_site_code_status.sh
===========================================================================================
2.编辑WEB.txt:(输入要监控的url,文件路径要与脚本中的一致 )
ubuntu@VM-200-135-ubuntu:/etc/zabbix/sbin$ cat WEB.txt
#http://10.133.200.135:8050/get/game/config?gameid=10&pn=com.izhangxin.ddz.lua.test&version=2.1.1&fwversion=15042901&versioncode=5
statics.hiigame.com
10.133.200.135:8050/get/game/config?gameid=10&pn=com.izhangxin.ddz.lua.test&version=2.1.1&fwversion=15042901&versioncode=5
=============================================================================
3.修改客户端的配置文件:
ubuntu@VM-200-135-ubuntu:/etc/zabbix/zabbix_agentd.conf.d$ cat web_site_discovery.conf
UserParameter=web.site.discovery,/etc/zabbix/web_site_code_status.sh web_site_discovery UserParameter=web.site.code[*],/etc/zabbix/web_site_code_status.sh web_site_code $1
ubuntu@VM-200-135-ubuntu:/etc/zabbix$ vi zabbix_agentd.conf
Include=/etc/zabbix/zabbix_agentd.conf.d/ #配置文件路径(启用include文件
UnsafeUserParameters=1 #自定义key生效
==========================================================================================
4.测试:服务器端:
用zabbix_get测试:
[root@VM_81_161_centos bin]# /home/data/zabbix/bin/zabbix_get -p 10050 -s 10.133.200.135 -k web.site.discovery
{
"data":[
{
"{#SITENAME}":"statics.hiigame.com"},
{
"{#SITENAME}":"10.133.200.135:8050/get/game/config?gameid=10&pn=com.izhangxin.ddz.lua.test&version=2.1.1&fwversion=15042901&versioncode=5"}]}
[root@VM_81_161_centos bin]# /home/data/zabbix/bin/zabbix_get -p 10050 -s 10.133.200.135 -k web.site.code[statics.hiigame.com]
200