标签:etc mamicode oca agent 用户 scripts mic parameter 空值
zabbix 简单监控ipv6地址的连通性,参照Template ICMP Ping模板
0-1、服务器已有ipv6地址,ipv6涉及配置文件(部分可不管):
/usr/share/oem/grub.cfg
/etc/modprobe*
/etc/sysconfig/network
/etc/sysctl.conf /etc/sysctl.conf.first
/etc/ssh/sshd_config
/etc/sysconfig/network-scripts/ifcfg-$ifcfg
/etc/sysconfig/network-scripts/route6-$ifcfg # ip -6 route add default dev "$ifcfg"
modprobe ipv6 && lsmod | grep ipv6
ip6tables
...
0-2、zabbix server端编译(建议不开ipv6也可加上):
./configure --prefix=/usr/local/zabbix/ --enable-server --enable-agent --with-mysql --with-net-snmp --with-libcurl --with-libxml2 --enable-ipv6
make; make install # 重编译安装不会覆盖老的配置文件等
1-0、因为fping和fping6是区分的,但zabbix本身会不支持两个同时启用且能识别ipv6地址,需要应下载最新fping包编译安装(或者自定义shell脚本过滤ipv4地址使之兼容,但相对繁琐些。废弃!)
wget http://www.fping.org/dist/fping-4.2.tar.gz
tar xf fping-4.2.tar.gz && cd fping-4.2
./configure && make && make install
chmod u+x /usr/local/sbin/fping
cp -ra /usr/sbin/fping{,.bak} && cp -ra /usr/sbin/fping6{,.bak}
cp -ra /usr/local/sbin/fping /usr/sbin/fping
# 可先测试看新fping是否兼容ipv4和ipv6
1-1、取消注释Fping6Location=,且置空值
1-2、重启zabbix_server
1-3、ps aux | grep fping # 查看没有fping6就对了,不然之前同时存在fping和fping6命令的操作且fping不支持ipv6就会页面显示【Cannot send ICMP ping packets to this host.】
2-1、自定义发现key:
UserParameter=discovery.ipv6,sh /usr/local/zabbix/scripts/discovery_ipv6.sh discovery_ipv6
2-2、授权:
chown zabbix:zabbix /usr/local/zabbix/scripts/discovery_ipv6.sh
chmod +x /usr/local/zabbix/scripts/discovery_ipv6.sh
2-3、重启zabbix_agentd
3-1、创建模板:
3-2、创建自动发现规则:
3-3、创建监控原型:
3-4、创建触发器原型:
3-5、链接关联Template IPv6 Address模板到监控原始模板(母模板)
4-1、ipv6地址可自动发现亦可根据资源记录api获取
4-2、其他监控如ip6tables加入/etc/sudoers用户允许然后自定义防火墙监控
附件:
# cat /usr/local/zabbix/scripts/discovery_ipv6.sh
#!/bin/bash
# ipv6 地址发现
function discovery_ipv6(){
ipv6=($(ip a | grep ‘scope global‘ | grep -oP ‘(?<=inet6 )[^/]+‘ | grep -v ‘^fe80‘))
printf ‘{\n‘
printf ‘\t"data":[\n‘
for key in ${!ipv6[@]}
do
if [[ "${#ipv6[@]}" -gt 1 && "${key}" -ne "$((${#ipv6[@]}-1))" ]];then
printf ‘\t {\n‘
printf "\t\t\t\"{#IPV6ADDRESS}\":\"${ipv6[${key}]}\"},\n"
else [[ "${key}" -eq "((${#ipv6[@]}-1))" ]]
printf ‘\t {\n‘
printf "\t\t\t\"{#IPV6ADDRESS}\":\"${ipv6[${key}]}\"}\n"
fi
done
printf ‘\t ]\n‘
printf ‘}\n‘
}
if [ -z "$1" -o "$1" = "discovery_ipv6" ]; then
discovery_ipv6
else
echo "Usage: sh $0 [discovery_ipv6]"
exit 1
fi
标签:etc mamicode oca agent 用户 scripts mic parameter 空值
原文地址:https://blog.51cto.com/8440296/2457563