1、参考链接

1)Net-snmp添加子代理示例
 
2、操作步骤
1)网络拷贝下面的文件
http://www.net-snmp.org/tutorial/tutorial-5/toolkit/mib_module/NET-SNMP-TUTORIAL-MIB.txt
http://www.net-snmp.org/tutorial/tutorial-5/toolkit/demon/nstAgentSubagentObject.c
http://www.net-snmp.org/tutorial/tutorial-5/toolkit/demon/nstAgentSubagentObject.h
 
2)使用net-snmp-config 生成中间代码,然后使用gcc来编译它
./net-snmp-config --compile-subagent mysubagent nstAgentSubagentObject.c
报错:
root@sun-PC:~/share/work/tools/snmpd/mibs# ./net-snmp-config --compile-subagent mysubagent nstAgentSubagentObject.c
generating the temporary code file: netsnmptmp..c
void init_nstAgentSubagentObject(void);
checking for init_nstAgentSubagentObject in nstAgentSubagentObject.c
init_nstAgentSubagentObject(void)
checking for shutdown_nstAgentSubagentObject in nstAgentSubagentObject.c
running: arm-marvell-linux-gnueabi-gcc -fno-strict-aliasing -g -O2 -Ulinux -Dlinux=linux -I. -I/usr/local/include -o mysubagent netsnmptmp..c nstAgentSubagentObject.c -L/usr/local/lib -lnetsnmpmibs -lnetsnmpagent -lnetsnmp -lnetsnmpmibs -ldl -lnetsnmpagent -lnetsnmp -lrt
netsnmptmp..c::: error: net-snmp/net-snmp-config.h: No such file or directory
netsnmptmp..c::: error: net-snmp/net-snmp-includes.h: No such file or directory
netsnmptmp..c::: error: net-snmp/agent/net-snmp-agent-includes.h: No such file or directory
netsnmptmp..c:: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'stop_server'
netsnmptmp..c: In function 'usage':
netsnmptmp..c:: warning: incompatible implicit declaration of built-in function 'fprintf'
netsnmptmp..c:: error: 'stderr' undeclared (first use in this function)
netsnmptmp..c:: error: (Each undeclared identifier is reported only once
已经安装了net-snmp-devel,/usr/include/net-snmp/ 路径下也有相关的头文件。
我们重新定义头文件路径:
export C_INCLUDE_PATH="/home/sun/share/work/tools/snmpd/net-snmp-5.7.3/include"
export LDFLAGS="/home/sun/share/work/tools/snmpd/net-snmp-5.7.3/include/net-snmp/library"
3)再次编译依然报错
generating the temporary code file: netsnmptmp..c
void init_nstAgentSubagentObject(void);
checking for init_nstAgentSubagentObject in ./nstAgentSubagentObject.c
init_nstAgentSubagentObject(void)
checking for shutdown_nstAgentSubagentObject in ./nstAgentSubagentObject.c
running: arm-marvell-linux-gnueabi-gcc -fno-strict-aliasing -g -O2 -Ulinux -Dlinux=linux -I. -I/usr/local/include -o mysubagent netsnmptmp..c ./nstAgentSubagentObject.c -L/usr/local/lib -lnetsnmpmibs -lnetsnmpagent -lnetsnmp -lnetsnmpmibs -ldl -lnetsnmpagent -lnetsnmp -lrt
/home/sun/share/work/tools/arm-linux-gcc/armv7-marvell-linux-gnueabi-softfp/bin/../lib/gcc/arm-marvell-linux-gnueabi/4.4./../../../../arm-marvell-linux-gnueabi/bin/ld: cannot find -lnetsnmpmibs
/home/sun/share/work/tools/arm-linux-gcc/armv7-marvell-linux-gnueabi-softfp/bin/../lib/gcc/arm-marvell-linux-gnueabi/4.4./../../../../arm-marvell-linux-gnueabi/bin/ld: cannot find -lnetsnmpagent
/home/sun/share/work/tools/arm-linux-gcc/armv7-marvell-linux-gnueabi-softfp/bin/../lib/gcc/arm-marvell-linux-gnueabi/4.4./../../../../arm-marvell-linux-gnueabi/bin/ld: cannot find -lnetsnmp
/home/sun/share/work/tools/arm-linux-gcc/armv7-marvell-linux-gnueabi-softfp/bin/../lib/gcc/arm-marvell-linux-gnueabi/4.4./../../../../arm-marvell-linux-gnueabi/bin/ld: cannot find -lnetsnmpmibs
/home/sun/share/work/tools/arm-linux-gcc/armv7-marvell-linux-gnueabi-softfp/bin/../lib/gcc/arm-marvell-linux-gnueabi/4.4./../../../../arm-marvell-linux-gnueabi/bin/ld: cannot find -lnetsnmpagent
/home/sun/share/work/tools/arm-linux-gcc/armv7-marvell-linux-gnueabi-softfp/bin/../lib/gcc/arm-marvell-linux-gnueabi/4.4./../../../../arm-marvell-linux-gnueabi/bin/ld: cannot find -lnetsnmp
collect2: ld returned exit status
6)上述报错信息是缺少动态 .so库文件;
7)net-snmp5.7.3 路径下没有发现 .so文件。可能是没有编译 net-snmp-devel 这个的原因,下载编译,找不到源码包。
8)按照Ubuntu下的net-snmp-devel 工具编译,查找库文件路径: /usr/lib/x86_64-linux-gnu
libsnmp.so -> libsnmp.so.30.0.
libsnmp.so. -> libsnmp.so.30.0.
libnetsnmpagent.so -> libnetsnmpagent.so.30.0.
libnetsnmpagent.so. -> libnetsnmpagent.so.30.0.
9)编译snmpd的时候加上了 --prefix 选项
./configure --host=arm-marvell-linux-gnueabi --with-cc=arm-marvell-linux-gnueabi-gcc --with-ar=arm-marvell-linux-gnueabi-ar
--disable-shared --disable-scripts --with-endianness=little --disable-ipv6 --disable-manuals --disable-ucd-snmp-compatibility
--enable-as-needed --disable-embedded-perl --prefix=/home/sun/share/work/tools/bin/snmp
在安装的路径下面重新执行 net-snmp-devel 操作,编译完成;
 
10)执行以下测试命令
snmpd -f -Le -d -c /etc/snmpd/snmpd.conf -M /etc/snmpd/mibs --rwcommunity=public --master=agentx --rwcommunity=public --master=agentx &
./mysubagent -f -Lo &
本地运行mysubagent 会报以下错误信息
Warning: Failed to connect to the agentx master agent ([NIL]):
11)snmpd.conf增加以下内容(和前面命令中的--master=agentx应该是一个作用)
master agentx
master 是说该snmpd以主代理方式运行,目前主代理snmpd只支持agentx类型,而我们要开发的程序是一种子代理(subagent),是需要连snmpd的master agent的。
12)本地运行 snmpget
./snmpget -v 2c -M /etc/snmpd/mibs -c public localhost NET-S
NMP-TUTORIAL-MIB::nstAgentSubagentObject.
snmpget: Unknown host (localhost) (Resource temporarily unavailable)
服务器运行 snmpget/snmpwalk
snmpget -v2c -c public 10.13.113.205 NET-SNMP-TUTORIAL-MIB::nstAgentSubagentObject.
NET-SNMP-TUTORIAL-MIB::nstAgentSubagentObject.: Unknown Object Identifier
本地运行snmpget 报错的原因应该是没有运行snmp服务;
远端snmpd服务器获取模块失败的原因是没有NET-SNMP-TUTORIAL-MIB 文件;
13)将上面的NET-SNMP-TUTORIAL-MIB.txt 文件拷贝到 /home/sun/.snmp/mibs 目录中,Ubuntu中执行命令成功
root@# snmpget -v 2c -c public 10.13.113.205 NET-SNMP-TUTORIAL-MIB::nstAgentSubagentObject.
Bad operator (html): At line in /home/sun/.snmp/mibs/NET-SNMP-TUTORIAL-MIB.txt
NET-SNMP-TUTORIAL-MIB::nstAgentSubagentObject. = INTEGER:
3、整理一下子代理模式snmpd需要的程序和配置文件完整收录
1)需要的程序和文件
snmpd 程序、snmpd.conf配置文件、编译的子代理程序 xx;
新增子代理接口文件:XX-MIB.txt。放在snmp服务器侧;
 
2)运行脚本和命令
agent 端(注意:使用子代理模式,snmpd程序不能编译 mini-agent选项)
snmpd -f -Le -d -c /etc/snmpd/snmpd.conf &
./mysubagent -f -Lo &
snmpd -f -c /etc/snmpd/snmpd.conf & ##不指定mibs文件会报错误,但是不影响
./mysubagent -f &
服务器端
snmpget -v 2c -c public 10.13.113.205 NET-SNMP-TUTORIAL-MIB::nstAgentSubagentObject.
3)尝试压缩snmpd的体积(去除MIB接口,保留子代理模式)。

snmpd 子代理模式编译测试的更多相关文章

  1. java设计模式(10):代理模式(Proxy)

    一,定义:  代理模式(Proxy):为其他对象提供一种代理以控制对这个对象的访问. 二,其类图: 三,分类一:静态代理 1,介绍:也就是需要我们为目标对象编写一个代理对象,在编译期就生成了这个代理对 ...

  2. 代理模式——用AOP测试业务层方法的执行时间

    代理模式 对代理模式的理解,通过http://www.runoob.com/design-pattern/proxy-pattern.html 对AOP的代理模式,参考https://www.cnbl ...

  3. net-snmp子代理(SubAgent)编写详述

    net-snmp子代理(SubAgent)编写 net-snmp子代理(SubAgent)编写 Netsnmp_Node_Handler MIB/OID定义 1.头文件test.h的编写 2.test ...

  4. Spring代理模式及AOP基本术语

    一.代理模式: 静态代理.动态代理 动态代理和静态代理区别?? 解析:静态代理需要手工编写代理类,代理类引用被代理对象. 动态代理是在内存中构建的,不需要手动编写代理类 代理的目的:是为了在原有的方法 ...

  5. Spring 代理模式及AOP基本术语

    一.代理模式: 静态代理.动态代理 动态代理和静态代理区别?? 解析:静态代理需要手工编写代理类,代理类引用被代理对象. 动态代理是在内存中构建的,不需要手动编写代理类 代理的目的:是为了在原有的方法 ...

  6. AOP基础—代理模式

    代理模式是常用的java设计模式,他的特征是代理类与委托类有同样的接口,代理类主要负责为委托类预处理消息.过滤消息.把消息转发给委托类,以及事后处理消息等.代理类与委托类之间通常会存在关联关系,一个代 ...

  7. 代理模式 & Java原生动态代理技术 & CGLib动态代理技术

    第一部分.代理模式  代理模式是常用的java设计模式,他的特征是代理类与委托类有同样的接口,代理类主要负责为委托类预处理消息.过滤消息.把消息转发给委托类,以及事后处理消息等.代理类与委托类之间通常 ...

  8. Proxy 代理模式

    简介 代理模式是用一个简单的对象来代替一个复杂的或者创建耗时的对象. java.lang.reflect.Proxy RMI 代理模式是对象的结构模式.代理模式给某一个对象提供一个代理对象,并由代理对 ...

  9. Java设计模式---(动态)代理模式

    代理设计模式 定义:为其他对象提供一种代理以控制对这个对象的访问. 动态代理使用 java动态代理机制以巧妙的方式实现了代理模式的设计理念. 之前虽然会用JDK的动态代理,但是有些问题却一直没有搞明白 ...

随机推荐

  1. hdu 6053 TrickGCD(筛法+容斥)

    TrickGCD Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total ...

  2. textbox和input限制文字长度

    textbox 看下面 要求(限制140,并且显示还剩余多少个文字) <asp:textbox id="txt_xm" runat="server" on ...

  3. LeetCode OJ:N-Queens(N皇后问题)

    Given an integer n, return all distinct solutions to the n-queens puzzle. Each solution contains a d ...

  4. Code Cache相关知识总结

    codecache代码缓存区,主要存放JIT所编译的代码,同时还有Java所使用的本地方法代码也会存储在codecache中.不同的jvm.不同的启动方式codecache的默认值大小也不尽相同. J ...

  5. webpack 事件触发 按需加载

    比较易懂, 方法简单 var util_sync = require('./util-sync.js') alert(util_sync.data) document.getElementById(& ...

  6. SSH项目搭建(二)

    本章讲解SSH项目需要到哪些jar包,及各个jar包的作用 一.struts2 1.下载好struts2,struts2文件夹>>>>apps>>>>a ...

  7. NSPort

    NSPort是一个描述通信通道的抽象类.通信发生在两个NSPort对象之中,这两个NSPort对象通常属于不同的进程或任务.分发对象系统使用NSPort对象来返回或发送NSProtMessage对象. ...

  8. Swift 发送邮件和发短信

    // MARK: - Action // MARK: compose mail 发送邮件 @IBAction func composeMail(sender: AnyObject) { // 判断能否 ...

  9. Linux RTC Test Example rtctest.c hacking

    /********************************************************************** * Linux RTC Test Example rtc ...

  10. 分布式版本控制系统Git——图形化Git客户端工具TortoiseGit

    本篇导读: 上篇介绍了一款Windows环境下的Git服务器工具GitStack ,搭建了最简单的Windows下的Git服务器,需要再次提醒的是GitStack是打包了相对较稳定的Git原生版本的, ...