Requirements: Get the current bandwidth of the switch if the threshold is exceeded, send a short message alarm mainly use the company's SMS interface and Snmpwalk command to achieve a basic Environment 1, version cat /etc/debian_version 7.82, kernel uname -r3.2.0-4-amd643, IP (eth0) 10.1.10.185 Second, the specific script #!/bin/bash#-------------------------------------- ------------#Author: jimmygong#email:[email protected] #FileName: shcnc.sh#function: Gets the switch bandwidth exceeds the threshold to send a short message # version:1.0 #Created: 2015-11-12#--------------------------------------------------#apt-get -y install snmp curl links or yum -y install curl links net-snmp-utilsfunction get () { hostip= ' 111.111.111.111 ' snmpc= "222222222222" hostport= "1111" timed= " " in1=$ (snmpwalk -ov -v 2c -c $snmpc $hostip if-mib:: Ifhcinoctets. $hostport) in1=${in1#*: } out1=$ (snmpwalk -Ov -v 2c -c $snmpc $hostip if-mib::ifhcoutoctets $hostport) out1=${out1#*: } sleep $timed in2=$ (snmpwalk -ov -v 2c -c $SNMPC $hostip if-mib::ifhcinoctets. $hostport) in2=${in2#*: } out2=$ (snmpwalk -ov -v 2c -c $snmpc $hostip if-mib: : Ifhcoutoctets. $hostport) out2=${out2#*: } in=$ (($in 2-$in 1 ) *8/1000000/$timed)) out=$ ((($out 2-$out 1) *8/1000000/$timed)) echo $in: $out}function send () { g=$ (GET) i= ${g%:*} e=${g#*:} c=95 telgroup= ( 11111111111) sign= "222222222222222" if [[ $i -gt $c ]] &Nbsp;then msg= "Shcnc%20ingress%20rate:%20${i}mbps%20>%20$c" for tt in ${telgroup[@]} do /usr/ bin/links -dump "http://111.111.111.111/aaa/back.send?mobile= $tt &msg= $msg &sms_sign= $sign" done fi if [[ $e -gt $c ]] then msg= "Shcnc%20egress%20rate:%20${e}mbps%20>%20$c" for tt in ${telgroup[@]} do /usr/bin/curl "Http://111.111.111.111/aaa/back.send? mobile= $tt &msg= $msg &sms_sign= $sign " done fi}sendexit 0
This article is from the "7928217" blog, please be sure to keep this source http://7938217.blog.51cto.com/7928217/1712358
Get switch bandwidth exceeding threshold on alarm