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. The capacitive screen technology - tadpole

  2. vue.js 源代码学习笔记 ----- $watcher

    /* @flow */ import { queueWatcher } from './scheduler' import Dep, { pushTarget, popTarget } from '. ...

  3. 《Drools7.0.0.Final规则引擎教程》第4章 4.4 LHS简介&Pattern

    LHS简介 在规则文件组成章节,我们已经了解了LHS的基本使用说明.LHS是规则条件部分的统称,由0个或多个条件元素组成.前面我们已经提到,如果没有条件元素那么默认就是true. 没有条件元素,官方示 ...

  4. HBase架构解析

    Hbase组件  客户端Client 整个HBase集群的入口 使用HBase RPC机制与HMaster和HRegionserver通信 与HMaster通信进行管理类的操作 与HRegionse ...

  5. 打开U盘时出现“使用驱动器 X:中的光盘之前需要将其格式化。”字样

    今天打开U盘时出现如下情况,吓死宝宝了,格式化!!!里面还有好多数据嘞,幸好最终找到方法解决了这个问题. 解决方法: 1.下载DiskGenius软件 2.工具->搜索已丢失分区(重建分区):不 ...

  6. Oracle基本概念与数据导入

    Oracle基本概念 实例 一个Oracle实例(Oracle Instance)有一系列的后台进程(Backguound Processes)和内存结构(Memory Structures)组成.一 ...

  7. (转)Java获取CLASSPATH路径

    ClassLoader提供了两个方法用于从装载的类路径中取得资源: public URL getResource(String name); public InputStream getResourc ...

  8. Luogu 3690 Link Cut Tree

    Luogu 3690 Link Cut Tree \(LCT\) 模板题.可以参考讲解和这份码风(个人认为)良好的代码. 注意用 \(set\) 来维护实际图中两点是否有直接连边,否则无脑 \(Lin ...

  9. HDU2222 Keywords Search 【AC自动机】

    HDU2222 Keywords Search Problem Description In the modern time, Search engine came into the life of ...

  10. SQL Server 为存储过程添加预定设置注释代码

    一个优秀的项目最少不了的是代码注释,兴许你是代码高手入目既知道该段代码主要功能是什么,但日子长了,记的东西多了,即时再熟悉的代码也渐渐的有点不认 识它,所以养成良好的写注释的习惯,对于自己对于他人都是 ...