1. 程式人生 > >使用nagios監控交換機端口流量,對低於閾值的流量進行報警

使用nagios監控交換機端口流量,對低於閾值的流量進行報警

交換機 nagios snmp

需求:使用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

結果截圖:

技術分享

本文出自 “榮耀屬於前輩” 博客,請務必保留此出處http://lipenglong.blog.51cto.com/5309038/1946063

使用nagios監控交換機端口流量,對低於閾值的流量進行報警