Requirement: Use the Nagios service to monitor 24 ports on a Cisco switch, send an alarm when traffic is below 2mb/s, alarm cancel when traffic is higher than 3mb/s, and in a warning warning state when traffic is between 2mb/s-3mb/s.
Operation Method:
First: Write the script file:
vim/usr/lib64/nagios/plugins/check_traffic_less.sh
#!/bin/bashrxpre=$ (/usr/bin/snmpwalk -v 2c -c public 10.10.3.242 if-mib::ifinoctets.10124 | awk ' {print $4} ') sleep 1rxnext=$ (/usr/bin/snmpwalk -v 2c -c public 10.10.3.242 if-mib::ifinoctets.10124 | awk ' {print $4} ') rx=$ ((${rxnext}-${rxpre})) if [[ $RX -lt 2097152 ]];thenrx=$ (echo $RX | awk ' {print $1/1048576 "MB/S"} ') echo "critical,rx is $RX" exit 2elif [[ $RX -gt 3145728 ]];thenrx=$ (echo $RX | awk ' {print $1/1048576 "MB/S"} ') echo "ok,rx is $RX" exit 0elserx=$ (echo $RX | awk ' {print $1/1048576 ' MB/S "} ') echo " warning,rx is $RX " exit 1fi
Second: Add permissions
chmod +x check_traffic_less.sh
Third: Configure the Commands.cfg file
Define Command{
Command_name check_traffic_less
Command_line $USER 1$/check_traffic_less.sh
}
IV: Configure the Switch.cfg file
Define Service{
Use GENERIC-SERVICE,SRV-PNP; Inherit values from a template
HOST_NAME h19_unicom_access_switch_3.242
Service_description check_traffice_less_g0/24
Check_command check_traffic_less
}
V: Reload Service::
Service Nagios Reload
Results:
650) this.width=650; "title=" Image.png "src=" https://s1.51cto.com/wyfs02/M01/9B/76/ Wkiol1ljwvciuzcoaabckptyqx8528.png "alt=" Wkiol1ljwvciuzcoaabckptyqx8528.png "/>
This article is from the "Glory Belongs to seniors" blog, please be sure to keep this source http://lipenglong.blog.51cto.com/5309038/1946063
Monitor switch port traffic using Nagios to alert traffic below the threshold