原理:在智象智能运维平台系统配置安装过程中,利用snmp协议在交换机上设置trap陷阱,当端口状态发生改变时,通知监控主机,监控主机配置snmptrapd进行接收,然后告警给用户。
一、智象运维中交换机配置部分(需要查看具体产品文档,这里以华为S9306为例):
displaysnmp-agenttrapfeature-nameifnetall------------------------------------------------------------------------------Featurename:IFNETTrapnumber:17------------------------------------------------------------------------------TrapnameDefaultswitchstatusCurrentswitchstatushwIfFlowDownoffoffhwIfFlowUpoffoffhwIfNameChangeoffoffhwIfNameChangeResumeoffoffhwIfMonitorInputRateRisingoffoffhwIfMonitorInputRateResumeoffoffhwIfMonitorOutputRateRisingoffoffhwIfMonitorOutputRateResumeoffoffhwEntityExtCfmOverSlotoffoffhwEntityExtCfmOverCardoffofflinkDownoffofflinkUpoffoffhwIfControlFlapSuppressoffoffhwIfControlFlapResumeoffoffhwExtInterfaceDeleteoffoffhwIfMonitorCrcErrorRisingoffoffhwIfMonitorCrcErrorResumeoffoff------------------------------------------------------------------------------snmp-agenttrapenablefeature-nameifnettrap-namelinkdownsnmp-agenttrapenablefeature-nameifnettrap-namelinkupsnmp-agenttarget-hosttrapaddressudp-domain192.168.1.172sourceVlanif4001paramssecuritynamepublicv2cdissnmp-agenttarget-hostTarget-hostNO.1-----------------------------------------------------------IP-address:192.168.1.172(trap服务器地址)Sourceinterface:Vlanif4001VPNinstance:-Securityname:%@%@Wkz7H#,G'@JZvn-ayZ"Nf2')%@%@Port:162Type:trapVersion:v2cLevel:NoauthenticationandprivacyNMStype:NMSWithext-vb:No-----------------------------------------------------------
二、trap服务器配置:
1、安装snmptrapd,根据系统类型安装并配置:
Ubuntu:apt-getinstallsnmptrapd-yCentOS:yuminstall-ynet-snmpnet-snmp-utilsnet-snmp-perl
2、配置snmpd:
cat/etc/snmp/snmptrapd.conf#Exampleconfigurationfileforsnmptrapd##Notrapsarehandledbydefault,youmusteditthisfile!##authCommunitylog,execute,netpublic#traphandleSNMPv2-MIB::coldStart/usr/bin/bin/my_great_scriptcoldauthCommunitylog,execute,netpublictraphandleIF-MIB::linkDown/monitor/notification.shtraphandleIF-MIB::linkUp/monitor/notification.sh
三、编写脚本:
1、告警脚本:
[root@monitormonitor]#catnotification.sh#!/bin/shreadblankreadipswitch_ip=`/bin/echo$ip|/bin/awk-F'[''{print$2}'|/bin/awk-F']''{print$1}'`whilereadoidvaldoif["$oid"="SNMPv2-MIB::snmpTrapOID.0"];thenif_status=`/bin/echo$val|/bin/awk-F"link"'{print$2}'`fiif/bin/echo$oid|/bin/grepifDescr;thenif_name=`/bin/echo$val`fidoneif[$if_status="Up"];thenmsg=`/bin/echo"OK!Switch($switch_ip)--$if_name--$if_status"`elsemsg=`/bin/echo"Critical!Switch($switch_ip)--$if_name--$if_status"`fi/monitor/sendwx.sh"$msg"
2、编写sendwx.sh告警通知脚本,根据实际情况自行编写,这里暂不作示例。