Attivare il mapping dei nomi SNMP delle interfacce in NTOP
Questo script mappa i nomi delle interfacce snmp estraendo gli IP dei monitored devices da redis
export NTOPSNMPCOMMUNITY="public"
- Creare lo script:
cat > /usr/local/sbin/make_snmp_mappings.sh <<EOFile
#!/bin/bash
COMMUNITY=$1
NEW_DEV_DETECTED="1"
if [ -z "$COMMUNITY" ]
then
echo "Usage: $0 snmp_community_name"
exit 127
fi
IPS=$(redis-cli -h 127.0.0.1 --scan --pattern '*' | grep snmp| grep system | cut -f 2-5 --delimiter='.')
if [ -f /etc/nprobe/snmp_mappings.txt ]
then
/bin/mv -f /etc/nprobe/snmp_mappings.txt /etc/nprobe/snmp_mappings.txt.old
fi
for IP in $IPS
do
echo "Adding $IP"
/usr/local/sbin/build_snmp_mappings.sh $IP 2c ${COMMUNITY} >> /etc/nprobe/snmp_mappings.txt
done
if [ -f /etc/nprobe/snmp_mappings.txt.old ]
then
diff -q /etc/nprobe/snmp_mappings.txt /etc/nprobe/snmp_mappings.txt.old
NEW_DEV_DETECTED="$?"
fi
if [ $NEW_DEV_DETECTED -eq "1" ]
then
echo "New device detected. Restart Nprobe"
#echo "New device detected. Restart Ntop and Nprobe"
#systemctl restart ntopng.service
for UNIT in $(systemctl list-units nprobe\* --all | grep nprobe | grep '\.service' | tr -s ' ' | cut -f 2 --delimiter=' ')
do
systemctl restart $UNIT
done
else
echo "No new devices detected"
fi
EOFile
- Renderlo eseguibile
chmod +x /usr/local/sbin/make_snmp_mappings.sh
- Creare il link allo script che crea il file, o copiare e customizzare l'originale per usare la descrizione dell'interfaccia:
ln -s /usr/local/sbin/build_snmp_mappings.sh /usr/bin/build_snmp_mappings.sh
- Provare lo script
/usr/local/sbin/make_snmp_mappings.sh $NTOPSNMPCOMMUNITY
- Creare il cronjob
cat > /etc/cron.d/ntopngSnmpMappings <<EOFile # Check for new SNMP deviced and map them every 5 minutes /5 * * * * root /usr/local/sbin/make_snmp_mappings.sh $NTOPSNMPCOMMUNITY > /dev/null EOFile