如何将自定义 mib 文件加载到 snmpd 代理

问题描述 投票:0回答:1

我正在 docker 中运行 snmpd(polinux/snmpd:alpine 映像),我想将自定义 mib 文件与我为测试目的准备的不同数据类型的 OID 对象一起使用,并通过 2 个不同的在线 mib 验证器对其进行验证,然后我修复了他们向我指出的所有错误,现在我的文件应该没问题,但我仍然无法通过 snmpwalk 找到我的 oid 或通过 snmptranslate 找到我的模块。 这是我尝试过的:

  1. -m <mib file>
    或/和
    -M <mibs dir>
    参数传递给 snmpd - 不起作用
  2. 添加
mibdirs +/etc/snmpd/
mibs +ALL

到 snmpd.conf 文件 - 也不起作用

我错过了什么吗?可能出了什么问题?

我的微博:

MY-MIB DEFINITIONS ::= BEGIN

IMPORTS
    MODULE-IDENTITY,
    OBJECT-TYPE,
    Counter32,
    Counter64,
    Gauge32,
    TimeTicks,
    IpAddress
        FROM SNMPv2-SMI
        DisplayString, TimeStamp
        FROM SNMPv2-TC
        OBJECT-GROUP
        FROM SNMPv2-CONF;

myMIB MODULE-IDENTITY
    LAST-UPDATED "202310110000Z"
    ORGANIZATION "My Organization"
    CONTACT-INFO "[email protected]"
    DESCRIPTION "Example Custom MIB"
    REVISION "202310110000Z"
    DESCRIPTION "Initial revision"
    ::= { iso(1) identified-organization(3) dod(6) internet(1) private(4) enterprises(1) 9999 }
    
myObjects OBJECT IDENTIFIER ::= { myMIB 1 }
    
myObjectGroup OBJECT-GROUP
    OBJECTS { myBits,
              myCounter32,
              myCounter64,
              myGauge,
              myInteger,
              myIpAddress,
              myOctetString,
              myString,
              myTimeTicks }
    STATUS current
    DESCRIPTION
        "A group of my objects."
    ::= { myMIB 2 }

myString OBJECT-TYPE
    SYNTAX      DisplayString
    MAX-ACCESS  read-write
    STATUS      current
    DESCRIPTION "Example scalar object"
    DEFVAL { "example" }
    ::= { myObjects 1 }


myInteger OBJECT-TYPE
    SYNTAX      INTEGER
    MAX-ACCESS  read-only
    STATUS      current
    DESCRIPTION "Example integer object"
    DEFVAL { 1 }
    ::= { myObjects 2 }


myCounter32 OBJECT-TYPE
    SYNTAX      Counter32
    MAX-ACCESS  read-only
    STATUS      current
    DESCRIPTION "Example counter object"
    ::= { myObjects 3 }


myCounter64 OBJECT-TYPE
    SYNTAX      Counter64
    MAX-ACCESS  read-only
    STATUS      current
    DESCRIPTION "Example counter object"
    ::= { myObjects 4 }


myGauge OBJECT-TYPE
    SYNTAX      Gauge32
    MAX-ACCESS  read-only
    STATUS      current
    DESCRIPTION "Example gauge object"
    DEFVAL { 1 }
    ::= { myObjects 5 }


myTimeTicks OBJECT-TYPE
    SYNTAX      TimeTicks
    MAX-ACCESS  read-only
    STATUS      current
    DESCRIPTION "Example timeticks object"
    DEFVAL { 1 }
    ::= { myObjects 6 }


myIpAddress OBJECT-TYPE
    SYNTAX IpAddress
    MAX-ACCESS read-write
    STATUS current
    DESCRIPTION "My IPADDRESS object"
    DEFVAL { 'c0210415'H } -- 192.33.4.21
    ::= { myObjects 7 }


myOctetString OBJECT-TYPE
    SYNTAX OCTET STRING (SIZE(0..255))
    MAX-ACCESS read-write
    STATUS current
    DESCRIPTION "My OCTET STRING object"
    DEFVAL { "255" }
    ::= { myObjects 8 }


myBits OBJECT-TYPE
    SYNTAX BITS {
                bit1(0),
                bit2(1),
                bit3(2)
            }
    MAX-ACCESS read-write
    STATUS current
    DESCRIPTION "My BITS object"
    DEFVAL { { bit1 } }
    ::= { myObjects 9 }


END
snmp snmpd
1个回答
0
投票

这可能不是最好的答案,但它确实有效。

将 MIB 文件放入 /usr/share/snmp/mibs

snmp.conf: mibs +MY-MIB

我从未让 mibdirs 指令发挥作用

© www.soinside.com 2019 - 2024. All rights reserved.