.添加url监控脚本
[root@node1 usr]# vim /usr/local/zabbix_agents_3.2.0/scripts/web_site_code_status.sh
#!/bin/bash UrlFile="/usr/local/zabbix_agents_3.2.0/scripts/WEB.txt"
IFS=$'\n' web_site_discovery () {
WEB_SITE=($(cat $UrlFile|grep -v "^#"))
printf '{\n'
printf '\t"data":[\n'
num=${#WEB_SITE[@]}
for site in ${WEB_SITE[@]}
do
num=$(( $num - ))
url=$(echo $site|awk '{print $1}')
ip=$(echo $site|awk '{print $2}')
if [ $num -ne ] ; then
printf "\t\t{\"{#SITENAME}\":\""%s"\",\"{#PROXYIP}\":\""${ip}"\"},\n" ${url}
else
printf "\t\t{\"{#SITENAME}\":\""%s"\",\"{#PROXYIP}\":\""${ip}"\"}\n" ${url}
printf '\t]\n'
printf '}\n'
fi
done
} web_site_code () {
if [ "$2" == "" ]; then
curl -s -k --connect-timeout -m -o /dev/null -w %{http_code} "https://$1"
elif echo $ |grep ':' &>/dev/null ; then
curl -s -k --connect-timeout -m -o /dev/null -w %{http_code} "https://$1" -x $
else
curl -s -k --connect-timeout -m -o /dev/null -w %{http_code} "https://$1" -x $:
fi
} case "$1" in
web_site_discovery)
web_site_discovery
;;
web_site_code)
web_site_code $ $
;;
*)
echo "Usage:$0 {web_site_discovery|web_site_code [URL]}"
;;
esac [root@node1 usr]# chmod +x /usr/local/zabbix_agents_3.2.0/scripts/web_site_code_status.sh .在zabbix客户端加配置文件:
zabbix-agent中打开配置
Include=/usr/local/zabbix_agents_3.2.0/conf/zabbix_agentd/*.conf vim /usr/local/zabbix_agents_3.2.0/conf/zabbix_agentd/web_site_discovery.conf UserParameter=web.site.discovery,/usr/local/zabbix_agents_3.2.0/scripts/web_site_code_status.sh web_site_discovery
UserParameter=web.site.code[*],/usr/local/zabbix_agents_3.2.0/scripts/web_site_code_status.sh web_site_code $1 $2 [root@node1 usr]# cat /usr/local/zabbix_agents_3.2.0/scripts/WEB.txt
http://www.baidu.com
http://www.sina.com.cn
http://www.163.com 10.10.10.10
http://www.sohu.com 115.23.16.97:80
http://www.111.com # 客户端测试
[root@account_web03:~]# /usr/local/zabbix_agents_3.2.0/scripts/web_site_code_status.sh web_site_discovery
{
"data":[
{"{#SITENAME}":"www.wondershare.com","{#PROXYIP}":""},
{"{#SITENAME}":"www.wondershare.net","{#PROXYIP}":""},
{"{#SITENAME}":"www.wondershare.jp","{#PROXYIP}":""},
{"{#SITENAME}":"www.wondershare.de","{#PROXYIP}":""}, # 服务端测试 [root@node5 ~]# zabbix_get -s 10.11.0.210 -k 'web.site.discovery'
{
"data":[
{"{#SITENAME}":"http://www.baidu.com","{#PROXYIP}":""},
{"{#SITENAME}":"http://www.sina.com.cn","{#PROXYIP}":""},
{"{#SITENAME}":"http://www.163.com","{#PROXYIP}":"10.10.10.10"},
{"{#SITENAME}":"http://www.sohu.com","{#PROXYIP}":"115.23.16.97:80"},
{"{#SITENAME}":"http://www.111.com","{#PROXYIP}":""}
]
} 被监控端 zabbix_Agentd.conf 的配置调整: ServerActive=*.*.*.* #zabbix_server的ip
Hostname=agent_host_name #重要:主机名
RefreshActiveChecks=1800 #被监控端到服务器获取监控项的周期
BufferSize=200 #被监控端存储监控信息的空间大小
Timeout=10 #超时时间
比较重要的参数是ServerActive和Hostname,ServerActive是指定Agentd收集的数据往哪里发送,Hostname是必须要和Server端添加主机时的主机名一样,这样Server端接收到数据才能找到对应关系。 3.服务端配置,导入自动发现的模板
4.也可以自定义item,具体如下:
触发器另外的写法,5次触发:
{urls_monitor_rsync:web.site.code[{#SITENAME},].count(#5,200,"eq")}=0 and {urls_monitor_rsync:web.site.code[{#SITENAME},].count(#5,301,"eq")}=0
自动发现模板
<?xml version="1.0" encoding="UTF-8"?>
<zabbix_export>
<version>3.4</version>
<date>--14T01::17Z</date>
<groups>
<group>
<name>Templates</name>
</group>
</groups>
<templates>
<template>
<template>Template Web Monitor_active</template>
<name>Template Web Monitor_active</name>
<description/>
<groups>
<group>
<name>Templates</name>
</group>
</groups>
<applications>
<application>
<name>web_monitor</name>
</application>
</applications>
<items/>
<discovery_rules>
<discovery_rule>
<name>web.site.discovery</name>
<type></type>
<snmp_community/>
<snmp_oid/>
<key>web.site.discovery</key>
<delay></delay>
<status></status>
<allowed_hosts/>
<snmpv3_contextname/>
<snmpv3_securityname/>
<snmpv3_securitylevel></snmpv3_securitylevel>
<snmpv3_authprotocol></snmpv3_authprotocol>
<snmpv3_authpassphrase/>
<snmpv3_privprotocol></snmpv3_privprotocol>
<snmpv3_privpassphrase/>
<params/>
<ipmi_sensor/>
<authtype></authtype>
<username/>
<password/>
<publickey/>
<privatekey/>
<port/>
<filter>
<evaltype></evaltype>
<formula/>
<conditions/>
</filter>
<lifetime>30d</lifetime>
<description/>
<item_prototypes>
<item_prototype>
<name>monitor_site $ $ response code</name>
<type></type>
<snmp_community/>
<snmp_oid/>
<key>web.site.code[{#SITENAME},{#PROXYIP}]</key>
<delay></delay>
<history>7d</history>
<trends>365d</trends>
<status></status>
<value_type></value_type>
<allowed_hosts/>
<units/>
<snmpv3_contextname/>
<snmpv3_securityname/>
<snmpv3_securitylevel></snmpv3_securitylevel>
<snmpv3_authprotocol></snmpv3_authprotocol>
<snmpv3_authpassphrase/>
<snmpv3_privprotocol></snmpv3_privprotocol>
<snmpv3_privpassphrase/>
<params/>
<ipmi_sensor/>
<authtype></authtype>
<username/>
<password/>
<publickey/>
<privatekey/>
<port/>
<description/>
<inventory_link></inventory_link>
<applications>
<application>
<name>web_monitor</name>
</application>
</applications>
<valuemap/>
<logtimefmt/>
<preprocessing/>
<jmx_endpoint/>
<application_prototypes/>
<master_item_prototype/>
</item_prototype>
</item_prototypes>
<trigger_prototypes>
<trigger_prototype>
<expression>{Template Web Monitor_active:web.site.code[{#SITENAME},{#PROXYIP}].last()}<> and {Template Web Monitor_active:web.site.code[{#SITENAME},{#PROXYIP}].last()}<></expression>
<recovery_mode></recovery_mode>
<recovery_expression/>
<name>web_monitor {#SITENAME} {#PROXYIP}</name>
<correlation_mode></correlation_mode>
<correlation_tag/>
<url/>
<status></status>
<priority></priority>
<description/>
<type></type>
<manual_close></manual_close>
<dependencies/>
<tags/>
</trigger_prototype>
</trigger_prototypes>
<graph_prototypes/>
<host_prototypes/>
<jmx_endpoint/>
</discovery_rule>
</discovery_rules>
<httptests/>
<macros/>
<templates/>
<screens/>
</template>
</templates>
</zabbix_export>