snmpd 子代理模式编译测试

news/2024/7/5 2:05:00

1、参考链接

1)Net-snmp添加子代理示例
https://blog.csdn.net/eyf0917/article/details/39546651
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.3261.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.3261.c nstAgentSubagentObject.c -L/usr/local/lib -lnetsnmpmibs -lnetsnmpagent -lnetsnmp -lnetsnmpmibs -ldl -lnetsnmpagent -lnetsnmp -lrt
netsnmptmp.3261.c:2:38: error: net-snmp/net-snmp-config.h: No such file or directory
netsnmptmp.3261.c:6:40: error: net-snmp/net-snmp-includes.h: No such file or directory
netsnmptmp.3261.c:7:52: error: net-snmp/agent/net-snmp-agent-includes.h: No such file or directory
netsnmptmp.3261.c:21: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'stop_server'
netsnmptmp.3261.c: In function 'usage':
netsnmptmp.3261.c:37: warning: incompatible implicit declaration of built-in function 'fprintf'
netsnmptmp.3261.c:37: error: 'stderr' undeclared (first use in this function)
netsnmptmp.3261.c:37: error: (Each undeclared identifier is reported only once
View Code

 

已经安装了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.32646.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.32646.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.5/../../../../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.5/../../../../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.5/../../../../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.5/../../../../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.5/../../../../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.5/../../../../arm-marvell-linux-gnueabi/bin/ld: cannot find -lnetsnmp
collect2: ld returned 1 exit status
View Code
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.3
libsnmp.so.30 -> libsnmp.so.30.0.3
libnetsnmpagent.so -> libnetsnmpagent.so.30.0.3
libnetsnmpagent.so.30 -> libnetsnmpagent.so.30.0.3
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.0
snmpget: Unknown host (localhost) (Resource temporarily unavailable)
服务器运行 snmpget/snmpwalk
snmpget -v2c -c public 10.13.113.205 NET-SNMP-TUTORIAL-MIB::nstAgentSubagentObject.0
NET-SNMP-TUTORIAL-MIB::nstAgentSubagentObject.0: 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.0
Bad operator (html): At line 128 in /home/sun/.snmp/mibs/NET-SNMP-TUTORIAL-MIB.txt
NET-SNMP-TUTORIAL-MIB::nstAgentSubagentObject.0 = INTEGER: 2
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.0
3)尝试压缩snmpd的体积(去除MIB接口,保留子代理模式)。

转载于:https://www.cnblogs.com/FarmPick/p/9155997.html


http://lihuaxi.xjx100.cn/news/237950.html

相关文章

你学习技术必须知道的开发工具

想知道更多关于区块链技术知识,请百度【链客区块链技术问答社区】 链客,有问必答!区块链的最强大链接是开放开发工具 为了在云2.0行业中充分利用区块链的优势,组织必须构建适当的技术框架。这个框架必须大量使用API和连接性解决方…

计算机基础第二课时

文件后缀名 1.也称文件扩展名(filename extension) 2.是操作系统用来标志文件类型的一种机制 3.通常来说,一个扩展名是跟在主文件名后面的,由一个分隔符分隔。例如:“前端开发知识要点.txt”的文件名中,前端开发知识要点是主文件名…

协议分析中的TCP/IP网络协议

“ TCP/IP协议作为互联网的基础,在协议分析中不可或缺,本文介绍在对协议进行分析还原的过程中的一些要点,快速掌握协议还原的精髓。” 注意,本文比较枯燥乏味,若非需要了解TCP/IP协议相关信息,建议绕行。 …

实现线程哪种方法更好_实施数据以实现更好的用户体验设计的4种方法

实现线程哪种方法更好Gone are the days when design used to rely mainly on the color palettes and the creativity of the designer. In the rapidly expanding technological world of today, it is essential to work across departments to enhance the screen experien…

DispatcherServlet之HandlerAdapter的handle

2019独角兽企业重金招聘Python工程师标准>>> 注:SpringFramework的版本是4.3.x。 1.DispatcherServlet的doService方法时序图 图1 DispatcherServlet的doService方法时序图 2.AnnotationMethodHandlerAdapter的handle方法时序图 图2的原图在Gith…

Java学习笔记二十五:Java面向对象的三大特性之多态

Java面向对象的三大特性之多态 一:什么是多态; 多态是同一个行为具有多个不同表现形式或形态的能力. 多态就是同一个接口,使用不同的实例而执行不同操作. 多态性是对象多种表现形式的体现。 现实中,比如我们按下 F1 键这个动作&am…

Observables简介以及它们与Promise有何不同

‘Observables’, ‘Observables’, ‘Observables’...Yes! Today, we will talk about this often discussed word of the market. Well also learn how they are different from Promises (havent heard about Promises? Not to worry! You will know more soon). Let’s s…

Android组件框架:Android组件管理者ActivityManager

关于作者 郭孝星,程序员,吉他手,主要从事Android平台基础架构方面的工作,欢迎交流技术方面的问题,可以去我的Github提issue或者发邮件至guoxiaoxingse163.com与我交流。 第一次阅览本系列文章,请参见导读&a…