如何开启snmp端口(配置监控交换机详细教程)

星辰博客 来源:互联网 栏目:IT教程

如何开启snmp端口(配置监控交换机详细教程)(1)

原理:在智象智能运维平台系统配置安装过程中,利用snmp协议在交换机上设置trap陷阱,当端口状态发生改变时,通知监控主机,监控主机配置snmptrapd进行接收,然后告警给用户。

一、智象运维中交换机配置部分(需要查看具体产品文档,这里以华为S9306为例):

displaysnmp-agenttrapfeature-nameifnetall
------------------------------------------------------------------------------
Featurename:IFNET
Trapnumber:17
------------------------------------------------------------------------------
TrapnameDefaultswitchstatusCurrentswitchstatus
hwIfFlowDownoffoff
hwIfFlowUpoffoff
hwIfNameChangeoffoff
hwIfNameChangeResumeoffoff
hwIfMonitorInputRateRisingoffoff
hwIfMonitorInputRateResumeoffoff
hwIfMonitorOutputRateRisingoffoff
hwIfMonitorOutputRateResumeoffoff
hwEntityExtCfmOverSlotoffoff
hwEntityExtCfmOverCardoffoff
linkDownoffoff
linkUpoffoff
hwIfControlFlapSuppressoffoff
hwIfControlFlapResumeoffoff
hwExtInterfaceDeleteoffoff
hwIfMonitorCrcErrorRisingoffoff
hwIfMonitorCrcErrorResumeoffoff
------------------------------------------------------------------------------
snmp-agenttrapenablefeature-nameifnettrap-namelinkdown
snmp-agenttrapenablefeature-nameifnettrap-namelinkup
snmp-agenttarget-hosttrapaddressudp-domain192.168.1.172sourceVlanif4001paramssecurityname public v2c
dissnmp-agenttarget-host
Target-hostNO.1
-----------------------------------------------------------
IP-address:192.168.1.172(trap服务器地址)
Sourceinterface:Vlanif4001
VPNinstance:-
Securityname:%@%@Wkz7H#,G'@JZvn-ayZ"Nf2')%@%@
Port:162
Type:trap
Version:v2c
Level:Noauthenticationandprivacy
NMStype:NMS
Withext-vb:No
-----------------------------------------------------------

二、trap服务器配置:

1、安装snmptrapd,根据系统类型安装并配置:

Ubuntu:
apt-get install snmptrapd -y
CentOS:
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_scriptcold
authCommunitylog,execute,net public
traphandleIF-MIB::linkDown/monitor/notification.sh
traphandleIF-MIB::linkUp/monitor/notification.sh

三、编写脚本:

1、告警脚本:

[root@monitormonitor]#catnotification.sh
#!/bin/sh

readblank
readip
switch_ip=`/bin/echo$ip|/bin/awk-F'[''{print$2}'|/bin/awk-F']''{print$1}'`

whilereadoidval
do
if["$oid"="SNMPv2-MIB::snmpTrapOID.0"];then
if_status=`/bin/echo$val|/bin/awk-F"link"'{print$2}'`
fi
if/bin/echo$oid|/bin/grepifDescr;then
if_name=`/bin/echo$val`
fi
done

if[$if_status="Up"];then
msg=`/bin/echo"OK!Switch($switch_ip)--$if_name--$if_status"`
else
msg=`/bin/echo"Critical!Switch($switch_ip)--$if_name--$if_status"`
fi
/monitor/sendwx.sh"$msg"

2、编写sendwx.sh告警通知脚本,根据实际情况自行编写,这里暂不作示例。