先说第一件事。我想创建我自己的 MIB。
如果我问一个简单的问题,请原谅我,因为我是 SNMP 的新手,而且我在这方面苦苦挣扎了几个星期。我已经通过了TUT:mib2c。
更新:我有以下名为 的 MIB SAMPLE-MIB,它编译良好,没有任何错误(此编译仅在代理系统上完成,不在服务器上完成)。
SAMPLE-MIB DEFINITIONS ::= BEGIN
IMPORTS
MODULE-IDENTITY, OBJECT-TYPE, Integer32,
NOTIFICATION-TYPE FROM SNMPv2-SMI
SnmpAdminString FROM SNMP-FRAMEWORK-MIB
netSnmp FROM NET-SNMP-MIB
;
sample MODULE-IDENTITY
LAST-UPDATED "201709120200Z"
ORGANIZATION "NCS"
CONTACT-INFO
"@ncs-in.com"
DESCRIPTION
"A test MIB"
REVISION "201709120200Z"
DESCRIPTION
"initial Draft"
::= { iso org(3) dod(6) internet(1) private(4) enterprises(1) 39106 }
sampleResearch OBJECT IDENTIFIER ::= { sample 2 }
sampleVar OBJECT-TYPE
SYNTAX Integer32
MAX-ACCESS read-write
STATUS current
DESCRIPTION
"testing"
::= { sampleResearch 1}
END
我已经这样做了:
root@snmp-agent:# MIBS=+SAMPLE-MIB
root@snmp-agent:# export MIBS
root@snmp-agent:# MIBS=ALL
我的 MIB 文件位于此路径中:/usr/share/snmp/mibs这是默认搜索路径。我已经编译并成功生成了 .c 和 .h 文件,如下所示:
root@snmp-agent:# snmptranslate -On SAMPLE-MIB::sampleVar
root@snmp-agent:# snmptranslate -IR SAMPLE-MIB
root@snmp-agent:# mib2c -c mib2c.scalar.conf sampleVar
注意:这些 sampleVar.c 和 sampleVar.h 文件位于以下路径中:
/home/snmp-agent/Desktop/project/net-snmp-5.7.3/agent/mibgroup/.
为了简单起见,我不会修改 中的任何内容sampleVar.h,这就是我的sampleVar.c文件的外观:
/*
* Note: this file originally auto-generated by mib2c using
* $
*/
#include <net-snmp/net-snmp-config.h>
#include <net-snmp/net-snmp-includes.h>
#include <net-snmp/agent/net-snmp-agent-includes.h>
#include "sampleVar.h"
static int myvar=10;
/** Initializes the sampleVar module */
void
init_sampleVar(void)
{
const oid sampleVar_oid[] = { 1,3,6,1,4,1,39106,2,1 };
const size_t sampleVar_oid_len = OID_LENGTH(sampleVar_oid);
netsnmp_handler_registration *reg;
netsnmp_iterator_info *iinfo;
netsnmp_table_registration_info *table_info;
DEBUGMSGTL(("sampleVar", "Initializing\n"));
/* netsnmp_register_scalar(
netsnmp_create_handler_registration("sampleVar", handle_sampleVar,
sampleVar_oid, OID_LENGTH(sampleVar_oid),
&,HANDLER_CAN_RWRITE ));*/
netsnmp_register_int_instance("sampleVar",
sampleVar_oid,
OID_LENGTH(sampleVar_oid),
&myvar, NULL);
}
int
handle_sampleVar(netsnmp_mib_handler *handler,
netsnmp_handler_registration *reginfo,
netsnmp_agent_request_info *reqinfo,
netsnmp_request_info *requests)
{
int ret = 120892;
netsnmp_request_info *request;
netsnmp_table_request_info *table_info;
struct poolTable_entry *table_entry;
/* We are never called for a GETNEXT if it's registered as a
"instance", as it's "magically" handled for us. */
DEBUGMSGTL(("sampleVar", "Initializing\n"));
/* a instance handler also only hands us one request at a time, so
we don't need to loop over a list of requests; we'll only get one. */
return ret;
}
现在我用 MIB 重新配置 net-snmp,如下所示:
./configure --with-mib-modules="sampleVar"
make
make install
在此之后,当我(在代理上)执行此操作时,我snmptranslate -IR sampleVar.0得到的输出为:
root@snmp-agent:# snmptranslate -IR sampleVar.0
SAMPLE-MIB::sampleVar.0 (expected output of the command)
使用命令snmptranslate -On objectName.0我得到的输出为:
root@snmp-agent:# snmptranslate -On SAMPLE-MIB::sampleVar.0
.1.3.6.1.4.1.39106.2.1 (expected output of the command)
当我snmpwalk在服务器上做:
snmp-server:# snmpwalk -v 2c -c ncs -m SAMPLE-MIB 192.168.5.22 .1.3.6.1.4.1.39106.2.1
SAMPLE-MIB::sampleVar.2.18.46.49.46.51.46.54.46.49.46.52.46.49.46.51.57.49.48.54 = Wrong Type (should be INTEGER): STRING: "/bin/echo"
SAMPLE-MIB::sampleVar.3.18.46.49.46.51.46.54.46.49.46.52.46.49.46.51.57.49.48.54 = Wrong Type (should be INTEGER): ""
SAMPLE-MIB::sampleVar.4.18.46.49.46.51.46.54.46.49.46.52.46.49.46.51.57.49.48.54 = Wrong Type (should be INTEGER): ""
SAMPLE-MIB::sampleVar.5.18.46.49.46.51.46.54.46.49.46.52.46.49.46.51.57.49.48.54 = INTEGER: 5
SAMPLE-MIB::sampleVar.6.18.46.49.46.51.46.54.46.49.46.52.46.49.46.51.57.49.48.54 = INTEGER: 1
SAMPLE-MIB::sampleVar.7.18.46.49.46.51.46.54.46.49.46.52.46.49.46.51.57.49.48.54 = INTEGER: 1
SAMPLE-MIB::sampleVar.20.18.46.49.46.51.46.54.46.49.46.52.46.49.46.51.57.49.48.54 = INTEGER: 4
SAMPLE-MIB::sampleVar.21.18.46.49.46.51.46.54.46.49.46.52.46.49.46.51.57.49.48.54 = INTEGER: 1
但是,当我snmpget从我的服务器上做时,我得到:
root@snmp-server:# snmpget 192.168.5.22 sampleVar.0
SAMPLE-MIB::sampleVar = No Such Object available on this agent at this OID
root@snmp-server:# snmpget -v 2c -c ncs 192.168.5.22 -m SAMPLE-MIB .1.3.6.1.4.1.39106.2.1
SAMPLE-MIB::sampleResearch.3.1.2 = No Such Object available on this agent at this OID
我确实sysUpTime.0从我的服务器得到了预期的输出:
root@snmp-server:# snmpget 192.168.5.22 sysUpTime.0
DISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks: (721781) 2:00:17.81 (OUTPUT)
我已经用谷歌搜索了它并仍在搜索但没有运气。所以谁能告诉我下一步该怎么做?我应该如何snmpget在我自己的 MIB 上使用我的服务器?
任何想法或建议都受到高度赞赏。谢谢你。
更新 2:输出snmpgetnext:
root@snmp-server:~# snmpgetnext -v 2c -c ncs 192.168.5.22 -m SAMPLE-MIB .1.3.6.1.4.1.39106.2.1
SAMPLE-MIB::sampleVar.2.18.46.49.46.51.46.54.46.49.46.52.46.49.46.51.57.49.48.54 = Wrong Type (should be INTEGER): STRING: "/bin/echo"
root@snmp-server:~# snmpgetnext -v 2c -c ncs 192.168.5.22 -m SAMPLE-MIB .1.3.6.1.4.1.39106.2.2
SAMPLE-MIB::sample.3.1.1.18.46.49.46.51.46.54.46.49.46.52.46.49.46.51.57.49.48.54 = ""
正如您所说:snmpget 用于定位 SNMP 中的特定 OID,因此,当我指定完整的 OID 时,我会得到正确的输出:
root@snmp-server:~# snmpget -v 2c -c ncs -m SAMPLE-MIB 192.168.5.22 sampleVar.2.18.46.49.46.51.46.54.46.49.46.52.46.49.46.51.57.49.48.54
SAMPLE-MIB::sampleVar.2.18.46.49.46.51.46.54.46.49.46.52.46.49.46.51.57.49.48.54 = Wrong Type (should be INTEGER): STRING: "/bin/echo"
但这是什么:sampleVar.2.18.46.49.46.51.46.54.46.49.46.52.46.49.46.51.57.49.48.54?这里有什么问题?我不明白!我没有指定这个东西!!!!