网络设备snmp
- 1、安装
- 1.1、安装net-snmp服务
- 1.2、安装net-snmp-utils工具
- 2、snmpwalk命令实践
- 3、H3C交换机命令
- 4、snmpwalk 命令说明书
1、安装
1.1、安装net-snmp服务
安装snmp服务
sudo yum install -y net-snmp
添加服务开机启动
sudo systemctl enable snmpd
启动服务
sudo systemctl start snmpd
查看服务状态
sudo systemctl status snmpd
停止正在执行的snmpd服务
sudo systemctl stop snmpd
关闭开机自启动snmpd服务
sudo systemctl disable snmpd
配置snmpd服务
sudo vim /etc/snmp/snmpd.conf
===============================================================
编辑snmpd服务配置,找到行
com2sec notConfigUser default public
修改为
# 允许ip为192.168.20.32的 管理主机如zabbix 访问 社区名称为 public
com2sec notConfigUser 192.168.168.32 public
# 允许本机访问用于测试 社区名称为 public
com2sec notConfigUser 127.0.0.1 public
===============================================================
保存退出后,重启snmpd发服务
sudo systemctl restart snmpd
运行命令,开放161端口并重载防火墙
sudo firewall-cmd --add-port=161/udp --permanent
sudo firewall-cmd --reload
1.2、安装net-snmp-utils工具
yum install -y net-snmp-utils
测试读取本机系统信息 社区名称为public
snmpwalk -v 2c -c public 127.0.0.1 system
snmpwalk -v 2c -c public 127.0.0.1 sysdesc
2、snmpwalk命令实践
华三OID链接: https://www.h3c.com/cn/d_202202/1545944_30005_0.htm
查看系统开机运行时长
snmpwalk -v 2c -c public 127.0.0.1 sysUptime
snmpwalk -v 2c -c public 127.0.0.1 IfNumber
snmpwalk -v 2c -c public 127.0.0.1 IfDescr
snmpwalk -v 2c -c public 127.0.0.1 IfInOctet
==========================================
#### 获取光模块的温度
光模块温度:hh3cTransceiverTemperature
节点OID值:1.3.6.1.4.1.25506.2.70.1.1.1.15
## 列出本交换机上所有的能显示的所有光模块的温度
snmpwalk -v 2c -c public 192.168.46.246 1.3.6.1.4.1.25506.2.70.1.1.1.15
------------------------------------
SNMPv2-SMI::enterprises.25506.2.70.1.1.1.15.1 = INTEGER: 19
SNMPv2-SMI::enterprises.25506.2.70.1.1.1.15.2 = INTEGER: 34
SNMPv2-SMI::enterprises.25506.2.70.1.1.1.15.5 = INTEGER: 23
SNMPv2-SMI::enterprises.25506.2.70.1.1.1.15.6 = INTEGER: 2147483647
SNMPv2-SMI::enterprises.25506.2.70.1.1.1.15.8 = INTEGER: 2147483647
SNMPv2-SMI::enterprises.25506.2.70.1.1.1.15.24 = INTEGER: 34
## 仅列出24口的光模块温度
snmpwalk -v 2c -c snmp#public@read 192.168.46.246 1.3.6.1.4.1.25506.2.70.1.1.1.15.24
-----------------------------------
SNMPv2-SMI::enterprises.25506.2.70.1.1.1.15.24 = INTEGER: 34
================================================
#### 获取光模块电压
光模块电压:hh3cTransceiverVoltage
节点OID值:1.3.6.1.4.1.25506.2.70.1.1.1.16
## 列出本交换机上所有的能显示的所有光模块的电压
snmpwalk -v 2c -c public 192.168.100.100 1.3.6.1.4.1.25506.2.70.1.1.1.16
-----------------------------------------
SNMPv2-SMI::enterprises.25506.2.70.1.1.1.16.1 = INTEGER: 332
SNMPv2-SMI::enterprises.25506.2.70.1.1.1.16.2 = INTEGER: 333
SNMPv2-SMI::enterprises.25506.2.70.1.1.1.16.5 = INTEGER: 331
SNMPv2-SMI::enterprises.25506.2.70.1.1.1.16.6 = INTEGER: 2147483647
SNMPv2-SMI::enterprises.25506.2.70.1.1.1.16.8 = INTEGER: 2147483647
SNMPv2-SMI::enterprises.25506.2.70.1.1.1.16.14 = INTEGER: 332
SNMPv2-SMI::enterprises.25506.2.70.1.1.1.16.24 = INTEGER: 334
## 仅列出24口的光模块电压 需要换算下 334/100=3.34
C:\usr\bin>snmpwalk -v 2c -c snmp#public@read 192.168.46.246 1.3.6.1.4.1.25506.2.70.1.1.1.16.24
SNMPv2-SMI::enterprises.25506.2.70.1.1.1.16.24 = INTEGER: 334
================================================
#### 获取光模块发光功率:
光模块发光功率:hh3cTransceiverCurTXPower
节点OID值:1.3.6.1.4.1.25506.2.70.1.1.1.9
## 列出交换机上所有光模块发光功率 有异常值的一般都是非H3C模块或不被H3C认可的模块
snmpwalk -v 2c -c public 192.168.100.100 1.3.6.1.4.1.25506.2.70.1.1.1.9
SNMPv2-SMI::enterprises.25506.2.70.1.1.1.9.1 = INTEGER: -194
SNMPv2-SMI::enterprises.25506.2.70.1.1.1.9.2 = INTEGER: -582
SNMPv2-SMI::enterprises.25506.2.70.1.1.1.9.6 = INTEGER: 2147483647
SNMPv2-SMI::enterprises.25506.2.70.1.1.1.9.8 = INTEGER: 2147483647
SNMPv2-SMI::enterprises.25506.2.70.1.1.1.9.14 = INTEGER: -556
SNMPv2-SMI::enterprises.25506.2.70.1.1.1.9.24 = INTEGER: 161
snmpwalk -v 2c -c public 192.168.100.100 1.3.6.1.4.1.25506.2.70.1.1.1.10
## 仅列出24口的光模块发光功率 需要换算下 161/100=1.61
C:\usr\bin>snmpwalk -v 2c -c snmp#public@read 192.168.46.246 1.3.6.1.4.1.25506.2.70.1.1.1.9.24
SNMPv2-SMI::enterprises.25506.2.70.1.1.1.9.24 = INTEGER: 161
==========================================
#### 获取光模块收光功率
光模块收光功率:hh3cTransceiverCurRXPower
节点OID值:1.3.6.1.4.1.25506.2.70.1.1.1.12
## 列出交换机上所有光模块收光功率 有异常值的一般都是非H3C模块或不被H3C认可的模块
snmpwalk -v 2c -c public 192.168.100.100 1.3.6.1.4.1.25506.2.70.1.1.1.12
-----------------------------------------
SNMPv2-SMI::enterprises.25506.2.70.1.1.1.12.1 = INTEGER: -178
SNMPv2-SMI::enterprises.25506.2.70.1.1.1.12.2 = INTEGER: -564
SNMPv2-SMI::enterprises.25506.2.70.1.1.1.12.3 = INTEGER: -744
SNMPv2-SMI::enterprises.25506.2.70.1.1.1.12.7 = INTEGER: 2147483647
SNMPv2-SMI::enterprises.25506.2.70.1.1.1.12.8 = INTEGER: 2147483647
SNMPv2-SMI::enterprises.25506.2.70.1.1.1.12.14 = INTEGER: -556
SNMPv2-SMI::enterprises.25506.2.70.1.1.1.12.24 = INTEGER: -1585
## 仅列出24口的光模块收光功率 需要换算下 -1585/100=-15.85 因为取值有时间差异,和命令行获取差0.02
snmpwalk -v 2c -c public 192.168.46.246 1.3.6.1.4.1.25506.2.70.1.1.1.12.24
----------------------------------------------
SNMPv2-SMI::enterprises.25506.2.70.1.1.1.12.24 = INTEGER: -1585
3、H3C交换机命令
1、查看光模块的信息
display transceiver interface
dis transceiver interface g 1/0/28
其中g 1/0/28为端口号。
这个命令可以查看光模块的基本信息,包括温度、电压、电流、接收功率等。这个命令适用于华三交换机。
2、查看所有光口的收发光功率信息
display transceiver diagnosis interface
dis transceiver diagnosis interface
这个命令可以查看所有光口的收发光功率信息。这个命令适用于华为交换机。
3、查看某光口的收发光功率信息
display transceiver diagnosis interface interface-type interface-number
dis transceiver diagnosis interface XGigabitEthernet 1/10/1/10 verbose
其中XGigabitEthernet 1/10/1/10为端口号。
这个命令可以查看某个光口的收发光功率信息。这个命令适用于华为交换机。
# 先通过端口索引oid获取指定端口的索引值,然后通过使用收发光oid+端口索引的形式获取本端口的收发光
# 使用snmpwalk扫描端口 1/3/0/25 的索引值为 316
snmpwalk -c public -v 2c 192.168.50.70 1.3.6.1.2.1.2.2.1.2 | grep 1/3/0/25
IF-MIB::ifDescr.316 = STRING: Ten-GigabitEthernet1/3/0/25
# 使用snmpget获取端口 1/3/0/25 的发光值为 50
snmpwalk -c public -v 2c 192.168.50.70 1.3.6.1.4.1.25506.2.70.1.1.1.9.316
SNMPv2-SMI::enterprises.25506.2.70.1.1.1.9.316 = INTEGER: 50
# 使用snmpget获取 1/3/0/25 的收光值为 -1717
snmpwalk -c public -v 2c 192.168.50.70 1.3.6.1.4.1.25506.2.70.1.1.1.12.316
SNMPv2-SMI::enterprises.25506.2.70.1.1.1.12.316 = INTEGER: -1717
4、snmpwalk 命令说明书
snmpwalk --help
================================================
-c COMMUNITY set the community string;SNMP Version 1 or 2c specific;v1 v2c版本使用
-v 1|2c|3 specifies SNMP version to use 指定snmp版本
-V, --version display package version number
ip地址; 指令(获取网络设备的信息);名称方式 / OID方式
General communication options 基本通用的参数配置
-r RETRIES set the number of retries 设置重试次数
-t TIMEOUT set the request timeout (in seconds) 设置请求超时时间
USAGE: snmpwalk [OPTIONS] AGENT [OID]
Version: 5.7.2
Web: http://www.net-snmp.org/
Email: net-snmp-coders@lists.sourceforge.net
OPTIONS:
-h, --help display this help message
-H display configuration file directives understood
SNMP Version 3 specific
-a PROTOCOL set authentication protocol (MD5|SHA)
-A PASSPHRASE set authentication protocol pass phrase
-e ENGINE-ID set security engine ID (e.g. 800000020109840301)
-E ENGINE-ID set context engine ID (e.g. 800000020109840301)
-l LEVEL set security level (noAuthNoPriv|authNoPriv|authPriv)
-n CONTEXT set context name (e.g. bridge1)
-u USER-NAME set security name (e.g. bert)
-x PROTOCOL set privacy protocol (DES|AES)
-X PASSPHRASE set privacy protocol pass phrase
-Z BOOTS,TIME set destination engine boots/time
Debugging
-d dump input/output packets in hexadecimal
-D[TOKEN[,...]] turn on debugging output for the specified TOKENs
(ALL gives extremely verbose debugging output)
General options
-m MIB[:...] load given list of MIBs (ALL loads everything)
-M DIR[:...] look in given list of directories for MIBs
(default: $HOME/.snmp/mibs:/usr/share/snmp/mibs)
-P MIBOPTS Toggle various defaults controlling MIB parsing:
u: allow the use of underlines in MIB symbols
c: disallow the use of "--" to terminate comments
d: save the DESCRIPTIONs of the MIB objects
e: disable errors when MIB symbols conflict
w: enable warnings when MIB symbols conflict
W: enable detailed warnings when MIB symbols conflict
R: replace MIB symbols from latest module
-O OUTOPTS Toggle various defaults controlling output display:
0: print leading 0 for single-digit hex characters
a: print all strings in ascii format
b: do not break OID indexes down
e: print enums numerically
E: escape quotes in string indices
f: print full OIDs on output
n: print OIDs numerically
q: quick print for easier parsing
Q: quick print with equal-signs
s: print only last symbolic element of OID
S: print MIB module-id plus last element
t: print timeticks unparsed as numeric integers
T: print human-readable text along with hex strings
u: print OIDs using UCD-style prefix suppression
U: don't print units
v: print values only (not OID = value)
x: print all strings in hex format
X: extended index format
-I INOPTS Toggle various defaults controlling input parsing:
b: do best/regex matching to find a MIB node
h: don't apply DISPLAY-HINTs
r: do not check values for range/type legality
R: do random access to OID labels
u: top-level OIDs must have '.' prefix (UCD-style)
s SUFFIX: Append all textual OIDs with SUFFIX before parsing
S PREFIX: Prepend all textual OIDs with PREFIX before parsing
-L LOGOPTS Toggle various defaults controlling logging:
e: log to standard error
o: log to standard output
n: don't log at all
f file: log to the specified file
s facility: log to syslog (via the specified facility)
(variants)
[EON] pri: log to standard error, output or /dev/null for level 'pri' and above
[EON] p1-p2: log to standard error, output or /dev/null for levels 'p1' to 'p2'
[FS] pri token: log to file/syslog for level 'pri' and above
[FS] p1-p2 token: log to file/syslog for levels 'p1' to 'p2'
-C APPOPTS Set various application specific behaviours:
p: print the number of variables found
i: include given OID in the search range
I: don't include the given OID, even if no results are returned
c: do not check returned OIDs are increasing
t: Display wall-clock time to complete the walk
T: Display wall-clock time to complete each request
E {OID}: End the walk at the specified OID