1.环境介绍:
Zabbix Server:192.168.3.168
Keepalived Server(Zabbix Agent): 192.168.8.11
Zabbix Server监控keepalived,需要事先知道keepalived设置的VIP地址。
2.在zabbix_agentd上编写监控keepalived的脚本,并且设置属主和属组为zabbix,赋予执行权限。
mkdir –p /etc/zabbix/scripts
cd /etc/zabbix/scripts
vim keepalived.addr.availability.sh,内容如下:
#/usr/bin/env bash
# Description: determines if the IP address is available on this server
# Author:
lutaoxu@87long.comPATH='/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'
IPADDR=$1
[[ $1 ]] || { echo "ZBX_NOTSUPPORTED, need at least one parameter in which IP address must be specified."; exit 1; }
[[ -f $(which ip 2>/dev/null) ]] || { echo "ZBX_NOTSUPPORTED, ip utility from iproute2 not found."; exit 1; }
if ip addr show |grep -qo $IPADDR; then echo "Up"; else echo "Not present"; fi
vim keepalived.addr.discovery.sh,内容如下:
#!/usr/bin/env bash
# Description: keepalived virtual addreses auto-discovery
# Author:
lutaoxu@87long.comKEEPALIVED_CONF=$1
[[ $1 ]] || { echo "ZBX_NOTSUPPORTED, need at least one parameter in which keepalived.conf must be specified"; exit 1; }
[[ -f $KEEPALIVED_CONF ]] || { echo "ZBX_NOTSUPPORTED, $KEEPALIVED_CONF doesn't exist" ; exit 1; }
ADDRESSES=$(sed -n -e '/virtual_ipaddress {/,/}/p' $KEEPALIVED_CONF |grep -v ^# |awk '{print $1}' |grep -oE '([0-9]{1,3}[\.]){3}[0-9]{1,
3}*')
echo -n '{"data":['
for addr in $ADDRESSES; do echo -n "{\"{#KADDR}\": \"$addr\"},"; done |sed -e 's:\},$:\}:'
echo -n ']}'
chmod o+x keepalived.addr.availability.sh
chmod o+x keepalived.addr.discovery.sh
chown zabbix.zabbix keepalived.addr.availability.sh keepalived.addr.discovery.sh
3.修改keepalived服务器上zabbix客户端zabbix_agentd.conf配置文件,在配置文件最下面添加监控内容后,重启zabbix agentd服务。
UserParameter=keepalived.addr.discovery[*],/etc/zabbix/scripts/keepalived.addr.discovery.sh /etc/keepalived/keepalived.conf
UserParameter=keepalived.addr.availability[*],/etc/zabbix/scripts/keepalived.addr.availability.sh 192.168.8.11
4.在zabbix server端进行Zabbix_get测试,获取到数据,说明没问题。
/usr/bin/zabbix_get -s 192.168.8.11 -p 10050 -k "proc.num[keepalived]"
/usr/bin/zabbix_get -s 192.168.8.11 -p 10050 -k "keepalived.addr.availability[*]"
/usr/bin/zabbix_get -s 192.168.8.11 -p 10050 -k "keepalived.addr.availability[{#KADDR}]"
5.在网上搜索zabbix监控keepalived的模板,把模板导入zabbix 服务器。
<?xml version="1.0" encoding="UTF-8"?>
<zabbix_export>
<version>2.0</version>
<date>2013-12-25T06:35:12Z</date>
<groups>
<group>
<name>Templates</name>
</group>
</groups>
<templates>
<template>
<template>Keepalived-Template</template>
<name>Keepalived-Template</name>
<groups>
<group>
<name>Templates</name>
</group>
</groups>
<applications>
<application>
<name>Keepalived</name>
</application>
</applications>
<items>
<item>
<name>Keepalived: process count</name>
<type>0</type>
<snmp_community/>
<multiplier>0</multiplier>
<snmp_oid/>
<key>proc.num[keepalived]</key>
<delay>60</delay>
<history>1</history>
<trends>365</trends>
<status>0</status>
<value_type>3</value_type>
<allowed_hosts/>
<units/>
<delta>0</delta>
<snmpv3_securityname/>
<snmpv3_securitylevel>0</snmpv3_securitylevel>
<snmpv3_authpassphrase/>
<snmpv3_privpassphrase/>
<formula>1</formula>
<delay_flex/>
<params/>
<ipmi_sensor/>
<data_type>0</data_type>
<authtype>0</authtype>
<username/>
<password/>
<publickey/>
<privatekey/>
<port/>
<description/>
<inventory_link>0</inventory_link>
<applications>
<application>
<name>Keepalived</name>
</application>
</applications>
<valuemap/>
</item>
</items>
<discovery_rules>
<discovery_rule>
<name>Keepalived: virtual address discovery</name>
<type>0</type>
<snmp_community/>
<snmp_oid/>
<key>keepalived.addr.discovery[/etc/keepalived/keepalived.conf]</key>
<delay>600</delay>
<status>0</status>
<allowed_hosts/>
<snmpv3_securityname/>
<snmpv3_securitylevel>0</snmpv3_securitylevel>
<snmpv3_authpassphrase/>
<snmpv3_privpassphrase/>
<delay_flex/>
<params/>
<ipmi_sensor/>
<authtype>0</authtype>
<username/>
<password/>
<publickey/>
<privatekey/>
<port/>
<filter>{#KADDR}:</filter>
<lifetime>1</lifetime>
<description/>
<item_prototypes>
<item_prototype>
<name>Keepalived: virtual address $1 status</name>
<type>0</type>
<snmp_community/>
<multiplier>0</multiplier>
<snmp_oid/>
<key>keepalived.addr.availability[{#KADDR}]</key>
<delay>60</delay>
<history>7</history>
<trends>365</trends>
<status>0</status>
<value_type>4</value_type>
<allowed_hosts/>
<units/>
<delta>0</delta>
<snmpv3_securityname/>
<snmpv3_securitylevel>0</snmpv3_securitylevel>
<snmpv3_authpassphrase/>
<snmpv3_privpassphrase/>
<formula>1</formula>
<delay_flex/>
<params/>
<ipmi_sensor/>
<data_type>0</data_type>
<authtype>0</authtype>
<username/>
<password/>
<publickey/>
<privatekey/>
<port/>
<description/>
<inventory_link>0</inventory_link>
<applications>
<application>
<name>Keepalived</name>
</application>
</applications>
<valuemap/>
</item_prototype>
</item_prototypes>
<trigger_prototypes/>
<graph_prototypes/>
</discovery_rule>
</discovery_rules>
<macros/>
<templates/>
<screens/>
</template>
</templates>
</zabbix_export>
6.导入模板。登录zabbix web界面后,点击“组态”—“模板”—“汇入”—“浏览文件”—“选择文件”—“汇入”。
7.创建触发器,创建完触发器点击“添加”。
触发器名称:Keepalived process count
触发器表达式:{Keepalived-Template:proc.num[keepalived].last(0)}<1
严重性:严重。
8.创建图形。
图形名称:Keepalived: process count
项目—添加—选择192.168.8.11:Keepalived: process count。
9.添加主机。登录zabbix web界面后,选择“组态”—“主机”—“创建主机”—“模板”—“选择Keepalived-Template模板”—“启用主机”。