# As the snmp packages come without MIB files due to license reasons, loading# of MIBs is disabled by default. If you added the MIBs you can reenable# loading them by commenting out the following line.
mibs :
# If you want to globally change where snmp libraries, commands and daemons# look for MIBS, change the line below. Note you can set this for individual# tools with the -M option or MIBDIRS environment variable.## mibdirs /usr/share/snmp/mibs:/usr/share/snmp/mibs/iana:/usr/share/snmp/mibs/ietf
# snmpwalk -v 2c -c public 10.0.0.1 sysUpTime
Bad operator (INTEGER): At line 73in /usr/share/snmp/mibs/ietf/SNMPv2-PDU
DISMAN-EXPRESSION-MIB::sysUpTimeInstance = Timeticks: (1235303)3:25:53.03
#!/bin/bash
set -e
set -o pipefail
SMISTRIP=/usr/bin/smistrip
CONFDIR=/etc/snmp-mibs-downloader
. $CONFDIR/snmp-mibs-downloader.conf
download_mibs()
{
TMP="$(mktemp -d)"
if [ ! -z "$ARCHIVE" ]; then
ARCHTMP="$(mktemp -d)"
if [ "$ARCHTYPE" == "dirgz" ]; then
if [ ! -z "$HOST" ]; then
echo "Downloading a whole directory with compressed content"
echo "is not supported."
exit 1
else
cp "$DIR/$ARCHIVE"/* "$ARCHTMP/"
gzip -d "$ARCHTMP"/* || /bin/true
fi
else
if [ ! -z "$HOST" ]; then
wget -O "$ARCHTMP/$ARCHIVE" -q -nv "$HOST/$DIR/$ARCHIVE"
else
cp "$DIR/$ARCHIVE" "$ARCHTMP/$ARCHIVE"
fi
case "$ARCHTYPE" in
tar)
tar -C "$ARCHTMP" -xf "$ARCHTMP/$ARCHIVE"
;;
tgz)
tar -C "$ARCHTMP" -xzf "$ARCHTMP/$ARCHIVE"
;;
zip)
unzip -d "$ARCHTMP" "$ARCHTMP/$ARCHIVE"
;;
esac
fi
fi
while read -r file mibs; do
if [ "$file" != "#" ]; then
if [ ! -z "$PREFIX" ]; then
file="$PREFIX$file"
fi
if [ ! -z "$SUFFIX" ]; then
file="$file$SUFFIX"
fi
if [ -z "$ARCHIVE" ]; then
archive_fetcher=(wget -O - -q -nv "$HOST/$DIR/$file")
else
archive_fetcher=(cat "$ARCHTMP/$ARCHDIR/$file")
fi
"${archive_fetcher[@]}" \
| tr -d \\r \
| $SMISTRIP -v -a -d "$TMP" -m "$mibs" -
fi
done <"$CONFDIR/$CONF"
if [ ! -z "$DIFF" ]; then
patch -d "$TMP" <"$CONFDIR/$DIFF"
fi
if [ ! -d "$BASEDIR/$DEST" ]; then
mkdir -p "$BASEDIR/$DEST"
fi
cp "$TMP"/* "$BASEDIR/$DEST"
rm -f "$BASEDIR/$DEST/.index"
rm -fr "$TMP"
if [ ! -z "$ARCHTMP" ]; then
rm -rf "$ARCHTMP"
fi
}
list_mibs()
{
while read -r file mibs; do
if [ "$file" = "#" ]; then
continue
fi
echo "$mibs" | tr ':' '\n'
done <"$CONFDIR/$CONF"
}
MODE='get'
while [ $# -gt 0 ]; do
case $1 in
--get)
MODE='get'
;;
--list)
MODE='list'
;;
*)
break
esac
shift
done
if [ $MODE = get ]; then
echo ""
echo "Downloading documents and extracting MIB files."
echo "This will take some minutes."
echo ""
echo "In case this process fails, it can always be repeated later by executing"
echo "$0 again."
echo ""
fi
sources=$1
if [ -z "$sources" ]; then
sources="$AUTOLOAD"
fi
for i in $sources; do
TMP=
ARCHTMP=
HOST=
DIR=
CONF=
DEST=
DIFF=
PREFIX=
SUFFIX=
ARCHIVE=
ARCHTYPE=
ARCHDIR=
. "$CONFDIR/$i.conf"
if [ $MODE = list ]; then
list_mibs
else
download_mibs
fi
done