【问题标题】:Net-snmp writing a MIB moduleNet-snmp 编写 MIB 模块
【发布时间】:2014-12-27 18:21:53
【问题描述】:

喂! 我尝试编写自己的 net-snmp MIB 模块,但我遇到了一些问题...... :) 我在 www.net-snmp.org 网站上阅读了文档。 我做的步骤:

  • 我尝试编译NET-SNMP-EXAMPLES-MIB 这样。

1.) mib2c -c mib2c.scalar.conf netSnmpExampleScalars - 现在我得到一个 .c 和一个 .h 文件,我将它们复制到 ../agent/mibgroup 目录

2.) 我写了一个配置脚本:

    ./configure \
    --with-ldflags="" \
    --with-cflags="-I/usr/src/net-snmp-5.4.4/agent/mibgroup" \
    --enable-mini-agent \
    --with-logfile="/var/log/snmpd.log" \
    --with-default-snmp-version=2 \
    --with-sys-contact=xxx@yyyy.com \
    --with-sys-location=HU/Sze \
    --disable-applications \
    --disable-debugging \
    --disable-manuals \
    --with-mib-modules="netSnmpExampleScalars" \
    --disable-scripts \
    --without-perl-modules \
    --disable-embedded-perl \
    --without-python-modules \
    --without-libwrap \
    --without-openssl \
    --without-rpm \
    --without-zlib

3.) 运行 ./myconfig

  SNMP Versions Supported:    1 2c 3
  Building for:               linux
  Net-SNMP Version:           5.7.3
  Network transport support:  Callback Unix Alias TCP UDP IPv4Base SocketBase TCPBase UDPIPv4Base UDPBase
  SNMPv3 Security Modules:     usm
  Agent MIB code:            default_modules netSnmpExampleScalars =>  snmpv3mibs mibII/snmp_mib mibII/system_mib mibII/sysORTable mibII/vacm_vars mibII/vacm_conf
  MYSQL Trap Logging:         unavailable
  Embedded Perl support:      disabled
  SNMP Perl modules:          disabled
  SNMP Python modules:        disabled
  Crypto support from:
  Authentication support:     MD5
  Encryption support:
  Local DNSSEC validation:    disabled

4.) 运行 make 命令

netSnmpExampleScalars.c: In function 'handle_netSnmpExampleInteger':
netSnmpExampleScalars.c:55:90: error: expected expression before ',' token
netSnmpExampleScalars.c:75:58: error: expected expression before ')' token
netSnmpExampleScalars.c:88:34: error: expected expression before ')' token
netSnmpExampleScalars.c:95:34: error: expected expression before ')' token 
netSnmpExampleScalars.c:103:34: error: expected expression before ')' token
netSnmpExampleScalars.c: In function 'handle_netSnmpExampleSleeper':
netSnmpExampleScalars.c:134:90: error: expected expression before ',' token
netSnmpExampleScalars.c:154:58: error: expected expression before ')' token
netSnmpExampleScalars.c:167:34: error: expected expression before ')' token
netSnmpExampleScalars.c:174:34: error: expected expression before ')' token
netSnmpExampleScalars.c:182:34: error: expected expression before ')' token
netSnmpExampleScalars.c: In function 'handle_netSnmpExampleString':
netSnmpExampleScalars.c:213:90: error: expected expression before ',' token
netSnmpExampleScalars.c:233:58: error: expected expression before ')' token
netSnmpExampleScalars.c:246:34: error: expected expression before ')' token
netSnmpExampleScalars.c:253:34: error: expected expression before ')' token
netSnmpExampleScalars.c:261:34: error: expected expression before ')' token
make[2]: *** [netSnmpExampleScalars.lo] Error 1
make[2]: Leaving directory `/usr/src/net-snmp-5.7.3/agent/mibgroup'
make[1]: *** [subdirs] Error 1
make[1]: Leaving directory `/usr/src/net-snmp-5.7.3/agent
make: *** [subdirs] Error 1

我还需要编辑 mib2c 生成的 c 文件= 还是需要使用其他 .conf 文件? 另外我不知道我的配置脚本是正确还是不正确。离开目录错误怎么办?

【问题讨论】:

  • 在生成的 c 文件中看起来像是语法错误。编译器不会撒谎... =) 如果不查看 MIB 文件或生成的 .c 和 .h 文件,很难判断这里发生了什么。

标签: linux snmp


【解决方案1】:

我猜你还没有编辑过 mib2c 生成的 .c 文件。 mib2c 在 C 代码中转换您的 mib,但您必须编辑代码以返回值 MIB 数据(或在处理 SET 时接受它)。例如。你的 mib 是关于健康监测(心跳,...)。 mib2c 将生成 C 代码的所有内容,除了将要返回的内容(考虑 snmp get 请求)。当然,mib2c 不知道应该返回什么。你将如何读取心跳?您要从设备、文本文件或其他文件中读取此信息吗?所以你需要在.c代码中填写这个,因为mib2c让它为空,不会编译。

【讨论】:

    猜你喜欢
    • 2021-11-17
    • 1970-01-01
    • 2023-03-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多