本文共 1763 字,大约阅读时间需要 5 分钟。
我的博客已迁移到xdoujiang.com请去那边和我交流需求:获取交换机当前使用带宽 如果超过阀值就发短消息报警 主要利用公司的短信接口和snmpwalk命令来实现一、基础环境1、版本cat /etc/debian_version 7.82、内核uname -r3.2.0-4-amd643、ip(eth0)10.1.10.185二、具体脚本#!/bin/bash#--------------------------------------------------#Author:jimmygong#Email:jimmygong@taomee.com#FileName:shcnc.sh#Function:获取交换机带宽超过阀值就发短消息 #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="15" 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=$((($in2-$in1)*8/1000000/$timed)) out=$((($out2-$out1)*8/1000000/$timed)) echo $in:$out}function send () { g=$(get) i=${g%:*} e=${g#*:} c=95 telgroup=(11111111111) sign="222222222222222" if [[ $i -gt $c ]] 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
转载于:https://blog.51cto.com/7938217/1712358