snmpwalk命令的帮助
# snmpwalk --help
USAGE: snmpwalk [OPTIONS] AGENT [OID]Version:  5.7.2Web:      http://www.net-snmp.org/Email:    net-snmp-coders@lists.sourceforge.netOPTIONS:-h, --help            display this help message-H                    display configuration file directives understood-v 1|2c|3             specifies SNMP version to use-V, --version         display package version number
SNMP Version 1 or 2c specific-c COMMUNITY          set the community string
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
General communication options-r RETRIES            set the number of retries-t TIMEOUT            set the request timeout (in seconds)
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 symbolsc:  disallow the use of "--" to terminate commentsd:  save the DESCRIPTIONs of the MIB objectse:  disable errors when MIB symbols conflictw:  enable warnings when MIB symbols conflictW:  enable detailed warnings when MIB symbols conflictR:  replace MIB symbols from latest module-O OUTOPTS            Toggle various defaults controlling output display:0:  print leading 0 for single-digit hex charactersa:  print all strings in ascii formatb:  do not break OID indexes downe:  print enums numericallyE:  escape quotes in string indicesf:  print full OIDs on outputn:  print OIDs numericallyq:  quick print for easier parsingQ:  quick print with equal-signss:  print only last symbolic element of OIDS:  print MIB module-id plus last elementt:  print timeticks unparsed as numeric integersT:  print human-readable text along with hex stringsu:  print OIDs using UCD-style prefix suppressionU:  don't print unitsv:  print values only (not OID = value)x:  print all strings in hex formatX:  extended index format-I INOPTS             Toggle various defaults controlling input parsing:b:  do best/regex matching to find a MIB nodeh:  don't apply DISPLAY-HINTsr:  do not check values for range/type legalityR:  do random access to OID labelsu:  top-level OIDs must have '.' prefix (UCD-style)s SUFFIX:  Append all textual OIDs with SUFFIX before parsingS PREFIX:  Prepend all textual OIDs with PREFIX before parsing-L LOGOPTS            Toggle various defaults controlling logging:e:           log to standard erroro:           log to standard outputn:           don't log at allf file:      log to the specified files 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 foundi:  include given OID in the search rangeI:  don't include the given OID, even if no results are returnedc:  do not check returned OIDs are increasingt:  Display wall-clock time to complete the walkT:  Display wall-clock time to complete each requestE {OID}:  End the walk at the specified OID
oid定义和常见oid
oid是对象标识符的缩写,它是一种用来在全球范围内唯一地标识某个对象、概念或事物的机制,它由一串数字组成,表示了一个树形的层次结构。oid在计算机科学中有很多应用,例如在计算机安全、网络管理、数据交换等领域中。
常见的oid有以下几种:
- 1.3.6.1.4.1:这是私有企业号(PEN)的根节点,由IANA分配给各个公司或组织,下面的子节点由各自的组织控制和定义¹。例如,1.3.6.1.4.1.343是英特尔公司的oid,1.3.6.1.4.1.9是思科公司的oid。
- 2.5:这是目录服务(DS)的根节点,用于定义X.500和LDAP相关的标准和属性²。例如,2.5.4是属性类型的节点,2.5.4.3是通用名称(CN)的oid,2.5.4.10是组织名称(O)的oid。
- 2.16:这是国家代码的根节点,用于表示各个国家或地区的标识符³。例如,2.16.840是美国的oid,2.16.156是中国的oid。
- 2.16.840:这是美国国家标准和技术研究所(NIST)管理的节点,用于定义美国相关的标准和技术。例如,2.16.840.1是美国政府部门和机构的节点,2.16.840.1.101是美国国防部(DoD)的节点。
- 2.16.840.1.113883:这是美国卫生水平七(HL7)管理的节点,用于定义电子医疗数据交换相关的标准和概念。例如,2.16.840.1.113883.3是美国医疗保健提供者注册号(NPI)的oid。
以1.3.6.1.4.1.2021.2.1.5.8为例
1.3.6.1.4.1.2021.2.1.5.8是一个用于监控运行中的程序或守护进程的oid,它属于UCD-SNMP-MIB模块。这个oid的全名是prErrorFlag,它表示一个程序或守护进程是否违反了代理配置文件中要求的运行进程数量²。如果违反了,这个oid的值会是一个非零的整数,表示错误的类型。例如,如果这个oid的值是1,表示运行进程数量太少;如果是2,表示运行进程数量太多;如果是3,表示两者都有。
为了更好地理解这个oid,我们可以将它分解为以下几个部分:
- 1.3.6.1:这是iso.org.dod.internet节点,表示互联网标准相关的oid。
- 4.1:这是iso.org.dod.internet.private.enterprises节点,表示私有企业号(PEN)的根节点。
- 2021:这是iso.org.dod.internet.private.enterprises.ucdavis节点,表示加州大学戴维斯分校(UC Davis)的oid。
- 2:这是iso.org.dod.internet.private.enterprises.ucdavis.software节点,表示UC Davis开发的软件相关的oid。
- 1:这是iso.org.dod.internet.private.enterprises.ucdavis.software.services节点,表示UC Davis开发的服务相关的oid。
- 5:这是iso.org.dod.internet.private.enterprises.ucdavis.software.services.prTable.prEntry节点,表示服务表中的服务条目相关的oid。
- 8:这是iso.org.dod.internet.private.enterprises.ucdavis.software.services.prTable.prEntry.prErrorFlag节点,表示服务条目中的错误标志相关的oid。
 使用如下命令查看完整输出
# snmpwalk -Oa backup 1.3.6.1.4.1.2021.2.1.5.8
UCD-SNMP-MIB::prCount.8 = INTEGER: 1
输出内容解释
 UCD-SNMP-MIB::prCount.8 = INTEGER: 1是一个用于监控运行中的程序或守护进程的oid,它属于UCD-SNMP-MIB模块。这个oid的全名是prCount,它表示一个程序或守护进程在系统中的运行进程数量。8是这个oid的索引号,表示它对应的程序或守护进程的名称在UCD-SNMP-MIB::prNames.8中。INTEGER: 1表示这个程序或守护进程只有一个运行进程。
例如,如果你使用以下命令来查询一个Linux机器上的所有程序或守护进程的名称和运行进程数量:
# snmpwalk -Oa backup UCD-SNMP-MIB::prTable
你可能会得到类似以下的结果:
`UCD-SNMP-MIB::prNames.1 = STRING: "init"
UCD-SNMP-MIB::prNames.2 = STRING: "kthreadd"
UCD-SNMP-MIB::prNames.3 = STRING: "ksoftirqd/0"
...
UCD-SNMP-MIB::prNames.8 = STRING: "systemd-journal"
...
UCD-SNMP-MIB::prCount.1 = INTEGER: 1
UCD-SNMP-MIB::prCount.2 = INTEGER: 1
UCD-SNMP-MIB::prCount.3 = INTEGER: 1
...
UCD-SNMP-MIB::prCount.8 = INTEGER: 1
...
从这些结果中,你可以看到每个程序或守护进程的名称和运行进程数量。例如,init程序的名称在UCD-SNMP-MIB::prNames.1中,它有一个运行进程在UCD-SNMP-MIB::prCount.1中。systemd-journal守护进程的名称在UCD-SNMP-MIB::prNames.8中,它也有一个运行进程在UCD-SNMP-MIB::prCount.8中。
 知道需要监控的进程id后,即可用如下命令对进程条目监控:
#snmpwalk -Oqv backup 1.3.6.1.4.1.2021.2.1.5.8
1
snmp oid索引号
snmp index number是一个用于标识SNMP表中的条目的数字,它通常是一个或多个对象的值的组合,表示了表中的一行。snmp index number可以是系统中自动设置的,也可以是需要snmp中配置的,这取决于不同的MIB和设备。
你可以使用以下命令来获取snmp监控的所有进程的oid索引值和名称:
snmpwalk -Oa backup UCD-SNMP-MIB::prNames
这个命令会返回类似以下的结果:
UCD-SNMP-MIB::prNames.1 = STRING: xauthd
UCD-SNMP-MIB::prNames.2 = STRING: game
...
从这些结果中,你可以看到linux机器snmp监控的进程和oid索引号。然后你可以拼接oid用于远程进程条目的监控。
 需要注意的问题进程的oid索引号并不一定是固定的。