zz:cacti被监控端配置 SNMP AGNET 调试总结

这篇文章是在弄cacti的时候看到的,就学会了一个命令,snmpd -f -Le;看snmpd的出错信息还是看log来着,不记得了,反正有点用

软件包为net-snmp。

exportMIBDIRS=/share/snmp/mibs

exportMIBS=+AA-BASE-MIB

snmpgetnext-v2c-cpublic192.168.4.12.1.3.6.1.4.1.29881.3.1.1

/opt/net-snmp-5.1.4/agent/helpers/old_api.c108

/opt/net-snmp-5.1.4/agent/agent_registry.c533

/opt/net-snmp-5.1.4/agent/mibgroup/mibII/system_mib.c308

/opt/net-snmp-5.1.4/agent/mibgroup/mib_module_inits.h

资料:

README.txt

INSTALL.txt

FAQ.txt

./configure--help

AGENT.txtmoduleAPI描述

man手册

mansnmpd.conf

mansnmp.conf

mansnmp_conf

http://www.net-snmp.org/wiki/index.php/TutorialsWiKiTutorialsAgent扩展

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-linuxconfigureforbuildingcompilersforTARGET

--with-endianness=little指定目标机的大小端

--with-cc=mipsel-linux-gcc确定交叉编译工具

--with-ar=mipsel-linux-ar确定编译库的工具

LD=mipsel-linux-ld确定交叉链接工具

--with-mibdirs=

--with-mibdirs=

--with-mibfiles

--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-applications--disable-manuals--disable-debugging--disable-snmptrapd-subagent--disable-scripts--with-mib-modules=loogson_base

二、配置

1、基本配置

其实配制一个snmpd.conf文件不算太难,

(1)首选是定义一个共同体名(community),这里是public,及可以访问这个public的用户名(secname),这里是notConfigUser。Public相当于用户notConfigUser的密码:)

#sec.namesourcecommunity

com2secnotConfigUserdefaultpublic

(2)定义一个组名(groupName)这里是notConfigGroup,及组的安全级别,把notConfigGroup这个用户加到这个组中。

groupNamesecurityModelsecurityName

groupnotConfigGroupv1notConfigUser

groupnotConfigGroupv2cnotConfigUser

(3)定义一个可操作的范围(view)名,这里是all,范围是.1

#nameincl/exclsubtreemask(optional)

viewallincluded.1

(4)定义notConfigUser这个组在all这个view范围内可做的操作,这时定义了notConfigUser组的成员可对.1这个范围做只读操作。

#groupcontextsec.modelsec.levelprefixreadwritenotif

accessnotConfigGroup""anynoauthexactallnonenone

2、高级配置

3、问题

错误1:

gwfirewall#snmpwalk-v1-cpubliclocalhostsystem

Cannotfindmodule(IP-MIB):Atline0in(none)

Cannotfindmodule(IF-MIB):Atline0in(none)

Cannotfindmodule(TCP-MIB):Atline0in(none)

Cannotfindmodule(UDP-MIB):Atline0in(none)

Cannotfindmodule(HOST-RESOURCES-MIB):Atline0in(none)

Cannotfindmodule(SNMPv2-MIB):Atline0in(none)

Cannotfindmodule(SNMPv2-SMI):Atline0in(none)

Cannotfindmodule(NOTIFICATION-LOG-MIB):Atline0in(none)

Cannotfindmodule(UCD-SNMP-MIB):Atline0in(none)

Cannotfindmodule(UCD-DEMO-MIB):Atline0in(none)

Cannotfindmodule(SNMP-TARGET-MIB):Atline0in(none)

Cannotfindmodule(NET-SNMP-AGENT-MIB):Atline0in(none)

Cannotfindmodule(SNMP-VIEW-BASED-ACM-MIB):Atline0in(none)

Cannotfindmodule(SNMP-COMMUNITY-MIB):Atline0in(none)

Cannotfindmodule(NET-SNMP-EXTEND-MIB):Atline0in(none)

Cannotfindmodule(UCD-DLMOD-MIB):Atline0in(none)

Cannotfindmodule(SNMP-FRAMEWORK-MIB):Atline0in(none)

Cannotfindmodule(SNMP-MPD-MIB):Atline0in(none)

Cannotfindmodule(SNMP-USER-BASED-SM-MIB):Atline0in(none)

Cannotfindmodule(SNMP-NOTIFICATION-MIB):Atline0in(none)

Cannotfindmodule(SNMPv2-TM):Atline0in(none)

system:UnknownObjectIdentifier(Sub-idnotfound:(top)->system)

gwfirewall#

参考资料:可以参考FAQ文档

设置MIBDIRS环境变量==MIBS库的路径

错误2:

qu@ubuntu:~$snmpwalk-v2c-cpublic192.168.4.12

Timeout:NoResponsefrom192.168.4.12

dunkel<antal.pettermann@gmail.com>:

>

>Theoriginalproblemwas:

>"HoweverifIrun"snmpwalk-v1-cpublic192.168.1.36system"onthe

>stablebox,with192.168.1.36theIPaddressofthetestingbox,iget:

>Timeout:NoResponsefrom192.168.1.36

>

>snmpdisupandrunning,Icanpingbothways,therearenofirewalls

>inplace.Whatcouldbewrong?"

>

>Thesolutionis:

>opensnmpd.confwithyourfavouriteeditorand

>addthese2lines:

>interfaceeth0

>agentaddress[ipaddressofyourhost]:[listeningport-161isthedefault]

错误3:

sarge:/#snmpwalk-v2c-cpubliclocalhost

Timeout:NoResponsefromlocalhost

错误排除:

步骤1:

sarge:/#snmpd-f-Le

屏幕显示(net-snmpd的log文件中是同样内容)

Warning:noaccesscontrolinformationconfigured.

It'sunlikelythisagentcanserveanyusefulpurposeinthisstate.

Run"snmpconf-gbasic_setup"tohelpyouconfigurethesnmpd.conffileforthisagent.

Erroropeningspecifiedendpoint"udp:161"

ServerExitingwithcode1

新建目录

拷贝现有snmpd.conf到/root/.snmp/snmpd.conf

步骤2:

snmpd-f-Le-Dread_config

读配置文件,开头显示了默认的配置文件的路径。

sarge:/#snmpd-f-Le-Dread_config

read_config:readingpremibconfigurationtokens

read_config:configpathused:/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命令的有用选项:

-cFILE指定文件为配置文件

-C不读取默认的配置文件

-ddump接收和发送SNMP数据包

-DTOKEN对于给定的TOKEN(标志)打开调试信息(-Dmib_init)

-I[-]INITLIST对于要初始化的MIB列表显示

-MDIRLIST指定MIB库的路径

-V显示详细信息

-Le把错误信息输出到日志中

-LfFILE把错误信息输出到指定文件中

-mMIBLISTuseMIBLISTinsteadofthedefaultMIBlist

错误4:

为什么添加代码后,也不能够访问这个变量?

排错步骤:

(1)看这个新模块是否编译进去了?

把.o目标文件删除,重新编译,看是否重新产生.o目标文件?

(2)看这个新模块是否被包含近Agentlibrary?

运行nmlibnetsnmpmibs.so.8命令查找initialisationroutineandvariablehandlers的名称。

(3)initialisationroutine(初始化例程)是否运行?

(4)这个新模块是否注册进Agent?

(TrywalkingtheNET-SNMP-MIB::nsModuleTable)

Thiswillalsocheckwhethertheagentaccepts

requestsforenterprise-specificOIDs.

(5)这个新模块处理程序是否真正的执行了?

(6)这个新模块处理程是否返回了错误?

错误5:

我把自己的MIB文件写好了,也把它拷贝到MIBS库的目录下了。

并且把环境变量

exportMIBS=+MY-MIB

这么设置了。

在MIBBrowser中,怎么看不到这个节点呀?

答:

资料:http://www.net-snmp.org/wiki/index.php/TUT:Using_and_loading_MIBS(TUT:UsingandloadingMIBS)

使用snmptranslate命令来测试MY-MIB文件中一个节点名,是否能够识别。

snmptranslate-IR-OnMachType(MY-MIB中的一个节点)

qu@ubuntu:~/Desktop$snmptranslate-IR-OnMachType

.1.3.6.1.4.1.29881.3.1.1

%snmptranslate-IR-OnciscoLS1010ChassisFanLed

Unknownobjectidentifier:ciscoLS1010ChassisFanLed

不能够识别。

三、自定义MIB

1、简单变量

(1)mib2c配置文件的确定(参考FAQ.txt)

IftheMIBcontainsscalarobjects,thenusetheconfigfile

'mib2c.scalar.conf'.Thiswillgeneratetemplatehandlersfor

thesescalarobjects(ignoringinternalstructuraldefinitions,

tableobjectsandnotifications).

(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下的例子。

Whatisthenameofthecodefile?

That'swhat--with-mib-moduleiswanting,notthenameoftheMIB.

Ifyourcodeisinthefile'drs.c',thentheconfigurecommand

shouldbe

./configure--with-mib-modules=drs....

anditwillinvoketheroutine'init_drs'

Ifyourinitroutineiscalled'init_drsProductName',thenthefile

mustbecalled'drsProductName.c',andyouinvokeconfigure

as

./configure--with-mib-modules=drsProductName....

Thesethreevaluesmustmatch.

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)manualpages。

(3)连接到另一个SubAgent(子Agent)程序,这个Agent程序有所需要的功能。

(4)最后,可以通过用C语言编程扩展Agent的方式,来支持新添加的MIBGroup。

可以把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)manualpage。

要产生一个trap信息,还是很简单的,直接调用系统调用send_easy_trap()或者send_v2trap()就行。

在使用mib2c时使用mib2c.notify.conf配置文件就能够构建一个产生trap的合适的模板。

产生trap有两种情况,一种是Agent的Action进行报告,一种是对某种状态的改变进行trap。

七、使用shell命令来扩展Agent

(1)

(2)passMIBOIDEXEC

使用EXEC(三种方式)

命令格式:EXEC[选项]MIBOID命令命令参数

EXEC-gMIBOID

EXEC-nMIBOID

这种方式用来匹配SNMP的get和getnext命令。

把命令参数传递给命令,并通过命令的标准输出来输出的内容来响应请求。

标注输出中的内容应该为:

第一行:请求的MIBOID

第二行:返回值的类型(string,integer,unsigned,objectid,timeticks,ipaddress,counter,orgauge.)

第三行:Value

EXEC-sMIBOIDTYPEVALUE

这种方式用来匹配SNMP的set命令。

TYPE是要设置的类型(string,integer,unsigned,objectid,timeticks,ipaddress,counter,orgauge.)

如果stdout没有返回内容,Agent程序假设操作正确。

否则Agent程序将报错,not-writable或者wrong-type。

相关推荐