为长篇道歉,其中大部分是需要显示的配置文件。
我一直在创建自己的 SNMP 代理。为了创建我的 MIB 和 snmpd.conf 文件,我刚刚在网上搜索了答案。为了实际实现处理程序,我使用了http://www.net-snmp.org/dev/agent/example_8c_source.html上的 example.c/.h
我正在使用另一台 PC(全是 Linux)来测试我的实现,到目前为止,我只能让snmpwalk/snmpget命令工作。
我已经在我的源文件中为我的可设置对象设置了 WriteMethod 函数。问题是,我认为在尝试设置对象时不会执行此代码。
下面是尝试设置对象的示例:
root@jt:/usr/share/snmp/mibs# snmpset -v 2c -c communityNameHere -m MIB-NAME-HERE.txt 10.20.30.40 1.3.6.1.4.1.12345.1 s "0"
MIB search path: /root/.snmp/mibs:/usr/share/snmp/mibs:/usr/share/snmp/mibs/iana:/usr/share/snmp/mibs/ietf:/usr/share/mibs/site:/usr/share/snmp/mibs:/usr/share/mibs/iana:/usr/share/mibs/ietf:/usr/share/mibs/netsnmp
Cannot find module (MIB-NAME-HERE.txt): At line 0 in (none)
Error in packet.
Reason: notWritable (That object does not support modification)
Failed object: iso.3.6.1.4.1.12345.1
我也尝试使用不带 -m 选项的 snmpset。我也尝试过使用 -m +MIB-NAME-HERE.txt 。
问题- 我已将 snmp.conf 注释掉。当我指定的 MIB 位于 /usr/share/snmp/mibs 时,它怎么找不到模块?
下面是我的 MIB:
MIB-NAME-HERE DEFINITIONS ::= BEGIN
IMPORTS
MODULE-IDENTITY, OBJECT-TYPE, Integer32, enterprises,
NOTIFICATION-TYPE FROM SNMPv2-SMI
OBJECT-GROUP, NOTIFICATION-GROUP FROM SNMPv2-CONF
;
testSnmp MODULE-IDENTITY
LAST-UPDATED "201505200000Z"
ORGANIZATION "www.example.com"
CONTACT-INFO
"email: support@example.com"
DESCRIPTION
"MIB Example."
REVISION "201505200000Z"
DESCRIPTION
"version 1.0"
::= { enterprises 12345 }
--
-- top level structure
--
testSnmpValues OBJECT IDENTIFIER ::= { testSnmp 1 }
testSnmpValuesGroup OBJECT-GROUP
OBJECTS { testObject
}
STATUS current
DESCRIPTION
"Group of all test variables."
::= { testSnmp 4 }
--
-- Values
--
testObject OBJECT-TYPE
SYNTAX OCTET STRING (SIZE(1..4096))
MAX-ACCESS read-write
STATUS current
DESCRIPTION
"Test Example"
::= { testSnmpValues 1 }
问题- 的目的是什么:
testSnmpValues OBJECT IDENTIFIER ::= { testSnmp 1 }
testSnmpValuesGroup OBJECT-GROUP
OBJECTS { testObject
}
STATUS current
DESCRIPTION
"Group of all test variables."
::= { testSnmp 4 }
现在对于我的 snmpd.conf 文件:
###############################################################################
#
# snmpd.conf:
# Test snmpd configuration file. (See EXAMPLE.conf as a reference)
#
###############################################################################
# By default snmp looks here:
# /etc/snmp/snmpd.conf.
# Use '-C -c <configfile>' to override.
#
###############################################################################
# Access Control
###############################################################################
# sec.name source community
com2sec testall default communityNameHere
#---- Community 'communityNameHere' uses security name 'testall'. 'source' selects which IPs can connect.
####
# Second, map the security names into group names:
# sec.model sec.name
group TestGroup v1 testall
group TestGroup v2c testall
group TestGroup usm testall
####
# Third, create a view for us to let the groups have rights to:
# incl/excl subtree mask
#view all included .1 80
view testview included .1.3.6.1.4.1.12345
#---- testview - A view which only allows access to Test OIDs.
####
# Finally, grant the groups access to the 1 view with different
# write permissions:
# context sec.model sec.level match read write notif
#---- Grant read access to TEST group for all security models.
access TestGroup "" any noauth exact testview testview testview
# -----------------------------------------------------------------------------
# load the testsnmp module
dlmod testsnmp /usr/local/testsnmp.so
问题- 我是否缺少使对象可写的东西?我见过其他格式不同的 snmpd.conf 文件,但我认为这不重要吗?