SnamTrap and Zabbix
Centos 6
- edit /etc/snmp/snmptrapd.conf
disableAuthorization yes
traphandle default /usr/sbin/snmptt
snmpTrapdAddr udp:10.100.0.2:162
doNotLogTraps yes
- /etc/snmp/snmptt.ini
snmptt_conf_files = <<END
/etc/snmp/snmptt.conf
END
- Add MIB in /etc/snmp/snmptt.conf
EVENT linkDown .1.3.6.1.6.3.1.1.5.3 “Status Events” Normal
FORMAT ZBXTRAP $aA Link down on interface $1. Admin state: $2. Operational state: $4
EXEC /usr/lib/zabbix/externalscripts/zabbix_trapper.sh $aA $1 $4EVENT linkUp .1.3.6.1.6.3.1.1.5.4 “Status Events” Normal
FORMAT ZBXTRAP $aA Link up on interface $1. Admin state: $2. Operational state: $4
EXEC /usr/lib/zabbix/externalscripts/zabbix_trapper.sh $aA $1 $4
- cat /usr/lib/zabbix/externalscripts/zabbix_trapper.sh
!/bin/sh
ZABBIX_CONFIG_FILE=”/etc/zabbix/zabbix_agentd.conf”
MYSQL=”/usr/bin/mysql”
MYSQL_USER=”zabbix_user”
MYSQL_DB=”zabbix”
#MYSQL_PASS=”*”
ZABBIX_SENDER=”/usr/bin/zabbix_sender”export MYSQL_TEST_LOGIN_FILE=/root/.mylogin.cnf
#
#
#Mysql password !!!!
#mysql_config_editor print –all
#set zabbix
#
#
host_ip=$1
snmpintid=$2
ifoperstatus=$3
#
# 1 ⇒ up
#2 ⇒ down
#3 ⇒ testing
#4 ⇒ unknown
#5 ⇒ dormant
#6 ⇒ notPresent
#7 ⇒ lowerLayerDown
if [ “X${ifoperstatus}” == “Xup” ]
then
ifoperstatusd=1
elif [ “X${ifoperstatus}” == “Xdown” ]
then
ifoperstatusd=2
else
ifoperstatusd=4
fi
mysql=”select h.host from hosts as h ,interface as i where i.hostid=h.hostid and i.ip=’${host_ip}'”
hostname=echo ${mysql} | ${MYSQL} --login-path=${MYSQL_USER} ${MYSQL_DB} -N
#echo “${ZABBIX_SENDER} -z localhost -p 10051 -s \”${hostname}\” -k zabbixTrapKey[zabbixTrapKey.${snmpintid}] -o ${ifoperstatusd} — ${host_ip}” > /tmp/zabbix_sender.txta
${ZABBIX_SENDER} -z localhost -p 10051 -s “${hostname}” -k zabbixTrapKey[zabbixTrapKey.${snmpintid}] -o ${ifoperstatusd} > /dev/null 2>&1
In Zabbix Create new element with Type=”Zabbix trapper”
and
key = “zabbixTrapKey[zabbixTrapKey.{#SNMPINDEX}]”



