zabbix 批量监控web服务状态
背景:需要监控业务网站的状态,于是采用zabbix 实现。
操作步骤:
1)部署脚本到zabbix proxy的/etc/zabbix/script目录
[root@zabbix-proxy zabbix]# ll scripts/
total 12
-rwxr-xr-x 1 root root 4439 Sep 16 22:59 url.txt
-rwxr-xr-x 1 root root 934 Jan 23 2019 web_site_code_status
[root@zabbix-proxy zabbix]#
[root@zabbix-proxy-de zabbix]# head scripts/url.txt
#公司官网:
https://sss.com/pc/en/home.html
https://ssss.com/wap/en/home.html
#OA
https://xxx.ssss.com/api.php
#主机官网:
https://en-console.xxxxx.com
#论坛:
https://forum-xxxx.xxxxx.com
https://forum-xx.xxxxxx.com
[root@zabbix-proxy-de scripts]# cat web_site_code_status #!/bin/bash # function:monitor tcp connect status from zabbix source /etc/bashrc >/dev/null 2>&1 source /etc/profile >/dev/null 2>&1 web_site_discovery () { WEB_SITE=($(cat /etc/zabbix/scripts/url.txt|grep -v "^#" |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 -L -s -w '%{http_code}\n' "$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
重启zabbix agent
2)web页面添加
创建模板,自动发现
最后将模板添加到zabbix proxy中
完