eNSP VMWAE SNMP
因为没有真实的交换机 所以使用eNSP生成一台华为的设备 在vmware创建了一台centos7.9的虚拟机用来安装snmp_exporter
R1的配置
[Huawei]sys
[Huawei]sysname r1
[r1-GigabitEthernet0/0/1]ip add 192.168.1.89 24
[r1-GigabitEthernet0/0/1]snmp
[r1]snmp-agent sys-info version v1 #生产环境建议使用v3
[r1]snmp-agent community read huawei
Cloud3配置
虚拟机的配置
安装snmpwalk
yum install net-snmp-utils[root@jk ~]# snmpwalk -v 1 -c huawei 192.168.1.89 sysDescr
SNMPv2-MIB::sysDescr.0 = STRING: Huawei Versatile Routing Platform Software
VRP WVRP-C Software Version VRPV500R011C00B071-GR
Copyright (c) 2000-2011 by VRP Team Beijing Institute Huawei Tech, Inc
Compiled Dec 19 2012 11:52:04 by ZhangWeiming[root@jk ~]# snmpwalk -v 1 -c huawei 192.168.1.89 sysName
SNMPv2-MIB::sysName.0 = STRING: r1
在虚拟机上安装监控软件
golang安装
下载
curl -O https://dl.google.com/go/go1.17.7.linux-amd64.tar.gz
解压
tar -C /usr/local -xzf go1.17.7.linux-amd64.tar.gz
设置环境变量
[root@jk ~]# echo "export PATH=$PATH:/usr/local/go/bin" >> ~/.profile
[root@jk ~]# source ~/.profile
安装完成
[root@jk ~]# go version
go version go1.17.7 linux/amd64设置go代理
export GO111MODULE=on
export GOPROXY=https://goproxy.cn
echo "export GO111MODULE=on" >> ~/.profile
echo "export GOPROXY=https://goproxy.cn" >> ~/.profile
snmp配置文件生成
下载snmp_exporter generator
curl -O https://github.com/prometheus/snmp_exporter/archive/refs/heads/main.zip
unzip snmp_exporter-main.zip
cd snmp_exporter-main
cd generator/
按README.md文件安装
yum install gcc gcc-g++ make net-snmp net-snmp-utils net-snmp-libs net-snmp-devel -y
go build
make mibs 这一步因为我的环境没有上不了"外"网 所以有的mib文件下载失败(make: *** [mibs/KEEPALIVED-MIB] Error 7 )所以从
curl -O https://github.com/librenms/librenms/archive/refs/heads/master.zip
下载了mib文件 解压并cp到generator/mibs中
unzip librenms-master.zip
cd mibs/
cp -r ./* /root/snmp_exporter-main/generator/mibs/cd /root/snmp_exporter-main/generator
编辑配置文件
[root@jk generator]# cat generator.yml
modules:# Default IF-MIB interfaces table with ifIndex.if_mib:walk: [sysUpTime, interfaces, ifXTable]lookups:- source_indexes: [ifIndex]lookup: ifAlias- source_indexes: [ifIndex]# Uis OID to avoid conflict with PaloAlto PAN-COMMON-MIB.lookup: 1.3.6.1.2.1.2.2.1.2 # ifDescr- source_indexes: [ifIndex]# Use OID to avoid conflict with Netscaler NS-ROOT-MIB.lookup: 1.3.6.1.2.1.31.1.1.1.1 # ifNameoverrides:ifAlias:ignore: true # Lookup metricifDescr:ignore: true # Lookup metricifName:ignore: true # Lookup metricifType:type: EnumAsInfoversion: 1auth:community: huaweiexport MIBDIRS=mibs
./generator generate
生成的配置文件在当前目录下snmp.yml
snmp_exporter安装
curl -O https://github.com/prometheus/snmp_exporter/releases/download/v0.20.0/snmp_exporter-0.20.0.linux-amd64.tar.gz
tar -xvf snmp_exporter-0.20.0.linux-amd64.tar.gz -C /opt/
将刚才生成的配置文件cp
cp /root/snmp_exporter-main/generator/mibs/snmp.yml /opt/snmp_exporter-0.20.0.linux-amd64/
cd /opt/snmp_exporter-0.20.0.linux-amd64/运行snmp_exporter
[root@jk snmp_exporter-0.20.0.linux-amd64]# ./snmp_exporter
level=info ts=2022-02-25T12:07:39.476Z caller=main.go:152 msg="Starting snmp_exporter" version="(version=0.20.0, branch=HEAD, revision=c33572b6c8c8e43a479fde0f9fa8ac86e15598bc)"
level=info ts=2022-02-25T12:07:39.476Z caller=main.go:153 build_context="(go=go1.15.8, user=root@eebd39e6960e, date=20210212-11:37:48)"
level=info ts=2022-02-25T12:07:39.479Z caller=main.go:246 msg="Listening on address" address=:9116
level=info ts=2022-02-25T12:07:39.481Z caller=tls_config.go:191 msg="TLS is disabled." http2=false
测试snmp采集
[root@jk ~]# curl 'http://192.168.233.128:9116/snmp?target=192.168.1.89&module=if_mib'
# HELP ifAdminStatus The desired state of the interface - 1.3.6.1.2.1.2.2.1.7
# TYPE ifAdminStatus gauge
ifAdminStatus{ifAlias="",ifDescr="Console0/0/0",ifIndex="3",ifName="Console0/0/0"} 1
ifAdminStatus{ifAlias="",ifDescr="Ethernet0/0/0",ifIndex="4",ifName="Ethernet0/0/0"} 1
ifAdminStatus{ifAlias="",ifDescr="Ethernet0/0/1",ifIndex="5",ifName="Ethernet0/0/1"} 1
ifAdminStatus{ifAlias="",ifDescr="GigabitEthernet0/0/0",ifIndex="6",ifName="GigabitEthernet0/0/0"} 1
ifAdminStatus{ifAlias="",ifDescr="GigabitEthernet0/0/1",ifIndex="7",ifName="GigabitEthernet0/0/1"} 1
ifAdminStatus{ifAlias="",ifDescr="GigabitEthernet0/0/2",ifIndex="8",ifName="GigabitEthernet0/0/2"} 1
ifAdminStatus{ifAlias="",ifDescr="GigabitEthernet0/0/3",ifIndex="9",ifName="GigabitEthernet0/0/3"} 1
ifAdminStatus{ifAlias="",ifDescr="InLoopBack0",ifIndex="1",ifName="InLoopBack0"} 1
ifAdminStatus{ifAlias="",ifDescr="NULL0",ifIndex="2",ifName="NULL0"} 1
ifAdminStatus{ifAlias="",ifDescr="Serial0/0/0",ifIndex="10",ifName="Serial0/0/0"} 1
ifAdminStatus{ifAlias="",ifDescr="Serial0/0/0-ppp",ifIndex="11",ifName=""} 1
ifAdminStatus{ifAlias="",ifDescr="Serial0/0/1",ifIndex="12",ifName="Serial0/0/1"} 1
ifAdminStatus{ifAlias="",ifDescr="Serial0/0/1-ppp",ifIndex="13",ifName=""} 1
ifAdminStatus{ifAlias="",ifDescr="Serial0/0/2",ifIndex="14",ifName="Serial0/0/2"} 1
ifAdminStatus{ifAlias="",ifDescr="Serial0/0/2-ppp",ifIndex="15",ifName=""} 1
ifAdminStatus{ifAlias="",ifDescr="Serial0/0/3",ifIndex="16",ifName="Serial0/0/3"} 1
ifAdminStatus{ifAlias="",ifDescr="Serial0/0/3-ppp",ifIndex="17",ifName=""} 1
# HELP ifConnectorPresent This object has the value 'true(1)' if the interface sublayer has a physical connector and the value 'false(2)' otherwise. - 1.3.6.1.2.1.31.1.1.1.17
# TYPE ifConnectorPresent gauge
ifConnectorPresent{ifAlias="",ifDescr="Console0/0/0",ifIndex="3",ifName="Console0/0/0"} 1
ifConnectorPresent{ifAlias="",ifDescr="Ethernet0/0/0",ifIndex="4",ifName="Ethernet0/0/0"} 1
ifConnectorPresent{ifAlias="",ifDescr="Ethernet0/0/1",ifIndex="5",ifName="Ethernet0/0/1"} 1
ifConnectorPresent{ifAlias="",ifDescr="GigabitEthernet0/0/0",ifIndex="6",ifName="GigabitEthernet0/0/0"} 1
....