历史经验之SNMP学习笔记_snmpwalk: no securityname specified_上善若水2020的博客-程序员宅基地

技术标签: 历史经验  

整理日期:2011年9月8日

历史经验之SNMP学习笔记

export MIBDIRS=/share/snmp/mibs/
export MIBS=+LOOGSON-MIB
:NET-SNMP-TUTORIAL-MIB
export MIBS=+NET-SNMP-TUTORIAL-MIB
snmpd -f -Le
snmptranslate -IR -On MachType
snmptranslate -IR -On NET-SNMP-TUTORIAL-MIB::nstAgentModuleObject.0
snmpget -v 2c -c public 192.168.4.12 .1.3.6.1.4.1.29881.3.1.1
/opt/net-snmp-5.1.4/agent/helpers/old_api.c 108
/opt/net-snmp-5.1.4/agent/agent_registry.c 533
/opt/net-snmp-5.1.4/agent/mibgroup/mibII/system_mib.c 308
/opt/net-snmp-5.1.4/agent/mibgroup/mib_module_inits.h
/opt/net-snmp-5.1.4/AGENT.txt 710
mibgroup/ucd-snmp/loadave.c CPU负载例程
./mibgroup/host/hr_storage.c:852: 内存使用例程
./mibgroup/mibII/interfaces.c:1667: 网络接口信息
资料:
README.txt
INSTALL.txt
FAQ.txt
./configure --help
AGENT.txt module API 描述
man 手册
man snmpd.conf
man snmp.conf
man snmp_conf
man read_config(5)
http://www.net-snmp.org/wiki/index.php/Tutorials WiKi Tutorials Agent扩展
http://www.net-snmp.org/wiki/index.php/TUT:Writing_a_MIB_Module
Agent扩展例程:
源码树中/agent/example/
(这三个程序都在Tutorials上面进行了说明)
agent/examples/scalar_int.c
agent/examples/data_set.c
agent/examples/delayed_instance.c
一、编译
CC=mipsel-linux-gcc 确定交叉编译工具
–prefix=/nfsroot/cq8401/bin/net-snmp 指定安装路径
–with-perl-modules 指定编译Perl模块
–build=BUILD 指定在BUILD进行编译
–host=mips-linux 指定编译好的程序在什么类型机器上运行
–target=mips-linux configure for building compilers for TARGET
–with-endianness=little 指定目标机的大小端
–with-cc=mipsel-linux-gcc 确定交叉编译工具
–with-ar=mipsel-linux-ar 确定编译库的工具
LD=mipsel-linux-ld 确定交叉链接工具
–with-mibdirs=
–with-mibdirs=
–with-mibfiles
–enable-debugging 打开调试信息
–disable-applications 指定不编译SNMP的应用(即SNMP协议的管理程序snmpget、snmpgetnext等)
–disable-manuals 指定不编译manual手册
–disable-debugging 指定不编译debug信息
–disable-scripts 指定不安装Perl脚本
--disable-snmptrapd-subagent
LD=mipsel-linux-ld
./configure --with-cc=mipsel-linux-gcc --with-ar=mipsel-linux-ar
–prefix=/nfsroot/cq8401/bin/net-snmp --host=mips-linux
–build=i386-linux --with-endianness=little --disable-applications
–disable-manuals --disable-debugging --disable-snmptrapd-subagent
LD=mipsel-linux-ld
./configure --with-cc=mipsel-linux-gcc --with-ar=mipsel-linux-ar
–prefix=/nfsroot/cq8401 --host=mips-linux --build=i386-linux
–with-endianness=little --disable-applications --disable-manuals
–disable-debugging --disable-snmptrapd-subagent --disable-scripts
LD=mipsel-linux-ld
./configure --with-cc=mipsel-linux-gcc --with-ar=mipsel-linux-ar
–prefix=/nfsroot/cq8401 --host=mips-linux --build=i386-linux
–with-endianness=little --disable-manuals
–disable-snmptrapd-subagent --disable-scripts --enable-debugging
–with-mib-modules=loogson 打开调试信息的
二、配置
1、基本配置
其实配制一个snmpd.conf文件不算太难,
(1)首选是定义一个共同体名(community),这里是public,及可以访问这个public的用户名(sec name),这里是notConfigUser。Public相当于用户notConfigUser的密码:)
#sec.name source community
com2sec notConfigUser default public
(2)定义一个组名(groupName)这里是notConfigGroup,及组的安全级别,把notConfigGroup这个用户加到这个组中。
groupName securityModel securityName
group notConfigGroup v1 notConfigUser
group notConfigGroup v2c notConfigUser
(3)定义一个可操作的范围(view)名, 这里是all,范围是 .1
# name incl/excl subtree mask(optional)
view all included .1
(4)定义notConfigUser这个组在all这个view范围内可做的操作,这时定义了notConfigUser组的成员可对.1这个范围做只读操作。
# group context sec.model sec.level prefix read write notif
access notConfigGroup “” any noauth exact all none none
2、高级配置
3、问题
错误1:
gw firewall # snmpwalk -v 1 -c public localhost system
Cannot find module (IP-MIB): At line 0 in (none)
Cannot find module (IF-MIB): At line 0 in (none)
Cannot find module (TCP-MIB): At line 0 in (none)
Cannot find module (UDP-MIB): At line 0 in (none)
Cannot find module (HOST-RESOURCES-MIB): At line 0 in (none)
Cannot find module (SNMPv2-MIB): At line 0 in (none)
Cannot find module (SNMPv2-SMI): At line 0 in (none)
Cannot find module (NOTIFICATION-LOG-MIB): At line 0 in (none)
Cannot find module (UCD-SNMP-MIB): At line 0 in (none)
Cannot find module (UCD-DEMO-MIB): At line 0 in (none)
Cannot find module (SNMP-TARGET-MIB): At line 0 in (none)
Cannot find module (NET-SNMP-AGENT-MIB): At line 0 in (none)
Cannot find module (SNMP-VIEW-BASED-ACM-MIB): At line 0 in (none)
Cannot find module (SNMP-COMMUNITY-MIB): At line 0 in (none)
Cannot find module (NET-SNMP-EXTEND-MIB): At line 0 in (none)
Cannot find module (UCD-DLMOD-MIB): At line 0 in (none)
Cannot find module (SNMP-FRAMEWORK-MIB): At line 0 in (none)
Cannot find module (SNMP-MPD-MIB): At line 0 in (none)
Cannot find module (SNMP-USER-BASED-SM-MIB): At line 0 in (none)
Cannot find module (SNMP-NOTIFICATION-MIB): At line 0 in (none)
Cannot find module (SNMPv2-TM): At line 0 in (none)
system: Unknown Object Identifier (Sub-id not found: (top) -> system)
gw firewall #
参考资料:可以参考FAQ文档
设置MIBDIRS环境变量 == MIBS库的路径
错误2:
qu@ubuntu:~$ snmpwalk -v 2c -c public 192.168.4.12
Timeout: No Response from 192.168.4.12
dunkel :

> 
>  The original problem was:
>  "However if I run "snmpwalk -v 1 -c public 192.168.1.36 system" on the
>  stable box, with 192.168.1.36 the IP address of the testing box, i get:
>  Timeout: No Response from 192.168.1.36
> 
>  snmpd is up and running, I can ping both ways, there are no firewalls
>  in place. What could be wrong?"
> 
>  The solution is:
>  open snmpd.conf with your favourite editor and
>  add these 2 lines:
>  interface eth0
>  agentaddress [ip address of your host]:[listening port -  161 is the default] 

错误3:
sarge:/# snmpwalk -v 2c -c public localhost
Timeout: No Response from localhost
错误排除:
步骤1:
sarge:/# snmpd -f -Le
屏幕显示(net-snmpd的log文件中是同样内容)
Warning: no access control information configured.
It’s unlikely this agent can serve any useful purpose in this state.
Run “snmpconf -g basic_setup” to help you configure the snmpd.conf file for this agent.
Error opening specified endpoint “udp:161”
Server Exiting with code 1
步骤2:
snmpd -f -Le -Dread_config
读配置文件,开头显示了默认的配置文件的路径。
sarge:/# snmpd -f -Le -Dread_config
read_config: reading premib configuration tokens
read_config: config path used: /nfsroot/cq8401/bin/net-snmp/etc/snmp:/nfsroot/cq8401/bin/net-snmp/sh
are/snmp:/nfsroot/cq8401/bin/net-snmp/lib/snmp:/root/.snmp:/var/net-snmp
中间显示了配置文件的内容。
首先查看在默认配置文件的路径中是否有你的配置文件。
如果有,再在配置文件中配置权限。
小技巧:可以使用snmpd -f -Le -Dread_config 命令来查看日志文件信息,排错。
snmpd命令的有用选项:
-c FILE 指定文件为配置文件
-C 不读取默认的配置文件
-d dump接收和发送SNMP数据包
-D TOKEN 对于给定的TOKEN(标志)打开调试信息 ( -Dmib_init)
-I [-]INITLIST 对于要初始化的MIB列表显示
-M DIRLIST 指定MIB库的路径
-V 显示详细信息
-Le 把错误信息输出到日志中
-Lf FILE 把错误信息输出到指定文件中
-m MIBLIST use MIBLIST instead of the default MIB list
错误4:
为什么添加代码后,也不能够访问这个变量?
排错步骤:
(1)看这个新模块是否编译进去了?
把.o目标文件删除,重新编译,看是否重新产生.o目标文件?
可以看/agent/mibgroup/mib_module_includes.h
/agent/mibgroup/mib_module_inits.h
(2)看这个新模块是否被包含近Agent library?
运行nm libnetsnmpmibs.so.8命令查找initialisation routine and variable handlers的名称。
(3)initialisation routine(初始化例程)是否运行?
(4)这个新模块是否注册进Agent?
(Try walking the NET-SNMP-MIB::nsModuleTable)
This will also check whether the agent accepts
requests for enterprise-specific OIDs.
(5)这个新模块处理程序是否真正的执行了?
如果上面都正确,可能是配置文件错误,没有权限进行访问,需要修改配置文件。
例如需要把
view system included .iso.org.dod.internet.mgnt.mib.system
修改为
view system included .iso.org.dod.internet
(6)这个新模块处理程是否返回了错误?
添加之后,如果出现这个错误,
qu@ubuntu:~/Desktop$ snmpget -v 2c -c public 192.168.4.12 .1.3.6.1.4.1.29881.3.1.1.0
SNMPv2-SMI::enterprises.29881.3.1.1.0 = No Such Object available on this agent at this OID
在配置文件中添加下面的配置
view all included .1 80
view system included .iso.org.dod.internet
错误5:
我把自己的MIB文件写好了,也把它拷贝到MIBS库的目录下了。
并且把环境变量
export MIBS=+MY-MIB
这么设置了。
在MIB Browser中,怎么看不到这个节点呀?
答:
资料:http://www.net-snmp.org/wiki/index.php/TUT:Using_and_loading_MIBS(TUT:Using and loading MIBS)
使用snmptranslate命令来测试MY-MIB文件中一个节点名,是否能够识别。
snmptranslate -IR -On MachType(MY-MIB中的一个节点)
qu@ubuntu:~/Desktop$ snmptranslate -IR -On MachType
.1.3.6.1.4.1.29881.3.1.1
% snmptranslate -IR -On ciscoLS1010ChassisFanLed
Unknown object identifier: ciscoLS1010ChassisFanLed
不能够识别。
三、自定义MIB
1、简单变量
(1)mib2c配置文件的确定(参考FAQ.txt)
If the MIB contains scalar objects, then use the config file
‘mib2c.scalar.conf’. This will generate template handlers for
these scalar objects (ignoring internal structural definitions,
table objects and notifications).
(2)如何处理由mib2c产生的文件
如果你使用源码树来编译新的MIB 模块,把mib2c产生的两个文件(mymib.c和mymib.h)
放在agent/mibgroup目录下。
再重新配置并编译Agent程序,使用这个参数( --with-mib-modules=mymib)。
如果你由一系列的MIB模块要添加,把所有的文件放入agent/mibgroup目录下一个单独的目录mymib下,
再创建一个头文件,列表单个的MIB模块,如下所示:
config_require(mymib/myObjects)
config_require(mymib/myTable)
config_require(mymib/myOtherTablLD=mipsel-linux-ld
./configure --with-cc=mipsel-linux-gcc --with-ar=mipsel-linux-ar
–prefix=/nfsroot/cq8401 --host=mips-linux --build=i386-linux
–with-endianness=little --disable-applications --disable-manuals
–disable-debugging --disable-snmptrapd-subagent
–disable-scripts --with-mib-modules=loogsone)
把它保存成mymib.h文件,放在agent/mibgroup目录下。
参考agent/mibgroup下的例子。
What is the name of the code file?
That’s what --with-mib-module is wanting, not the name of the MIB.
If your code is in the file ‘drs.c’, then the configure command
should be
./configure --with-mib-modules=drs …
and it will invoke the routine ‘init_drs’
If your init routine is called ‘init_drsProductName’, then the file
must be called ‘drsProductName.c’, and you invoke configure
as
./configure --with-mib-modules=drsProductName …
These three values must match.
2、table变量
(1)mib2c配置文件的确定(参考FAQ.txt)
当是table变量时,至少于四种config文件。
mib2c.create-dataset.conf
mib2c.iterate.conf
mib2c.iterate_access.conf
mib2c.array-user.conf
四、Agent增加一个功能有四种方法
(1)net-snmp已经开发了这个功能,需要在编译配置时把这个功能配置上。
–with-mib-modules=“list”
(2)这个Agent运行一个命令或者脚本来应答SNMP的访问。
通过这样来获取和报告所需要的信息,或者来执行所需要的操作。
细节信息看snmp(8)或者snmpd.conf(5)manual pages。
(3)连接到另一个SubAgent(子Agent)程序,这个Agent程序有所需要的功能。
(4)最后,可以通过用C语言编程扩展Agent的方式,来支持新添加的MIB Group。
可以把C语言编程静态编译进Agent主程序,或者通过动态加载的方式。
(用
net-snmp扩展代理,实现方式可归结为两种:一是静态库方式,通过修改配置头文件,在相应地方包含新引入的mib模块的.c和.h文件,然后重新编
译库文件和代理程序;二是编译动态共享库,只需把新引入的mib模块的.c和.h文件编译成动态库,通过设置能够让代理程序载入。
对于第
二种方式,一需要编译成.so动态共享库,二需要原代理程序是否包含dlmod或load命令,三还要看系统是否支持。一般情况下仅支持Unix平台。我
们在CygWin下试验过Unix平台编译。在VC下的编译环境,基本上都是参考其makefile,configure等文件。)
五、C语言与Agent的综合
有三种方法可以使C语言和Agent结合起来。
(1)静态编译进Agent主程序
(2)当Agent运行时,动态加载MIB库(必须大于4.2版本)
(3)通过SubAgent来实现。
六、如何使Agent产生一个trap?
资料:snmp_trap_api(3) manual page。
要产生一个trap信息,还是很简单的,直接调用系统调用send_easy_trap()或者send_v2trap()就行。
在使用mib2c时使用mib2c.notify.conf配置文件就能够构建一个产生trap的合适的模板。
产生trap有两种情况,一种是Agent的Action进行报告,一种是对某种状态的改变进行trap。
店铺地址:https://shop66907778.taobao.com/
七、使用shell命令来扩展Agent
(1)
(2)pass MIBOID EXEC
使用EXEC(三种方式)
命令格式: EXEC [选项] MIBOID 命令 命令参数
EXEC -g MIBOID
EXEC -n MIBOID
这种方式用来匹配SNMP的get和getnext命令。
把命令参数传递给命令,并通过命令的标准输出来输出的内容来响应请求。
标注输出中的内容应该为:
第一行:请求的MIBOID
第二行:返回值的类型 (string, integer, unsigned, objectid, timeticks, ipaddress, counter, or gauge.)
第三行:Value
EXEC -s MIBOID TYPE VALUE
这种方式用来匹配SNMP的set命令。
TYPE是要设置的类型(string, integer, unsigned, objectid, timeticks, ipaddress, counter, or gauge.)
如果stdout没有返回内容, Agent程序假设操作正确。
否则Agent程序将报错,not-writable或者wrong-type。

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/weixin_41486034/article/details/106257088

智能推荐

KNN分类算法_knn分类精度很高了为什么还有其他分类-程序员宅基地

目录算法概述算法原理算法推导算法流程——伪代码或者文字描述算法实例——Python实现(代码注释很重要)电影类别分类算法结果算法评价算法概述KNN算法,也叫做K近邻算法,是机器学习中一种简单的分类算法。是一种监督学习算法 。算法原理存在一个样本数据集合,也称作训练样本集,并且样本集中每个数据都存在标签,即我们知道样本集中每一数据与所属分类的对应关系。输人没有标签的新数据后,将新数据的每个特征与样本集中数据对应的特征进行比较,然后算法提取样本集中特征最相似数据(最近邻)的分类标签。一般来说,我们只选择_knn分类精度很高了为什么还有其他分类

正则表达式30分钟入门教程【转载】-程序员宅基地

正则表达式30分钟入门教程本文目标30分钟内让你明白正则表达式是什么,并对它有一些基本的了解,让你可以在自己的程序或网页里使用它。如何使用本教程最重要的是——请给我30分钟,如果你没有使用正则表达式的经验,请不要试图在30秒内入门——除非你是超人 :)别被下面那些复杂的表达式吓倒,只要跟着我一步一步来,你会发现正则表达式其实并没有想像中的那么困难。当然,如果

linux manpage(2) System Calls -程序员宅基地

System Calls Intro(2)NAME Intro, intro - introduction to system calls and error numbersSYNOPSIS #include DESCRIPTION

[NOI2015]软件包管理器_现在你拥有所有软件包之间的依赖关系。特别的是,除了0号软件包,所有的软件包有有-程序员宅基地

题目描述Linux用户和OSX用户一定对软件包管理器不会陌生。通过软件包管理器,你可以通过一行命令安装某一个软件包,然后软件包管理器会帮助你从软件源下载软件包,同时自动解决所有的依赖(即下载安装这个软件包的安装所依赖的其它软件包),完成所有的配置。Debian/Ubuntu使用的apt-get,Fedora/CentOS使用的yum,以及OSX下可用的homebrew都是优秀的软件包管理器。你..._现在你拥有所有软件包之间的依赖关系。特别的是,除了0号软件包,所有的软件包有有

WindowManagerService的理解-程序员宅基地

Android中的窗口概念:屏幕上一块用于绘制各种UI元素并可以响应用户输入的一块矩形区域。从原理上来看,窗口的概念是独自占有一个Surface实例的显示区域。如Dialog、Activity的界面、壁纸、状态栏以及Toast等都是窗口。 上述对窗口的概念性描述,提取出来主要有以下几点信息:用于绘制UI元素响应用户输入独自占有一个surface实例Surface是一块画布,应用通过canvas或者...

在3dmax中的动画关键帧消失的问题。-程序员宅基地

1、不是用biped直接建骨骼时,当我们没有全选所有物体时是不显示关键帧的。2、用biped直接建骨骼时,需要选中biped骨骼才会显示关键帧。转载于:https://www.cnblogs.com/ZeroMurder/p/5240591.html..._3dmax关键帧标尺不见了

随便推点

Kubernetes——容器基础(完全参考总结于张磊《深入剖析Kubernetes》)-程序员宅基地

容器基础容器本身是没有价值的,有价值的是“容器编排”Docker中做的约束容器,只是一种特殊的进程而已容器的隔离和限制容器本身是没有价值的,有价值的是“容器编排”容器中的边界是如何实现的一个小程序是如何运行的?一个小程序的运行,首先要将程序语言翻译成为二进制语言。要给代码提供数据(例如从磁盘中引入二进制文件)数据被加载到内存中待命CPU和内存共同工作,并且利用寄存器、内存堆栈...

CentOS6.5 linux 中的双网卡配置_liunx centos6 配置网卡_星际绿光的博客-程序员宅基地

CentOS6.5 linux 中的双网卡配置根据之前列的计划,迁移之前需要先打通两边的网络情况,当前linux是双网卡,需要设置linux双网卡双网关,经过几番周折及各路高人指点下,才终于设置好,需要联通的两台服务器网络情况如下:服务器一:操作系统:CentOS6.5 linux网卡:双网卡网卡配置信息:eth0:192.168.13.2(私有网)netmaask:255.255.255.0gateway:192.168.10.254eth1:192.168.204.15(校园网)n_liunx centos6 配置网卡

[实战]MVC5+EF6+MySql企业网盘实战(22)——图片列表-程序员宅基地

写在前面实现逻辑是:单击图片节点,加载所有的当前用户之前上传的图片,分页,按时间倒序加载。系列文章[EF]vs15+ef6+mysql code first方式[实战]MVC5+EF6+MySql企业网盘实战(1)[实战]MVC5+EF6+MySql企业网盘实战(2)——用户注册[实战]MVC5+EF6+MySql企业网盘实战(3)——验证码[实战]MVC5+EF6+M...

代码动态修改材质球的颜色-程序员宅基地

如题:gameObject.GetComponent<Renderer>().material.color=Color.red;//当材质球的Shader为标准时,可直接使用此方法修改颜色值//gameObject.GetComponent<Renderer>().material 得到的material是经过实例化之后的material(Instantiate)...

oracle 启动em失败-程序员宅基地

Q: [oracle@localhost ~]$ lsnrctl startLSNRCTL for Linux: Version 11.2.0.1.0 - Production on 04-OCT-2017 22:43:47Copyright (c) 1991, 2009, Oracle. All rights reserved.Starting /u0_oracle 启动em失败

块UI样式编辑器下实现NX的功能-程序员宅基地

进入块UI样式编辑器做出如下界面:在Create_Block::apply_cb()函数中添加的代码: { //---- Enter your callback code here ----- UF_initialize(); //布尔运算 UF_FEATURE_SIGN sign01=UF_NULLSI..._nx表ui块