Last active
March 14, 2020 17:24
-
-
Save jpawlowski/6aaaba6c353d6f9b380d0de9d2a266fe to your computer and use it in GitHub Desktop.
SNMP MIB and SNMPTT helper script for Zabbix integration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# This Script creates the following files to be used for | |
# Zabbix SNMP and SNMP trap integration: | |
# | |
# /etc/snmp/snmp.conf | |
# /etc/snmp/snmptt.conf.VENDOR | |
# Symlink vendor specific MIB files from | |
# $MIBS_VENDORS to $MIBS | |
# | |
# The actual order for the snmp.conf is defined in a vendor | |
# specific file that needs to be created manually! | |
# | |
# | |
MIBS_VENDORS=/usr/share/snmp/mibs_vendors | |
MIBS=/usr/share/snmp/mibs | |
find $MIBS/ -type l -exec rm -v {} \; | |
# | |
# MIB | |
# | |
rm -vf /etc/snmp/snmp.conf | |
for dir in $MIBS_VENDORS/*; do | |
if [ ! -d $dir ]; then | |
continue; | |
fi | |
VENDOR=${dir##/*/} | |
echo "##### MIB: Processing vendor $VENDOR ######" | |
CURRENT=`find $dir/* -type d -printf '%T@s %p\n' | sort -n | tail -1 | cut -f2- -d" "` | |
echo "# $VENDOR" >> /etc/snmp/snmp.conf | |
for file in $CURRENT/*.mib; do | |
DEST=${file::-4}-MIB.txt | |
DEST=$MIBS/${DEST##/*/} | |
DEST=`echo $DEST | sed -e "s/\/rfc/\/RFC/"` | |
if [[ -e "$DEST" ]]; then | |
echo "$DEST already existing, won't link from $file" | |
else | |
ln -s $file $DEST | |
fi | |
if [ ! -f $dir.order ]; then | |
echo "mibfile $file" >> /etc/snmp/snmp.conf | |
fi | |
done | |
if [ -f $dir.order ]; then | |
cat $dir.order >> /etc/snmp/snmp.conf | |
fi | |
done | |
service snmptrapd restart | |
# | |
# snmptt | |
# | |
for dir in $MIBS_VENDORS/*; do | |
if [ ! -d $dir ]; then | |
continue; | |
fi | |
VENDOR=${dir##/*/} | |
echo "##### SNMPTT: Processing vendor $VENDOR ######" | |
rm -vf /etc/snmp/snmptt.conf.$VENDOR | |
touch /etc/snmp/snmptt.conf.$VENDOR | |
CURRENT=`find $dir/* -type d -printf '%T@s %p\n' | sort -n | tail -1 | cut -f2- -d" "` | |
for file in $CURRENT/*.mib; do | |
grep -q TRAP-TYPE $file | |
if [ $? -eq 0 ]; then | |
/usr/sbin/snmpttconvertmib --in=$file --out=/etc/snmp/snmptt.conf.$VENDOR | |
continue; | |
fi | |
grep -q NOTIFICATION-TYPE $file | |
if [ $? -eq 0 ]; then | |
/usr/sbin/snmpttconvertmib --in=$file --out=/etc/snmp/snmptt.conf.$VENDOR | |
fi | |
done | |
sed -i 's/FORMAT/FORMAT ZBXTRAP $aA/g' /etc/snmp/snmptt.conf.$VENDOR | |
done | |
service snmptt restart |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment