/etc/zabbix/zabbix_agentd.conf
UnsafeUserParameters=1
UserParameter=ipvsadm.activeconn[],/etc/zabbix/ipvsadm.py active 2 1 3
UserParameter=ipvsadm.weight[],/etc/zabbix/ipvsadm.py weight 2 $3
UserParameter=ipvsadm.discovery,/etc/zabbix/ipvsadm_discover.sh
vi /etc/zabbix/ipvsadm_discover.sh
!/bin/bash
SVC_FLG=1
END_FLG=0
IFS=$'\n'
echo '{"data":['
for LINE in sudo /usr/sbin/ipvsadm -Ln
do
echo ${LINE}
TYPE=`echo ${LINE} | awk '{print $1}'`
IP_INFO=`echo ${LINE} | awk '{print $2}'`
if [ ${END_FLG} != 0 ] ; then
echo ", "
END_FLG=0
fi
if [ "${TYPE}" = "TCP" -o "${TYPE}" = "UDP" ] ; then
CUR_TYPE=${TYPE}
CUR_IP_INFO=${IP_INFO}
SVC_FLG=0
elif [ "${TYPE}" = "->" -a ${SVC_FLG} = 0 ] ; then
echo -n "{\"{#VTYPE}\":\"${CUR_TYPE}\",\"{#VIPINFO}\":\"${CUR_IP_INFO}\",\"{#RIPINFO}\":\"${IP_INFO}\"}"
END_FLG=1
fi
done
echo "]}"
vi /etc/zabbix/ipvaadm.py
!/bin/env python
-- coding: utf-8 --
usage: ipvsadm.py acctiveconn tcp 172.18.0.12:80 172.17.0.22:80
import sys
def parserArgs(args):
p = dict()
if args[1] not in ('active', 'inactive', 'weight') :
print 'type error'
sys.exit(1)
p['type'] = args[1]
p['proto'] = args[2].upper()
vip = args[3].split(':')
p['vipHex'] = ipToHexStr(vip[0])
p['vipPort'] = '%04X' % int(vip[1])
rip = args[4].split(':')
p['ripHex'] = ipToHexStr(rip[0])
p['ripPort'] = '%04X' % int(rip[1])
#print p
return p
def ipToHexStr(ip):
buf=list()
for i in ip.split('.'):
buf.append('%02X' % int(i))
return "".join(buf)
def findData(args):
vip = "%s %s:%s" % (args['proto'], args['vipHex'], args['vipPort'])
rip = " -> %s:%s" % (args['ripHex'], args['ripPort'])
vipStr = None
result = None
for line in file("/proc/net/ip_vs"):
if line.startswith(vip):
vipStr = True
continue
if vipStr is True and line.startswith(rip):
break
# -> AC110016:0050 Masq 1 10 157
import re
values = re.split('\s+', line)
#print values
# ['', '->', 'AC110016:0050', 'Masq', '1', '0', '0', '']
result = dict()
result['weight'] = values[4]
result['active'] = values[5]
result['inactive'] = values[6]
return result[args['type']]
if name == "main":
args = parserArgs(sys.argv)
print findData(args)
导入模板 zb_template.xml
<?xml version="1.0" encoding="UTF-8"?>
<zabbix_export>
<version>3.2</version>
<date>2018-12-21T02:33:10Z</date>
<groups>
<group>
<name>Templates</name>
</group>
</groups>
<templates>
<template>
<template>Template App LVS</template>
<name>Template App LVS</name>
<description/>
<groups>
<group>
<name>Templates</name>
</group>
</groups>
<applications>
<application>
<name>LVS</name>
</application>
</applications>
<items/>
<discovery_rules>
<discovery_rule>
<name>ipvsadm Service</name>
<type>0</type>
<snmp_community/>
<snmp_oid/>
<key>ipvsadm.discovery</key>
<delay>30</delay>
<status>0</status>
<allowed_hosts/>
<snmpv3_contextname/>
<snmpv3_securityname/>
<snmpv3_securitylevel>0</snmpv3_securitylevel>
<snmpv3_authprotocol>0</snmpv3_authprotocol>
<snmpv3_authpassphrase/>
<snmpv3_privprotocol>0</snmpv3_privprotocol>
<snmpv3_privpassphrase/>
<delay_flex/>
<params/>
<ipmi_sensor/>
<authtype>0</authtype>
<username/>
<password/>
<publickey/>
<privatekey/>
<port/>
<filter>
<evaltype>0</evaltype>
<formula/>
<conditions/>
</filter>
<lifetime>30</lifetime>
<description/>
<item_prototypes>
<item_prototype>
<name>Active Connections on {#RIPINFO} for {#VIPINFO} {#VTYPE}</name>
<type>0</type>
<snmp_community/>
<multiplier>0</multiplier>
<snmp_oid/>
<key>ipvsadm.activeconn[{#VTYPE},{#VIPINFO},{#RIPINFO}]</key>
<delay>30</delay>
<history>90</history>
<trends>365</trends>
<status>0</status>
<value_type>3</value_type>
<allowed_hosts/>
<units/>
<delta>0</delta>
<snmpv3_contextname/>
<snmpv3_securityname/>
<snmpv3_securitylevel>0</snmpv3_securitylevel>
<snmpv3_authprotocol>0</snmpv3_authprotocol>
<snmpv3_authpassphrase/>
<snmpv3_privprotocol>0</snmpv3_privprotocol>
<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>LVS</name>
</application>
</applications>
<valuemap/>
<logtimefmt/>
<application_prototypes/>
</item_prototype>
<item_prototype>
<name>InActive Connections on {#RIPINFO} for {#VIPINFO} {#VTYPE}</name>
<type>0</type>
<snmp_community/>
<multiplier>0</multiplier>
<snmp_oid/>
<key>ipvsadm.inactconn[{#VTYPE},{#VIPINFO},{#RIPINFO}]</key>
<delay>30</delay>
<history>90</history>
<trends>365</trends>
<status>0</status>
<value_type>3</value_type>
<allowed_hosts/>
<units/>
<delta>0</delta>
<snmpv3_contextname/>
<snmpv3_securityname/>
<snmpv3_securitylevel>0</snmpv3_securitylevel>
<snmpv3_authprotocol>0</snmpv3_authprotocol>
<snmpv3_authpassphrase/>
<snmpv3_privprotocol>0</snmpv3_privprotocol>
<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>LVS</name>
</application>
</applications>
<valuemap/>
<logtimefmt/>
<application_prototypes/>
</item_prototype>
<item_prototype>
<name>Balance Weight on {#RIPINFO} for {#VIPINFO} {#VTYPE}</name>
<type>0</type>
<snmp_community/>
<multiplier>0</multiplier>
<snmp_oid/>
<key>ipvsadm.weight[{#VTYPE},{#VIPINFO},{#RIPINFO}]</key>
<delay>30</delay>
<history>90</history>
<trends>365</trends>
<status>0</status>
<value_type>3</value_type>
<allowed_hosts/>
<units/>
<delta>0</delta>
<snmpv3_contextname/>
<snmpv3_securityname/>
<snmpv3_securitylevel>0</snmpv3_securitylevel>
<snmpv3_authprotocol>0</snmpv3_authprotocol>
<snmpv3_authpassphrase/>
<snmpv3_privprotocol>0</snmpv3_privprotocol>
<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>LVS</name>
</application>
</applications>
<valuemap/>
<logtimefmt/>
<application_prototypes/>
</item_prototype>
</item_prototypes>
<trigger_prototypes>
<trigger_prototype>
<expression>{Template App LVS:ipvsadm.weight[{#VTYPE},{#VIPINFO},{#RIPINFO}].last()}<1</expression>
<recovery_mode>0</recovery_mode>
<recovery_expression/>
<name>No Weight to {#RIPINFO}</name>
<correlation_mode>0</correlation_mode>
<correlation_tag/>
<url/>
<status>0</status>
<priority>2</priority>
<description/>
<type>0</type>
<manual_close>0</manual_close>
<dependencies/>
<tags/>
</trigger_prototype>
</trigger_prototypes>
<graph_prototypes>
<graph_prototype>
<name>Balance Weight {#RIPINFO} for {#VIPINFO} {#VTYPE}</name>
<width>900</width>
<height>200</height>
<yaxismin>0.0000</yaxismin>
<yaxismax>100.0000</yaxismax>
<show_work_period>1</show_work_period>
<show_triggers>1</show_triggers>
<type>0</type>
<show_legend>1</show_legend>
<show_3d>0</show_3d>
<percent_left>0.0000</percent_left>
<percent_right>0.0000</percent_right>
<ymin_type_1>0</ymin_type_1>
<ymax_type_1>0</ymax_type_1>
<ymin_item_1>0</ymin_item_1>
<ymax_item_1>0</ymax_item_1>
<graph_items>
<graph_item>
<sortorder>0</sortorder>
<drawtype>0</drawtype>
<color>1A7C11</color>
<yaxisside>0</yaxisside>
<calc_fnc>2</calc_fnc>
<type>0</type>
<item>
<host>Template App LVS</host>
<key>ipvsadm.weight[{#VTYPE},{#VIPINFO},{#RIPINFO}]</key>
</item>
</graph_item>
</graph_items>
</graph_prototype>
<graph_prototype>
<name>Connections Statictics on {#RIPINFO} for {#VIPINFO} {#VTYPE}</name>
<width>900</width>
<height>200</height>
<yaxismin>0.0000</yaxismin>
<yaxismax>100.0000</yaxismax>
<show_work_period>1</show_work_period>
<show_triggers>1</show_triggers>
<type>0</type>
<show_legend>1</show_legend>
<show_3d>0</show_3d>
<percent_left>0.0000</percent_left>
<percent_right>0.0000</percent_right>
<ymin_type_1>0</ymin_type_1>
<ymax_type_1>0</ymax_type_1>
<ymin_item_1>0</ymin_item_1>
<ymax_item_1>0</ymax_item_1>
<graph_items>
<graph_item>
<sortorder>0</sortorder>
<drawtype>0</drawtype>
<color>1A7C11</color>
<yaxisside>0</yaxisside>
<calc_fnc>2</calc_fnc>
<type>0</type>
<item>
<host>Template App LVS</host>
<key>ipvsadm.activeconn[{#VTYPE},{#VIPINFO},{#RIPINFO}]</key>
</item>
</graph_item>
<graph_item>
<sortorder>1</sortorder>
<drawtype>0</drawtype>
<color>2774A4</color>
<yaxisside>0</yaxisside>
<calc_fnc>2</calc_fnc>
<type>0</type>
<item>
<host>Template App LVS</host>
<key>ipvsadm.inactconn[{#VTYPE},{#VIPINFO},{#RIPINFO}]</key>
</item>
</graph_item>
</graph_items>
</graph_prototype>
</graph_prototypes>
<host_prototypes/>
</discovery_rule>
</discovery_rules>
<httptests/>
<macros/>
<templates/>
<screens/>
</template>
</templates>
</zabbix_export>