关于snmp oid以及使用snmpwalk作为进程监控工具

snmpwalk命令的帮助

basn 复制代码
# snmpwalk --help
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
  -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 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

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。
    使用如下命令查看完整输出
bash 复制代码
# 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

你可能会得到类似以下的结果:

bash 复制代码
`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后,即可用如下命令对进程条目监控:

bash 复制代码
#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

这个命令会返回类似以下的结果:

bash 复制代码
UCD-SNMP-MIB::prNames.1 = STRING: xauthd
UCD-SNMP-MIB::prNames.2 = STRING: game
...

从这些结果中,你可以看到linux机器snmp监控的进程和oid索引号。然后你可以拼接oid用于远程进程条目的监控。

需要注意的问题进程的oid索引号并不一定是固定的。

相关推荐
聚铭网络36 分钟前
聚铭安全管家平台2.0实战解码 | 安服篇(四):重构威胁追溯体系
网络·安全·重构
郭二哈36 分钟前
git的使用
大数据·网络·git·elasticsearch
phoenix09811 小时前
Linux入门DAY29
linux·运维
一休哥助手1 小时前
Naive RAG:简单而高效的检索增强生成架构解析与实践指南
运维·人工智能·架构
叔叔别拉了我害怕2 小时前
封装FTPSClient连接ftps服务器
服务器·git·github
不甘懦弱2 小时前
阿里云搭建flask服务器
服务器·python·flask
Bi2 小时前
包含多个子项目集成一个项目部署Vercel方法
运维·前端
Mr. Cao code2 小时前
使用Tomcat Clustering和Redis Session Manager实现Session共享
java·linux·运维·redis·缓存·tomcat
zcz16071278212 小时前
Linux 网络命令大全
linux·运维·网络
the sun342 小时前
Reactor设计模式及其在epoll中的应用
linux·运维·服务器·c++