码迷,mamicode.com
首页 > 其他好文 > 详细

zabbix3.2使用fping批量监控ip的连通性

时间:2018-09-13 23:11:37      阅读:315      评论:0      收藏:0      [点我收藏+]

标签:bubuko   nts   sep   必须   \n   一个   ping   lse   func   

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.编写自动发现脚本

[root@eus_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 {\n 
        printf \t"data":[\n 
for((i=0;i<${#WEB_IP[@]};++i)) 
{ 
num=$(echo $((${#WEB_IP[@]}-1))) 
        if [ "$i" != ${num} ]; 
                then 
        printf "\t\t{ \n" 
        printf "\t\t\t\"{#SITENAME}\":\"${WEB_IP[$i]}\"},\n" 
                else 
                        printf  "\t\t{ \n" 
                        printf  "\t\t\t\"{#SITENAME}\":\"${WEB_IP[$num]}\"}]}\n" 
        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


[root@eus_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: cant 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 就可以解决这个问题。)

[root@eus_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
[root@eus_dlcbs_web01:/usr/local/zabbix_agents_3.2.0/scripts]# chmod u+s /usr/local/fping/sbin/fping 
[root@eus_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,这样不能快速知道是哪台服务器出了问题,所以带上主机名,如下
# 自动发现脚本

[root@eus_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 {\n 
        printf \t"data":[\n 
for((i=0;i<${#WEB_IP[@]};++i)) 
{ 
num=$(echo $((${#WEB_IP[@]}-1))) 
        if [ "$i" != ${num} ]; 
                then 
        printf "\t\t{ \n" 
        printf "\t\t\t\"{#SITENAME}\":\"${WEB_IP[$i]}\"},\n" 
                else 
                        printf  "\t\t{ \n" 
                        printf  "\t\t\t\"{#SITENAME}\":\"${WEB_IP[$num]}\"}]}\n" 
        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的连通性

标签:bubuko   nts   sep   必须   \n   一个   ping   lse   func   

原文地址:https://www.cnblogs.com/reblue520/p/9643775.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!