Enviado em 09/11/2023 - 10:10h
Bom dia Amigos VOL, Seguindo a referencia abaixo:
#!/bin/bash
address="192.168.0.244"
index=$(snmpwalk -v2c -c public $address IF-MIB::ifName | awk '{ print $1 }' | sed -e 's/[^0-9 ]//ig')
for id in $index
do
# Capturar pacotes de entrada
interface=$(snmpwalk -v2c -c public $address IF-MIB::ifName.$id | awk '{ print $4 }')
entrada1=$(snmpget -v2c -c public $address IF-MIB::ifInOctets.$id |awk {'print $4'} )
sleep 5
entrada2=$(snmpget -v2c -c public $address IF-MIB::ifInOctets.$id |awk {'print $4'} )
# Capturar pacotes de Saida
saida1=$(snmpget -v2c -c public $address IF-MIB::ifOutOctets.$id |awk {'print $4'} )
sleep 5
saida2=$(snmpget -v2c -c public $address IF-MIB::ifOutOctets.$id |awk {'print $4'} )
# Calculo do tamanho dos pacotes
trafficIn=$(echo "$entrada2 - $entrada1 " | bc)
trafficOut=$(echo "$saida2 - $saida1 " | bc)
# Display do resultado
if [ $trafficIn -lt 2000 ] && [ $trafficOut -lt 2000 ] ; then
echo "OK : Interface $interface = Traffic In: $trafficIn, Traffic Out: $trafficOut"
exit 0;
else
echo "CRITICAL : Interface $interface = Traffic In: $trafficIn, Traffic Out: $trafficOut"
exit 1;
fi
done
Critical : Interface Et0/0 = Traffic In: 384931, Traffic Out: 384641
Ok : Interface Et0/1 = Traffic In: 0, Traffic Out: 0
Ok : Interface Et0/2 = Traffic In: 0, Traffic Out: 0
Ok : Interface Et0/3 = Traffic In: 0, Traffic Out: 0
Ok : All Interfaces are OK
Critical : Interface Et0/0 = Traffic In: 384931, Traffic Out: 384641