Utilizzare i nomi SNMP delle Interfacce di un Router in Nprobe
Jump to navigation
Jump to search
Con script automatico
Se si aggiungono tutti i router monitorati come device SNMP, questo script ne estrae gli ip, e popola il file snmp_mappings.txt
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/bin/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
chmod +x /usr/local/sbin/make_snmp_mappings.sh
Impostare la community:
export COMMUNITY="public"
Prepare il cronjob
if [ -n "$COMMUNITY" ]; then echo "# Check for new SNMP deviced and map them every 5 minutes" > /etc/cron.d/ntopngSnmpMappings; echo "/5 * * * * root /usr/local/sbin/make_snmp_mappings.sh ${COMMUNITY} > /dev/null" >> /etc/cron.d/ntopngSnmpMappings; else echo -e "\nDEFINE COMMUNITY first with export COMMUNITY=\"snmp_communit_name\".\nCRONJOB NOT ENABLED ! \n"; fi
Lanciare il comando manualmente due volte per testartlo
/usr/local/sbin/make_snmp_mappings.sh $COMMUNITY
- Lanciare poi nprobe con il parametro aggiuntivo
vi /etc/nprobe/nprobe-test.conf
### --snmp-mappings /etc/nprobe/snmp_mappings.txt ###
- Riavviare nprobe:
systemctl restart nprobe@test.service
- Nella webgui appaiono i nomi delle interfacce
Manualmente
- Per ogni router, occorre generare il file di testo che contiene i nomi:
/usr/bin/build_snmp_mappings.sh 192.168.253.254 2c public > /etc/nprobe/snmp_mappings.txt
Il contenuto sarà del tipo
192.168.253.254 1 "vtnet0" 192.168.253.254 2 "vtnet1" 192.168.253.254 3 "vtnet2" 192.168.253.254 4 "enc0" 192.168.253.254 5 "lo0" 192.168.253.254 6 "pfsync0" 192.168.253.254 7 "pflog0" 192.168.253.254 8 "ovpns1" 192.168.253.254 9 "ovpns2" 192.168.253.254 10 "ovpns3" 192.168.253.254 11 "ovpns4"
- Lanciare poi nprobe con il parametro aggiuntivo
vi /etc/nprobe/nprobe-test.conf
### --snmp-mappings /etc/nprobe/snmp_mappings.txt ###
- Riavviare nprobe:
systemctl restart nprobe@test.service
- Nella webgui appaiono i nomi delle interfacce