




已阅读5页,还剩7页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
Net-snmp 使用perl扩展 agent摘要:在snmpd.conf配置文件中,使用Perl进行扩展。官网:/dist/NetSNMP-agent/agent.pm版本:NET-SNMP version 系统:CentOS X64软件包:net-snmp-.tar.gz安装perlrootlocalhost net-snmp-#yum install perl-devel perl-ExtUtils-Embed net-snmp-perlrootlocalhost net-snmp-# rpm -qa|grep perlperl-version-0.77-136.el6.x86_64net-snmp-perl-5.5-49.el6_5.1.x86_64perl-Test-Simple-0.92-136.el6.x86_64perl-5.10.1-136.el6.x86_64perl-DBD-MySQL-4.013-3.el6.x86_64perl-ExtUtils-MakeMaker-6.55-136.el6.x86_64perl-Pod-Escapes-1.04-136.el6.x86_64perl-Pod-Simple-3.13-136.el6.x86_64perl-DBI-1.609-4.el6.x86_64perl-ExtUtils-ParseXS-2.2003.0-136.el6.x86_64perl-Module-Pluggable-3.90-136.el6.x86_64perl-CGI-3.51-136.el6.x86_64perl-devel-5.10.1-136.el6.x86_64perl-Test-Harness-3.17-136.el6.x86_64perl-libs-5.10.1-136.el6.x86_64perl-ExtUtils-Embed-1.28-136.el6.x86_64解压安装包:rootlocalhost snmp# pwd/root/snmprootlocalhost snmp# lsnet-snmp-.tar.gzrootlocalhost snmp# tar xzvf net-snmp-.tar.gzrootlocalhost snmp# lsnet-snmp- net-snmp-.tar.gz配置rootlocalhost snmp# cd net-snmp-rootlocalhost net-snmp-# pwd/root/snmp/net-snmp-rootlocalhost net-snmp-# ./configure配置完成后,会显示如下configure摘要信息- Net-SNMP configuration summary:- SNMP Versions Supported: 1 2c 3 Building for: linux Net-SNMP Version: Network transport support: Callback Unix Alias TCP UDP IPv4Base SocketBase TCPBase UDPIPv4Base UDPBase SNMPv3 Security Modules: usm Agent MIB code: default_modules = snmpv3mibs mibII ucd_snmp notification notification-log-mib target agent_mibs agentx disman/event disman/schedule utilities host MYSQL Trap Logging: unavailable Embedded Perl support: enabled SNMP Perl modules: building - embeddable SNMP Python modules: disabled Crypto support from: crypto Authentication support: MD5 SHA1 Encryption support: DES AES Local DNSSEC validation: disabled5.4版本以后的默认安装perl模块,如果不支持,请使用rootlocalhost net-snmp-#./configure -enable-embedded-perl编译、安装 make & make install配置snmpd.confrootlocalhost snmp# pwd/usr/local/share/snmprootlocalhost snmp# snmpconf The following installed configuration files were found: 1: ./snmptrapd.conf 2: /usr/local/share/snmp/snmptrapd.confWould you like me to read them in? Their content will be merged with theoutput files created by this session.Valid answer examples: all, none,3,1,2,5Read in which (default = all): noneI can create the following types of configuration files for you.Select the file type you wish to create:(you can create more than one as you run this program) 1: snmpd.conf 2: snmptrapd.conf 3: snmp.confOther options: quitSelect File: 1The configuration information which can be put into snmpd.conf is dividedinto sections. Select a configuration section for snmpd.confthat you wish to create: 1: Access Control Setup 2: Extending the Agent 3: Trap Destinations 4: Monitor Various Aspects of the Running Host 5: Agent Operating Mode 6: System Information SetupOther options: finishedSelect section: 1Section: Access Control SetupDescription: This section defines who is allowed to talk to your running snmp agent.Select from: 1: a SNMPv3 read-write user 2: a SNMPv3 read-only user 3: a SNMPv1/SNMPv2c read-only access community name 4: a SNMPv1/SNMPv2c read-write access community nameOther options: finished, listSelect section: 3Configuring: rocommunityDescription: a SNMPv1/SNMPv2c read-only access community name arguments: community default|hostname|network/bits oidThe community name to add read-only access for: publicThe hostname or network address to accept this community name from RETURN for all: The OID that this community should be restricted to RETURN for no-restriction: Finished Output: rocommunity public Section: Access Control SetupDescription: This section defines who is allowed to talk to your running snmp agent.Select from: 1: a SNMPv3 read-write user 2: a SNMPv3 read-only user 3: a SNMPv1/SNMPv2c read-only access community name 4: a SNMPv1/SNMPv2c read-write access community nameOther options: finished, listSelect section: 4Configuring: rwcommunityDescription: a SNMPv1/SNMPv2c read-write access community name arguments: community default|hostname|network/bits oidEnter the community name to add read-write access for: privateThe hostname or network address to accept this community name from RETURN for all: The OID that this community should be restricted to RETURN for no-restriction: Finished Output: rwcommunity private Section: Access Control SetupDescription: This section defines who is allowed to talk to your running snmp agent.Select from: 1: a SNMPv3 read-write user 2: a SNMPv3 read-only user 3: a SNMPv1/SNMPv2c read-only access community name 4: a SNMPv1/SNMPv2c read-write access community nameOther options: finished, listSelect section: finishedThe configuration information which can be put into snmpd.conf is dividedinto sections. Select a configuration section for snmpd.confthat you wish to create: 1: Access Control Setup 2: Extending the Agent 3: Trap Destinations 4: Monitor Various Aspects of the Running Host 5: Agent Operating Mode 6: System Information SetupOther options: finishedSelect section: finishedI can create the following types of configuration files for you.Select the file type you wish to create:(you can create more than one as you run this program) 1: snmpd.conf 2: snmptrapd.conf 3: snmp.confOther options: quitSelect File: quitThe following files were created: snmpd.conf These files should be moved to /usr/local/share/snmp if youwant them used by everyone on the system. In the future, if you add the -i option to the command line Ill copy them there automatically for you.Or, if you want them for your personal use only, copy them to/root/.snmp . In the future, if you add the -p option to thecommand line Ill copy them there automatically for you.perl扩展agentrootlocalhost snmp# pwd/usr/local/share/snmp rootlocalhost snmp# vim snmpd.conf增加如下内容:perl do /root/snmp/test/snmp_perl/perl_module.pl;snmpd.conf配置文件rootlocalhost snmp# pwd/usr/local/share/snmprootlocalhost snmp# cat snmpd.confrocommunity public rwcommunity private perl do /root/snmp/test/snmp_perl/perl_module.pl;perl脚本rootlocalhost snmp_perl# pwd/root/snmp/test/snmp_perlrootlocalhost snmp_perl# cat perl_module.pl #!/usr/bin/perl# This is an example of perl module support for the net-snmp agent.# To load this into a running agent with embedded perl support turned# on, simply put the following line (without the leading # mark) your# snmpd.conf file:# perl do /path/to/perl_module.pl;#my $regat = ..4.1.37945;BEGIN print STDERR starting perl_module.pln;use NetSNMP:OID (:all);use NetSNMP:agent (:all);use NetSNMP:ASN (:all);print STDERR perl_module.pl loaded okn;# set to 1 to get extra debugging information$debugging = 1;# if were not embedded, this will get auto-set below to 1$subagent = 0;# where we are going to hook ontomy $regoid = new NetSNMP:OID($regat);print STDERR registering at ,$regoid,n if ($debugging);# If were not running embedded within the agent, then try to start# our own subagent instead.if (!$agent) $agent = new NetSNMP:agent(Name = test, # reads test.confAgentX = 1); # make us a subagent $subagent = 1; print STDERR started us as a subagent ($agent)n# we register ourselves with the master agent were embedded in. The# global $agent variable is how we do this:$agent-register(myname,$regoid, &my_snmp_handler);if ($subagent) # We need to perform a loop here waiting for snmp requests. We # arent doing anything else here, but we could. $SIGINT = &shut_it_down; $SIGQUIT = &shut_it_down; $running = 1; while($running) $agent-agent_check_and_process(1); # 1 = blockprint STDERR mainloop excercisedn if ($debugging); $agent-shutdown();# define a subroutine to actually handle the incoming requests to our# part of the OID tree. This subroutine will get called for all# requests within the OID space under the registration oid made above.sub my_snmp_handler my ($handler, $registration_info, $request_info, $requests) = _; my $request; print STDERR refs: ,join(, , ref($handler), ref($registration_info), ref($request_info), ref($requests),n; print STDERR processing a request of type . $request_info-getMode() . nif ($debugging); print STDERR get=.MODE_GET., getnext=.MODE_GETNEXT., set reserve1=.MODE_SET_RESERVE1., set=.MODE_SET_ACTION.n; for($request = $requests; $request; $request = $request-next() my $oid = $request-getOID(); print STDERR processing request of $oidn; if ($request_info-getMode() = MODE_GET) if ($oid = new NetSNMP:OID($regat.1.1.0) print STDERR get n if ($debugging); $request-setValue(ASN_OCTET_STR, =get=); elsif ($request_info-getMode() = MODE_GETNEXT) if ($oid setOID($regat.1.1.0); $request-setValue(ASN_OCTET_STR, =getnext=); elsif ($request_info-getMode() = MODE_SET_RESERVE1) if ($oid != new NetSNMP:OID($regat.1.2.0) print STDERR =set reserve1=n if ($debugging); $request-setError($request_info, SNMP_ERR_NOSUCHNAME); elsif ($request_info-getMode() = MODE_SET_ACTION) print STDERR =set=n if ($debugging); if ($oid = new NetSNMP:OID($regat.1.2.0) $value = $request-getValue(); print STDERR finished processingnif ($debugging);sub shut_it_down $running = 0; print STDERR shutting downn if ($debugging);rootlocalhost snmp_perl#启动snmpd显示debug信息rootlocalhost snmp# snmpd -Le -f -dstarting perl_module.plperl_module.pl loaded okregistering at enterprises.37945开启另一个终端rootlocalhost test# snmpget -v2c -c public localhost ..4.1.379SNMPv2-SMI:enterprises.379 = STRING: =get=rootlocalhost test# snmpwalk -v2c -c public localhost ..4.1.37945.1SNMPv2-SMI:enterprises.379 = STRING: =getnext=rootlocalhost test# snmpset -v1 -c private localhost ..4.1.379 i 123SNMPv2-SMI:enterprises.379 = INTEGER: 123rootlocalhost test# snmpset -v1 -c private localhost ..4.1.379 s abcdefSNMPv2-SMI:enterprises.379 = STRING: abcdef查看原来终端的debug信息rootlocalhost snmp# snmpd -Le -f -dstarting perl_module.plperl_module.pl loaded okregistering at enterprises.37945NET-SNMP version refs: NetSNMP:agent:netsnmp_mib_handler, NetSNMP:agent:netsnmp_handler_registrationPtr, NetSNMP:agent:netsnmp_agent_request_info, NetSNMP:agent:netsnmp_request_infoPtrprocessing a request of type 160get=160, getnext=161, set reserve1=0, set=2 processing request of enterprises.379get finished processingrefs: NetSNMP:agent:netsnmp_mib_handler, NetSNMP:agent:netsnmp_handler_registrationPtr, NetSNMP:agent:netsnmp_agent_request_info, NetSNMP:agent:netsnmp_request_infoPtrprocessing a request of type 161get=160, getnext=161, set reserve1=0, set=2 processing request of enterprises.37945.1get next finished processingrefs: NetSNMP:agent:netsnmp_mib_handler, NetSNMP:agent:netsnmp_handler_registrationPtr, NetSNMP:agent:netsnmp_agent_request_info, NetSNMP:agent:netsnmp_request_infoPtrprocessing a request of type 161get=160, getnext=161, set reserve1=0, set=2 processing request of enterprises.379 finished processingrefs: NetSNMP:agent:netsnmp_mib_handler, NetSNMP:agent:netsnmp_handler_registrationPtr, NetSNMP:agent:netsnmp_agent_request_info, NetSNMP:agent:netsnmp_request_infoPtrprocessing a request of type 0get=160, getnext=161, set reserve1=0, set=2 processing request of enterprises.379 finished processingrefs: NetSNMP:agent:netsnmp_mib_handler, NetSNMP:agent:netsnmp_handler_registrationPtr, NetSNMP:agent:netsnmp_agent_request_info, NetSNMP:agent:netsnmp_request_infoPtrprocessing a request of type 1get=160, getnext=161, set reserve1=0, set=2 processing request of enterprises.379 finished processingrefs: NetSNMP:agent:netsnmp_mib_handler, NetSNMP:agent:netsnmp_handler_registrationPtr, NetSNMP:agent:netsnmp_agent_request_info, NetSNMP:agent:netsnmp_request_infoPtrprocessing a request of type 2get=160, getnext=161, set reserve1=0, set=2 processing request of enterprises.379=set= finished processingrefs: NetSNMP:agent:netsnmp_mib_handler, NetSNMP:agent:netsnmp_handler_registrationPtr, NetSNMP:agent:netsnmp_agent_request_info, NetSNMP:agent:netsnmp_request_infoPtrprocessing a request o
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 生药学试题及答案填空题
- 数字安全环境下国家安全威胁的多维度评估方法-洞察及研究
- 高频接地施工合同范本(3篇)
- 高空作业施工拆卸合同(3篇)
- 宠物领养与送养双方权益保障协议书
- 时尚街区品牌店面转租合作协议范本
- 自动驾驶汽车与移动应用的深度协同-洞察及研究
- 城市轨道交通材料运输及进度控制合同
- 高效个人购房贷款及专业担保服务合同
- 国际工程项目承包与咨询服务合同
- 药店医保考试试题及答案
- 2025年中考历史总复习中国古代史专题复习资料
- 单用途卡资金管理制度
- 雾化吸入治疗护理常规
- 全友家居加盟合同范本
- 地理-法国课件-2024-2025学年湘教版地理七年级下册
- 国际贸易学(第五版)课后题参考答案 金泽虎
- 2025年全国成人高考语文试题及答案
- 【镇江】2025年江苏镇江市高等专科学校公开招聘工作人员5人笔试历年典型考题及考点剖析附带答案详解
- 员工社保补贴合同协议
- 2025年家庭医生签约服务培训大纲
评论
0/150
提交评论