snmp自定义的MIB库中变量不能访问

cuishinankobe 2009-04-09 02:39:11
实在是走投无路了
最近一直在研究snmp。现在自己做了一个只包含三个简单变量的MIB库。
已经生成了.c和.h文件/agent/mibgroup/mib_module_includes.h中看到已经包含了添加的模块 /agent/mibgroup/mib_module_inits.h中也看到了模块的初始函数。
用指令snmptranslater -IR -On wyqmib也能看到节点,如下所示
[root@wen snmp]# snmptranslate -IR -On wyqmib
.1.3.6.1.4.1.4243
但是最可恶的问题一直困扰着我许久
当我输入[root@wen snmp]# snmpget -c public localhost .1.3.6.1.4.1.4243.1.1.0时出现了下面的错误:
WYQ-MIB::wYQAGENTTIME.0 = No Such Object available on this agent at this OID
翻译过来应该是在这个代理中没有这样的可用OID。
可是我查阅了很多资料包扩查看了wiki。都不知道哪里有错误!!!!!!
哪位大哥大姐如果知道请帮助小弟一把,实在是头痛啊。连三个简单变量都不能实现访问,接下来没办法进行了啊!!!!谢谢大家啊


...全文
2126 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
duanfa385104182 2011-02-15
  • 打赏
  • 举报
回复
[Quote=引用 12 楼 faye0412 的回复:]

引用 11 楼 xiaoyu10 的回复:
请问下如果要解析mib结构需要用到什么软件么?谢谢了。


同11楼兄弟的问题,谢谢!~
[/Quote]

你是指 mib browser 吗?
我晕死哦 2009-09-11
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 xiaoyu10 的回复:]
请问下如果要解析mib结构需要用到什么软件么?谢谢了。
[/Quote]

同11楼兄弟的问题,谢谢!~
xiaoyu10 2009-07-28
  • 打赏
  • 举报
回复
请问下如果要解析mib结构需要用到什么软件么?谢谢了。
xiaoyaojin2008 2009-07-27
  • 打赏
  • 举报
回复
hehe
cuishinankobe 2009-04-17
  • 打赏
  • 举报
回复
已经解决了,谢谢各位。
很简单的问题,和之前说到得都没关系
主要是我的操作系统中有个net-snmp-5.0.6.
我启动snmpd的时候默认启动的是低版本的那个所以怎么找都找不到oid了。
现在我先把原先的进程杀掉,然后再启动新的版本的snmpd就可以了
liuyang1943 2009-04-13
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 lemontel 的回复:]
先用下面的命令试:
snmpwalk -c public localhost .1.3.6.1.4.1.4243

引用楼主 cuishinankobe 的帖子:
实在是走投无路了
最近一直在研究snmp。现在自己做了一个只包含三个简单变量的MIB库。
已经生成了.c和.h文件/agent/mibgroup/mib_module_includes.h中看到已经包含了添加的模块 /agent/mibgroup/mib_module_inits.h中也看到了模块的初始函数。
用指令snmptranslater -IR -On wyqmib也能看到节点,如下所示
[r…
[/Quote]

没错,楼主先尝试加载的最上层节点,一级一级地向下延生,如果连4243这个节点都查询不到的话说明加载MIB失败或者未激活,反之如果4243节点可以成功查询但下面的节点查不到的话可能就是你扩展的MIB程序上的问题了
  • 打赏
  • 举报
回复
加个qq吧21733575……我也是做snmp,现在snmp的资料太少了
  • 打赏
  • 举报
回复
LZ应该通过抓包软件,看看发下去的包是什么?
lemontel 2009-04-11
  • 打赏
  • 举报
回复
先用下面的命令试:
snmpwalk -c public localhost .1.3.6.1.4.1.4243

[Quote=引用楼主 cuishinankobe 的帖子:]
实在是走投无路了
最近一直在研究snmp。现在自己做了一个只包含三个简单变量的MIB库。
已经生成了.c和.h文件/agent/mibgroup/mib_module_includes.h中看到已经包含了添加的模块 /agent/mibgroup/mib_module_inits.h中也看到了模块的初始函数。
用指令snmptranslater -IR -On wyqmib也能看到节点,如下所示
[root@wen snmp]# snmptranslate -IR -On wyqmib
.1.3.6.1.4.1.4243
但是最可恶的问题一直困扰着我许久
当我…
[/Quote]
某鸟 2009-04-11
  • 打赏
  • 举报
回复
脑袋迷糊了~~~
cuishinankobe 2009-04-10
  • 打赏
  • 举报
回复
楼上的可能对MIB的定义理解错误了。{enterprise 4243}的意思是enterprise下面的4243节点。并不是说enterprise 是在4243这个节点上。
某鸟 2009-04-09
  • 打赏
  • 举报
回复
enterprises 是在4243那个分支吗?
cuishinankobe 2009-04-09
  • 打赏
  • 举报
回复
贴上我的MIB库文件,和.C .H文件,其实这个也是网上找的我改动了一下
没人帮忙吗?自己先顶一下。
WYQ-MIB DEFINITIONS ::= BEGIN

IMPORTS
MODULE-IDENTITY, OBJECT-TYPE, Integer32,enterprises FROM SNMPv2-SMI
-- SnmpAdminString FROM SNMP-FRAMEWORK-MIB
-- netSnmp FROM NET-SNMP-MIB
-- RowStatus, StorageType FROM SNMPv2-TC
InetAddressType, InetAddress FROM INET-ADDRESS-MIB;

wyqmib MODULE-IDENTITY
LAST-UPDATED "200501260000Z"
ORGANIZATION "CHONGQING PUTIAN 515"
CONTACT-INFO
"
WYQ-EMAIL:BUNENGSHUO@333.COM
"
DESCRIPTION
"THE MIB MODULE IS USED TO TEST"
REVISION "200501260001Z"
DESCRIPTION
"我不知道该说什么!"
::= { enterprises 4243 }

wYQAGENT OBJECT IDENTIFIER ::= { wyqmib 1 }


wYQAGENTTIME OBJECT-TYPE
SYNTAX INTEGER
MAX-ACCESS read-only
STATUS current
DESCRIPTION "1"
::= { wYQAGENT 1 }

wYQAGENUPTTIME OBJECT-TYPE
SYNTAX INTEGER
MAX-ACCESS read-write
STATUS current
DESCRIPTION "2"
::= { wYQAGENT 2 }

wYQAGENVALUE OBJECT-TYPE
SYNTAX INTEGER
MAX-ACCESS read-write
STATUS current
DESCRIPTION "3"
::= { wYQAGENT 3 }

END


.C
/*
* Note: this file originally auto-generated by mib2c using
* : mib2c.old-api.conf,v 1.4 2004/07/28 08:04:58 dts12 Exp $
*/

#include <net-snmp/net-snmp-config.h>
#include <net-snmp/net-snmp-includes.h>
#include <net-snmp/agent/net-snmp-agent-includes.h>
#include "wyqmib.h"

/*
* wyqmib_variables_oid:
* this is the top level oid that we want to register under. This
* is essentially a prefix, with the suffix appearing in the
* variable below.
*/

oid wyqmib_variables_oid[] = { 1, 3, 6, 1, 4, 1, 4243 };

/*
* variable4 wyqmib_variables:
* this variable defines function callbacks and type return information
* for the mib section
*/
static long agvalue,aguptime,agttime;

struct variable4 wyqmib_variables[] = {
/*
* magic number , variable type , ro/rw , callback fn , L, oidsuffix
*/
#define WYQAGENVALUE 1
{WYQAGENVALUE, ASN_INTEGER, RWRITE, var_wyqmib, 1, {3}},
#define WYQAGENUPTTIME 2
{WYQAGENUPTTIME, ASN_INTEGER, RWRITE, var_wyqmib, 1, {2}},
#define WYQAGENTTIME 3
{WYQAGENTTIME, ASN_INTEGER, RONLY, var_wyqmib, 1, {1}},

};

/*
* (L = length of the oidsuffix)
*/


/** Initializes the wyqmib module */
void init_wyqmib(void)
{

DEBUGMSGTL(("wyqmib", "Initializing\n"));

/*
* register ourselves with the agent to handle our mib tree
*/
REGISTER_MIB("wyqmib", wyqmib_variables, variable4,
wyqmib_variables_oid);

/*
* place any other initialization junk you need here
*/
agttime=agvalue=aguptime=1;
}

/*
* var_wyqmib():
* This function is called every time the agent gets a request for
* a scalar variable that might be found within your mib section
* registered above. It is up to you to do the right thing and
* return the correct value.
* You should also correct the value of "var_len" if necessary.
*
* Please see the documentation for more information about writing
* module extensions, and check out the examples in the examples
* and mibII directories.
*/
unsigned char *
var_wyqmib(struct variable *vp,
oid * name,
size_t *length,
int exact, size_t *var_len, WriteMethod ** write_method)
{
/*
* variables we may use later
*/
static long long_ret;
static u_long ulong_ret;
static unsigned char string[SPRINT_MAX_LEN];
static oid objid[MAX_OID_LEN];
static struct counter64 c64;

if (header_generic(vp, name, length, exact, var_len, write_method)
== MATCH_FAILED)
return NULL;

/*
* this is where we do the value assignments for the mib results.
*/
switch (vp->magic) {
case WYQAGENVALUE:
*write_method = write_wYQAGENVALUE;
long_ret = agvalue; /* XXX */
return (u_char *) &long_ret;
case WYQAGENUPTTIME:
*write_method = write_wYQAGENUPTTIME;
long_ret = aguptime; /* XXX */
return (u_char *) &long_ret;
case WYQAGENTTIME:
long_ret = agttime; /* XXX */
return (u_char *) &long_ret;
default:
ERROR_MSG("");
}
return NULL;
}





int
write_wYQAGENVALUE(int action,
u_char * var_val,
u_char var_val_type,
size_t var_val_len,
u_char * statP, oid * name, size_t name_len)
{
long value;
int size;
static long old_value,new_value;
switch (action) {
case RESERVE1:
if (var_val_type != ASN_INTEGER) {
fprintf(stderr, "write to wyqmib not ASN_INTEGER\n");
return SNMP_ERR_WRONGTYPE;
}
if (var_val_len > sizeof(long)) {
fprintf(stderr, "write to wyqmib: bad length\n");
return SNMP_ERR_WRONGLENGTH;
}
break;

case RESERVE2:
size = var_val_len;
value = *(long *) var_val;

break;

case FREE:
/*
* Release any resources that have been allocated
*/
break;

case ACTION:
/*
* The variable has been stored in 'value' for you to use,
* and you have just been asked to do something with it.
* Note that anything done here must be reversable in the UNDO case
*/
old_value=agvalue;
new_value= *var_val;
agvalue=new_value;
fprintf("the agvalue is %d",agvalue);
break;

case UNDO:
/*
* Back out any changes made in the ACTION case
*/
agvalue=old_value;
break;

case COMMIT:
/*
* Things are working well, so it's now safe to make the change
* permanently. Make sure that anything done here can't fail!
*/
break;
}
return SNMP_ERR_NOERROR;
}


int
write_wYQAGENUPTTIME(int action,
u_char * var_val,
u_char var_val_type,
size_t var_val_len,
u_char * statP, oid * name, size_t name_len)
{
long value;
int size;
static long old_uptime,new_uptime;
switch (action) {
case RESERVE1:
if (var_val_type != ASN_INTEGER) {
fprintf(stderr, "write to wyqmib not ASN_INTEGER\n");
return SNMP_ERR_WRONGTYPE;
}
if (var_val_len > sizeof(long)) {
fprintf(stderr, "write to wyqmib: bad length\n");
return SNMP_ERR_WRONGLENGTH;
}
break;

case RESERVE2:
size = var_val_len;
value = *(long *) var_val;

break;

case FREE:
/*
* Release any resources that have been allocated
*/
break;

case ACTION:
/*
* The variable has been stored in 'value' for you to use,
* and you have just been asked to do something with it.
* Note that anything done here must be reversable in the UNDO case
*/
old_uptime=agttime;
new_uptime=*var_val;
agttime=new_uptime;
break;

case UNDO:
/*
* Back out any changes made in the ACTION case
*/
agttime=old_uptime;
break;

case COMMIT:
/*
* Things are working well, so it's now safe to make the change
* permanently. Make sure that anything done here can't fail!
*/
break;
}
return SNMP_ERR_NOERROR;
}

23,121

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 应用程序开发区
社区管理员
  • 应用程序开发区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧