Prometheus:帮助编辑/配置 Cisco MIB 的 snmp_exporter 的 generator.yml 文件

Posted

技术标签:

【中文标题】Prometheus:帮助编辑/配置 Cisco MIB 的 snmp_exporter 的 generator.yml 文件【英文标题】:Prometheus: Help editing/configuring snmp_exporter's generator.yml file for Cisco MIBs 【发布时间】:2019-09-24 08:33:46 【问题描述】:

我一直在尝试将 Prometheus 配置为从 Cisco 设备收集 SNMP 信息,然后将该数据发送到 Grafana。我遇到的问题是配置生成 snmp.yml 的 generator.yml 文件。

我按照此处列出的说明进行操作: https://github.com/prometheus/snmp_exporter/tree/master/generator

我可以按照这些步骤进行操作,没有任何问题。完成这些步骤时,您会下载 Cisco MIB。我把它们放在一个目录中。我相信我的主要问题是我不知道如何在 generator.yml 文件中引用 Cisco MIB。

我已尝试按照此处列出的示例进行操作: http://devopstarter.info/snmp-exporter-generator-tutorial/

作者给出了一个简短的例子,说明如何为华为编辑generator.yml文件。

默认的 generator.yml 将创建一个 snmp.yml 文件,其中包含预先配置的所有模块。所以,我快到了。我只需要一点帮助来添加我想要的 Cisco 模块。

有没有人偶然知道我会怎么做?或者有使用生成器文件和他们添加的模块/mib 的经验?

这是默认的 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]
        lookup: 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 # ifName
    overrides:
      ifType:
        type: EnumAsInfo

# Cisco Wireless LAN Controller
  cisco_wlc:
    walk:
      - interfaces
      - ifXTable
      - 1.3.6.1.4.1.14179.2.1.1.1.38   # bsnDot11EssNumberofMobileStations
      - 1.3.6.1.4.1.14179.2.2.2.1.2    # bsnAPIfType
      - 1.3.6.1.4.1.14179.2.2.2.1.4    # bsnAPIfPhyChannelNumber
      - 1.3.6.1.4.1.14179.2.2.2.1.15   # bsnApIfNoOfUsers
      - 1.3.6.1.4.1.14179.2.2.6.1      # bsnAPIfDot11CountersTable
      - 1.3.6.1.4.1.14179.2.2.13.1.3   # bsnAPIfLoadChannelUtilization
      - 1.3.6.1.4.1.14179.2.2.15.1.21  # bsnAPIfDBNoisePower
    lookups:
      - source_indexes: [bsnDot11EssIndex]
        lookup: bsnDot11EssSsid
        drop_source_indexes: true
      - source_indexes: [bsnAPDot3MacAddress]
        lookup: bsnAPName
        drop_source_indexes: true
    overrides:
      ifType:
        type: EnumAsInfo

# APC/Schneider UPS Network Management Cards
#
# Note: older management cards only support SNMP v1 (AP9606 and
# AP9607, possibly others). Older versions of the firmware may only
# support v1 as well. If you only have newer cards you can switch to
# version v2c or v3.
#
# The management cards have relatively slow processors so don't poll
# very often and give a generous timeout to prevent spurious
# errors. Alternatively you can eliminate the interface polling (OIDs
# beginning with 1.3.6.1.2.1) to reduce the time taken for polling.
#
# MIB: https://download.schneider-electric.com/files?p_File_Name=powernet426.mib
# Guide: http://www.apc.com/salestools/ASTE-6Z5QEY/ASTE-6Z5QEY_R0_EN.pdf
# Download site: http://www.apc.com/us/en/tools/download/index.cfm
  apcups:
    version: 1
    walk:
      - sysUpTime
      - interfaces
      - 1.3.6.1.4.1.318.1.1.1.2       # upsBattery
      - 1.3.6.1.4.1.318.1.1.1.3       # upsInput
      - 1.3.6.1.4.1.318.1.1.1.4       # upsOutput
      - 1.3.6.1.4.1.318.1.1.1.7.2     # upsAdvTest
      - 1.3.6.1.4.1.318.1.1.1.8.1     # upsCommStatus
      - 1.3.6.1.4.1.318.1.1.1.12      # upsOutletGroups
      - 1.3.6.1.4.1.318.1.1.10.2.3.2  # iemStatusProbesTable
      - 1.3.6.1.4.1.318.1.1.26.8.3    # rPDU2BankStatusTable
    lookups:
      - source_indexes: [upsOutletGroupStatusIndex]
        lookup: upsOutletGroupStatusName
        drop_source_indexes: true
      - source_indexes: [iemStatusProbeIndex]
        lookup: iemStatusProbeName
        drop_source_indexes: true
    overrides:
      ifType:
        type: EnumAsInfo
      rPDU2BankStatusLoadState:
        type: EnumAsStateSet
      upsAdvBatteryCondition:
        type: EnumAsStateSet
      upsAdvBatteryChargingCurrentRestricted:
        type: EnumAsStateSet
      upsAdvBatteryChargerStatus:
        type: EnumAsStateSet

# ServerTech Sentry 3 MIB
#
# Used by ServerTech PDUs
#
# ftp://ftp.servertech.com/Pub/SNMP/sentry3/Sentry3OIDTree.txt
# ftp://ftp.servertech.com/Pub/SNMP/sentry3/Sentry3.mib
  servertech_sentry3:
    walk:
      - sysUpTime
      - 1.3.6.1.4.1.1718.3.2.2  # infeedTable
      - 1.3.6.1.4.1.1718.3.2.3  # outletTable
    overrides:
      infeedCapacityUsed:
        ignore: true  # Composite metric: infeedLoadValue / infeedCapacity * 100
      infeedVACapacityUsed:
        ignore: true  # Composite metric: infeedApparentPower / infeedVACapacity * 100

# Palo Alto Firewalls
#
# Palo Alto MIBs can be found here:
# https://www.paloaltonetworks.com/documentation/misc/snmp-mibs.html
#
# PanOS 7.0 enterprise MIBs:
# https://www.paloaltonetworks.com/content/dam/pan/en_US/assets/zip/technical-documentation/snmp-mib-modules/PAN-MIB-MODULES-7.0.zip
#
# Tested on a Palo Alto Networks PA-3020 series firewall
#
  paloalto_fw:
    walk:
      - sysUpTime
      - interfaces
      - hrDevice
      - hrSystem
      - hrStorage
      - 1.3.6.1.4.1.25461.2.1.2.1 # panSys
      - 1.3.6.1.4.1.25461.2.1.2.3 # panSession
      - 1.3.6.1.4.1.25461.2.1.2.5 # panGlobalProtect

# Arista Networks
#
# Arista Networks MIBs can be found here: https://www.arista.com/en/support/product-documentation/arista-snmp-mibs
#
# https://www.arista.com/assets/data/docs/MIBS/ARISTA-ENTITY-SENSOR-MIB.txt
# https://www.arista.com/assets/data/docs/MIBS/ARISTA-SW-IP-FORWARDING-MIB.txt
#
# Tested on Arista DCS-7010T-48 switch
#
  arista_sw:
    walk:
      - sysUpTime
      - interfaces
      - ifXTable
      - 1.3.6.1.2.1.25.3.3.1.2 # hrProcessorLoad
      - 1.3.6.1.2.1.25.2.3.1.6 # hrStorageUsed
      - 1.3.6.1.4.1.30065.3.1.1 # aristaSwFwdIp
    overrides:
      ifType:
        type: EnumAsInfo

# Synology
#
# Synology MIBs can be found here:
#   http://www.synology.com/support/snmp_mib.php
#   http://dedl.synology.com/download/Document/MIBGuide/Synology_MIB_File.zip
#
# Tested on RS2414rp+ NAS
#
  synology:
    walk:
      - interfaces
      - sysUpTime
      - ifXTable
      - laNames
      - laLoadInt
      - ssCpuUser
      - ssCpuSystem
      - ssCpuIdle
      - memory
      - hrStorage
      - 1.3.6.1.4.1.6574.1       # synoSystem
      - 1.3.6.1.4.1.6574.2       # synoDisk
      - 1.3.6.1.4.1.6574.3       # synoRaid
      - 1.3.6.1.4.1.6574.4       # synoUPS
      - 1.3.6.1.4.1.6574.5       # synologyDiskSMART
      - 1.3.6.1.4.1.6574.6       # synologyService
      - 1.3.6.1.4.1.6574.101     # storageIO
      - 1.3.6.1.4.1.6574.102     # spaceIO
      - 1.3.6.1.4.1.6574.104     # synologyiSCSILUN
    lookups:
      - source_indexes: [spaceIOIndex]
        lookup: spaceIODevice
        drop_source_indexes: true
      - source_indexes: [storageIOIndex]
        lookup: storageIODevice
        drop_source_indexes: true
      - source_indexes: [serviceInfoIndex]
        lookup: serviceName
        drop_source_indexes: true
      - 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 # ifName
        drop_source_indexes: true
      - source_indexes: [diskIndex]
        lookup: diskID
        drop_source_indexes: true
      - source_indexes: [raidIndex]
        lookup: raidName
        drop_source_indexes: true
      - source_indexes: [laIndex]
        lookup: laNames
        drop_source_indexes: true
      - source_indexes: [hrStorageIndex]
        lookup: hrStorageDescr
        drop_source_indexes: true
    overrides:
      ifType:
        type: EnumAsInfo

# DD-WRT
#
# The list of SNMP OIDs to care about for DD-WRT can be found here: https://www.dd-wrt.com/wiki/index.php/SNMP#Known_OID.C2.B4s_via_SNMP
#
# Tested on  DD-WRT v3.0-r31825 (04/06/17) with an ASUS RT-AC66U
#
  ddwrt:
    walk:
      - sysUpTime
      - interfaces
      - ifXTable
      - 1.3.6.1.2.1.25.2 # hrStorage
      - 1.3.6.1.4.1.2021.4 # memory
      - 1.3.6.1.4.1.2021.10.1.1 # laIndex
      - 1.3.6.1.4.1.2021.10.1.2 # laNames
      - 1.3.6.1.4.1.2021.10.1.5 # laLoadInt
      - 1.3.6.1.4.1.2021.11 # systemStats
    lookups:
    - source_indexes: [ifIndex]
      lookup: ifDescr
      drop_source_indexes: true
    - source_indexes: [laIndex]
      lookup: laNames
      drop_source_indexes: true
    overrides:
      ifType:
        type: EnumAsInfo

# Ubiquiti / AirMAX
#
# https://dl.ubnt.com/firmwares/airos-ubnt-mib/ubnt-mib.zip
#
  ubiquiti_airmax:
    version: 1
    walk:
      - sysUpTime
      - interfaces
      - ifXTable
      - 1.3.6.1.4.1.41112.1.4 # ubntAirMAX
    overrides:
      ifType:
        type: EnumAsInfo

# Ubiquiti / UniFi
#
# http://dl.ubnt-ut.com/snmp/UBNT-MIB
# http://dl.ubnt-ut.com/snmp/UBNT-UniFi-MIB
#
  ubiquiti_unifi:
    walk:
      - sysUpTime
      - interfaces
      - ifXTable
      - 1.3.6.1.4.1.41112.1.6 # ubntUniFi
    overrides:
      ifType:
        type: EnumAsInfo

# keepalived
#
# https://github.com/acassen/keepalived/blob/master/doc/KEEPALIVED-MIB.txt
  keepalived:
    walk:
      - vrrpInstanceTable # Table of VRRP instances.
      - vrrpSyncGroupTable # Table of sync groups.
      - virtualServerGroupTable # Table of virtual server groups.
      - virtualServerTable # Table of virtual servers.
      - realServerTable # Table of real servers. This includes regular real servers and sorry servers.
    overrides:
      vrrpSyncGroupScriptMaster:
        ignore: true # Non-metric display string.
      vrrpSyncGroupScriptBackup:
        ignore: true # Non-metric display string.
      vrrpSyncGroupScriptFault:
        ignore: true # Non-metric display string.
      vrrpSyncGroupScript:
        ignore: true # Non-metric display string.
      vrrpSyncGroupScriptStop:
        ignore: true # Non-metric display string.
      vrrpInstanceLvsSyncDaemon:
        ignore: true # Deprecated.
      vrrpInstanceLvsSyncInterface:
        ignore: true # Deprecated.
      vrrpInstanceScriptMaster:
        ignore: true # Non-metric display string.
      vrrpInstanceScriptBackup:
        ignore: true # Non-metric display string.
      vrrpInstanceScriptFault:
        ignore: true # Non-metric display string.
      vrrpInstanceScriptStop:
        ignore: true # Non-metric display string.
      vrrpInstanceScript:
        ignore: true # Non-metric display string.
      vrrpInstanceScriptMstrRxLowerPri:
        ignore: true # Non-metric display string.

# Printer: RFC 3805
#
# https://tools.ietf.org/html/rfc3805
# https://www.iana.org/assignments/ianaprinter-mib/ianaprinter-mib.xhtml
  printer_mib:
    walk:
      - sysUpTime
      - hrPrinterStatus
      - prtGeneralReset
      - prtConsoleDisable
      - prtGeneralPrinterName
      - prtGeneralSerialNumber
      - prtAlertCriticalEvents
      - prtAlertAllEvents
      - prtCoverStatus
      - prtMarkerSuppliesLevel
      - prtMarkerSuppliesMaxCapacity
      - prtMarkerSuppliesType
    lookups:
      - source_indexes: [hrDeviceIndex, prtMarkerSuppliesIndex]
        lookup: prtMarkerSuppliesType
    overrides:
      hrPrinterStatus:
        type: EnumAsStateSet
      prtGeneralReset:
        type: EnumAsStateSet
      prtConsoleDisable:
        type: EnumAsStateSet
      prtGeneralPrinterName:
        type: DisplayString
      prtGeneralSerialNumber:
        type: DisplayString
      prtCoverStatus:
        type: EnumAsStateSet

【问题讨论】:

【参考方案1】:

MIBS 应该放在一个目录 mibs 中,该目录与 generator.yml 文件位于同一根目录中。

./generator.yml
./mibs/CISCO-MIB
./mibs/CICSO-OTHER-MIB

我建议使用 Docker 映像来构建 snmp.yml 文件,这样 NetSNMP 将仅在您的工作区中使用 MIBS,而不是在您的操作系统上使用其他可能的 MIBS。

docker run -ti -v "$PWD:/opt/" snmp-generator generate

如果生成器失败,请搜索缺少 OID 的 MIB,或者可能是 MIB 引用了您需要添加到目录中的其他 MIB。您可以通过以下方式查看:

docker run -ti -v "$PWD:/opt/" snmp-generator parse_errors | head

它会告诉您找不到哪些 MIB。

【讨论】:

【参考方案2】:

“由于对 NetSNMP 的动态依赖,你必须自己构建生成器。”

我最初并不清楚这一点。它的实际含义是;

"...您必须自己构建 generator.yml 文件"

我的期望是生成器会使用我放在 mibs 目录下的 MIB 文件创建 snmp.yml,但事实并非如此。

您仍然需要将您的 mib 文件放在 MIBS 下,因为生成器会在生成 snmp.yml 文件时查找这些值。

    将您的 MIB 文件放在 ./mibs/ 目录中 将generate.yml文件备份到generate.yml.bak(仅供参考) 使用 MIB 资源管理器来识别您感兴趣的条目。我使用了 Solarwinds 工具集,因为它包含一个 MIB Walk 应用程序。 (15 天免费试用)。 编辑 generate.yml 并创建您的模块。

简单的例子是;

# Qnap
  qnap:
    walk:
     - 1.3.6.1.4.1.24681.1.2.11.1.3.1 # HdTemperature.1
     - 1.3.6.1.4.1.24681.1.2.11.1.3.2 # HdTemperature.2
     - 1.3.6.1.4.1.24681.1.2.11.1.3.3 # HdTemperature.3
     - 1.3.6.1.4.1.24681.1.2.11.1.3.4 # HdTemperature.4

一旦您感到满意,请按照说明中的指示运行该模块(目前为 2021 年 3 月)

export MIBDIRS=mibs
./generator generate

【讨论】:

以上是关于Prometheus:帮助编辑/配置 Cisco MIB 的 snmp_exporter 的 generator.yml 文件的主要内容,如果未能解决你的问题,请参考以下文章

在哪可以下载cisco2801、3560中文配置手册

cisco交换机安全配置设定命令

cisco怎么进特权模式和配置模式?

配置 Prometheus 使用非默认端口

如何编辑 Helm Chart 的配置?

juniper-cisco-HP上网设置