zabbix3.2使用fping批量监控ip的连通性
Posted reblue520
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了zabbix3.2使用fping批量监控ip的连通性相关的知识,希望对你有一定的参考价值。
1.在zabbix-agent端安装fping wget http://www.fping.org/dist/fping-3.16.tar.gz tar zxvf fping-3.16.tar.gz cd fping-3.16 ./configure --prefix=/usr/local/fping/ make && make install 2.编写自动发现脚本 [[email protected]_dlcbs_web01:/usr/local/zabbix_agents_3.2.0/scripts]# cat webip_status.sh #!/bin/bash # function:monitor tcp connect status from zabbix web_ip_discovery () { WEB_IP=($(cat /usr/local/zabbix_agents_3.2.0/scripts/webip.txt|grep -v "^#")) printf ‘{ ‘ printf ‘ "data":[ ‘ for((i=0;i<${#WEB_IP[@]};++i)) { num=$(echo $((${#WEB_IP[@]}-1))) if [ "$i" != ${num} ]; then printf " { " printf " "{#SITENAME}":"${WEB_IP[$i]}"}, " else printf " { " printf " "{#SITENAME}":"${WEB_IP[$num]}"}]} " fi } } web_site_code () { /usr/local/fping/sbin/fping $1|grep -c ‘alive‘ } case "$1" in web_ip_discovery) web_ip_discovery ;; web_site_code) web_site_code $2 ;; *) echo "Usage:$0 {web_ip_discovery|web_site_code [URL]}" ;; esac 3.配置编写 vim /usr/local/zabbix_agents_3.2.0/conf/zabbix_agentd/web_ip_discovery.conf UserParameter=web.ip.discovery,/usr/local/zabbix_agents_3.2.0/scripts/webip_status.sh web_ip_discovery UserParameter=web.ip.code[*],/usr/local/zabbix_agents_3.2.0/scripts/webip_status.sh web_site_code $1 [[email protected]_dlcbs_web01:/usr/local/zabbix_agents_3.2.0/scripts]# cat webip.txt 1.1.1.1 2.2.2.2 触发器: web.ip.code {#SITENAME} is not alive # 最近5个取值最大值不为1 {ip_monitor:web.ip.code[{#SITENAME},].max(#5)}<>1 报错处理: Received value [/usr/local/fping/sbin/fping: can‘t create socket (must run as root?) : Permission denied0] is not suitable for value type [Numeric (unsigned)] and data type [Decimal] (这里遇到一个问题,在客户端自测脚本是好的,但是到了服务端怎么样都执行不出来fping,因为fping必须由root执行,如果非root会报错,这是权限问题,chmod u+s /usr/local/fping/sbin/fping 就可以解决这个问题。) [[email protected]_dlcbs_web01:/usr/local/zabbix_agents_3.2.0/scripts]# ll /usr/local/fping/sbin/fping -rwxr-xr-x 1 root root 87700 Sep 11 20:54 /usr/local/fping/sbin/fping [[email protected]_dlcbs_web01:/usr/local/zabbix_agents_3.2.0/scripts]# chmod u+s /usr/local/fping/sbin/fping [[email protected]_dlcbs_web01:/usr/local/zabbix_agents_3.2.0/scripts]# ll /usr/local/fping/sbin/fping -rwsr-xr-x 1 root root 87700 Sep 11 20:54 /usr/local/fping/sbin/fping # 触发报警的时候由于只是显示IP,这样不能快速知道是哪台服务器出了问题,所以带上主机名,如下 # 自动发现脚本 [[email protected]_dlcbs_web01:/usr/local/zabbix_agents_3.2.0/scripts]# cat webip_status.sh #!/bin/bash # function:monitor tcp connect status from zabbix web_ip_discovery () { WEB_IP=($(cat /usr/local/zabbix_agents_3.2.0/scripts/ips.txt|grep -v "^#")) printf ‘{ ‘ printf ‘ "data":[ ‘ for((i=0;i<${#WEB_IP[@]};++i)) { num=$(echo $((${#WEB_IP[@]}-1))) if [ "$i" != ${num} ]; then printf " { " printf " "{#SITENAME}":"${WEB_IP[$i]}"}, " else printf " { " printf " "{#SITENAME}":"${WEB_IP[$num]}"}]} " fi } } web_site_code () { ip=`echo $1|awk -F ‘:‘ ‘{print $1}‘` #echo $ip /usr/local/fping/sbin/fping ${ip}|grep -c ‘alive‘ } case "$1" in web_ip_discovery) web_ip_discovery ;; web_site_code) web_site_code $2 ;; *) echo "Usage:$0 {web_ip_discovery|web_site_code [URL]}" ;; esac # webip.txt 1.1.1.1:cbs_web01 2.2.2.2:cbs_web02
自动发现配置
以上是关于zabbix3.2使用fping批量监控ip的连通性的主要内容,如果未能解决你的问题,请参考以下文章
zabbix使用fping监控任意两个节点之间的网络质量丢包率和响应时间