温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

使用nagios监控交换机端口流量,对低于阈值的流量进行报警

发布时间:2020-05-27 18:31:32 来源:网络 阅读:1252 作者:plpy 栏目:移动开发

需求:使用nagios服务需要对一台思科交换机的24端口进行流量监控,当流量低于2MB/s时,发送报警;当流量高于3MB/s时,报警取消;当流量介于2MB/s-3MB/s时,处于警告warning状态。


操作方法:


第一:编写脚本文件:

vim /usr/lib64/nagios/plugins/check_traffic_less.sh

#!/bin/bash
RXpre=$(/usr/bin/snmpwalk -v 2c -c public 10.10.3.242 IF-MIB::ifInOctets.10124 | awk '{print $4}')
sleep 1
RXnext=$(/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 ]];then
RX=$(echo $RX | awk '{print $1/1048576 "MB/s"}')
   echo "critical,RX is $RX"
   exit 2
elif [[ $RX -gt 3145728 ]];then
RX=$(echo $RX | awk '{print $1/1048576 "MB/s"}')
   echo "ok,RX is $RX"
   exit 0
else
RX=$(echo $RX | awk '{print $1/1048576 "MB/s"}')
   echo "warning,RX is $RX"
   exit 1
fi

第二:添加权限
chmod +x check_traffic_less.sh

第三:配置commands.cfg文件
define command{
      command_name   check_traffic_less
      command_line   $USER1$/check_traffic_less.sh
}

第四:配置switch.cfg文件
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
        }

第五:重新加载服务::
service nagios reload

结果截图:

使用nagios监控交换机端口流量,对低于阈值的流量进行报警

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI