关键词不能为空

当前您在: 主页 > 英语 >

net-snmp perl

作者:高考题库网
来源:https://www.bjmy2z.cn/gaokao
2021-02-18 03:14
tags:

-

2021年2月18日发(作者:failsafe)





Net- snmp


使用


perl


扩展



agent



摘要:




< /p>


配置文件中,使用


Perl


进行扩展。< /p>



官网:




/dist/NetSNMP-agent/


版本:


NET-SNMP version 5.7.2.1


系统:


CentOS X64


软件包:




安装


perl


[root@localhost net-snmp-5.7.2.1]#yum install perl-devel perl-ExtUtils-Embed net-snmp- perl


[root@localhost net-snmp-5.7.2.1]# rpm -qa|grep perl


6.x86_64


6_5.1.x86_64


6.x86_64


6.x86_64


6.x86_64


6.x86_64


6.x86_64


6.x86_64


6.x86_64


6.x86_64


6.x86_64


6.x86_64


6.x86_64


6.x86_64


6.x86_64


6.x86_64


解压安装包:



[root@localhost snmp]# pwd


/root/snmp


[root@localhost snmp]# ls








[root@localhost snmp]# tar xzvf


[root@localhost snmp]# ls


net-snmp-5.7.2.1




配置



[root@localhost snmp]# cd net- snmp-5.7.2.1


[root@localhost net- snmp-5.7.2.1]# pwd


/root/snmp/net- snmp-5.7.2.1


[root@localhost net- snmp-5.7.2.1]# ./configure


配置完成后,会显示如下< /p>


configure


摘要信息



------------------------------------------- --------------














Net-SNMP configuration summary:


------------------------------ ---------------------------





SNMP Versions Supported:





1 2c 3




Building for:
















linux




Net-SNMP Version:












5.7.2.1




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:





disabled



5.4


版本以后的默认安装


perl


模块,如果不支持,请使用



[root@localhost net- snmp-5.7.2.1]#./configure --enable-embedded-perl


编译、安装




make && make install








配置



[root@localhost snmp]# pwd


/usr/local/share/snmp


[root@localhost snmp]# snmpconf




The following installed configuration files were found:






1:



./





2:



/usr/local/share/snmp/



Would you like me to read them in?



Their content will be merged with the


output files created by this session.



Valid answer examples:



Read in which (default = all):


none




I 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:







2:







3:





Other options: quit



Select File:


1




The configuration information which can be put into is divided


into sections.



Select a configuration section for


that 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 Setup








Other options: finished



Select section:


1




Section: Access Control Setup


Description:




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 name



Other options: finished, list



Select section:


3




Configuring: rocommunity


Description:




a SNMPv1/SNMPv2c read-only access community name






arguments:



community [default|hostname|network/bits] [oid]



The community name to add read-only access for: public


The 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 Setup


Description:




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 name








Other options: finished, list



Select section: 4



Configuring: rwcommunity


Description:




a SNMPv1/SNMPv2c read-write access community name






arguments:



community [default|hostname|network/bits] [oid]



Enter the community name to add read- write access for: private


The 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 Setup


Description:




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 name



Other options: finished, list



Select section:


finished




The configuration information which can be put into is divided


into sections.



Select a configuration section for


that 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 Setup



Other options: finished








Select section:


finished




I 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:







2:







3:





Other options:


quit




Select File:


quit





The following files were created:









These files should be moved to


/usr/local/share/snmp


if you


want them used by everyone on the system.



In the future, if you add



the -i option to the command line I'll 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 the


command line I'll copy them there automatically for you.



perl


扩展


agent


[root@localhost snmp]# pwd


/usr/local/share/snmp



[root@localhost snmp]# vim


增加如下内容:



perl do '/root/snmp/test/snmp_perl/perl_';





配置文件



[root@localhost snmp]# pwd







/usr/local/share/snmp


[root@localhost snmp]# cat


rocommunity



public




rwcommunity



private




perl do '/root/snmp/test/snmp_perl/perl_';



perl


脚本



[root@localhost snmp_perl]# pwd


/root/snmp/test/snmp_perl


[root@localhost snmp_perl]# cat perl_



#!/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


# file:


#


#




perl do


#



my $$regat = '.1.3.6.1.4.1.37945';



BEGIN {






print STDERR


}



use NetSNMP::OID (':all');


use NetSNMP::agent (':all');


use NetSNMP::ASN (':all');



print STDERR



# set to 1 to get extra debugging information


$$debugging = 1;



# if we're not embedded, this will get auto-set below to 1


$$subagent = 0;



# where we are going to hook onto


my $$regoid = new NetSNMP::OID($$regat);


print STDERR








# If we're not running embedded within the agent, then try to start


# our own subagent instead.


if (!$$agent) {






$$agent = new NetSNMP::agent('Name' => 'test', # reads






'AgentX' => 1);




# make us a subagent






$$subagent = 1;






print STDERR


}



# we register ourselves with the master agent we're 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






# aren't doing anything else here, but we could.






$$SIG{'INT'} = &shut_it_down;






$$SIG{'QUIT'} = &shut_it_down;






$$running = 1;






while($$running) {



$$agent->agent_check_and_process(1);



# 1 = block



print STDERR






}






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













ref($$request_info), ref($$requests)),







print STDERR



if ($$debugging);







print


STDERR



getnext=


reserve1=




set









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.


















print STDERR


















$$request->setValue(ASN_OCTET_STR,














}










} elsif ($$request_info->getMode() == MODE_GETNEXT) {














if ($$oid < new NetSNMP::OID($$regat.


















print STDERR


















$$request->setOID($$regat.


















$$request->setValue(ASN_OCTET_STR,














}










} elsif ($$request_info->getMode() == MODE_SET_RESERVE1) {














if ($$oid != new NetSNMP::OID($$regat.


















print STDERR


















$$request->setError($$request_info, SNMP_ERR_NOSUCHNAME);














}










} elsif ($$request_info->getMode() == MODE_SET_ACTION) {














print STDERR














if ($$oid == new NetSNMP::OID($$regat.


















$$value = $$request->getValue();














}










}






}







print STDERR



finished processingn



if ($$debugging);


}



sub shut_it_down {




$$running = 0;




print STDERR


}


[root@localhost snmp_perl]#


启动


snmpd


显示


debug


信息



[root@localhost snmp]# snmpd -Le -f -d


starting perl_


perl_ loaded ok



-


-


-


-


-


-


-


-



本文更新与2021-02-18 03:14,由作者提供,不代表本网站立场,转载请注明出处:https://www.bjmy2z.cn/gaokao/664165.html

net-snmp perl的相关文章

  • 余华爱情经典语录,余华爱情句子

    余华的经典语录——余华《第七天》40、我不怕死,一点都不怕,只怕再也不能看见你——余华《第七天》4可是我再也没遇到一个像福贵这样令我难忘的人了,对自己的经历如此清楚,

    语文
  • 心情低落的图片压抑,心情低落的图片发朋友圈

    心情压抑的图片(心太累没人理解的说说带图片)1、有时候很想找个人倾诉一下,却又不知从何说起,最终是什么也不说,只想快点睡过去,告诉自己,明天就好了。有时候,突然会觉得

    语文
  • 经典古训100句图片大全,古训名言警句

    古代经典励志名言100句译:好的药物味苦但对治病有利;忠言劝诫的话听起来不顺耳却对人的行为有利。3良言一句三冬暖,恶语伤人六月寒。喷泉的高度不会超过它的源头;一个人的事

    语文
  • 关于青春奋斗的名人名言鲁迅,关于青年奋斗的名言鲁迅

    鲁迅名言名句大全励志1、世上本没有路,走的人多了自然便成了路。下面是我整理的鲁迅先生的名言名句大全,希望对你有所帮助!当生存时,还是将遭践踏,将遭删刈,直至于死亡而

    语文
  • 三国群英单机版手游礼包码,三国群英手机单机版攻略

    三国群英传7五神兽洞有什么用那是多一个武将技能。青龙飞升召唤出东方的守护兽,神兽之一的青龙。玄武怒流召唤出北方的守护兽,神兽之一的玄武。白虎傲啸召唤出西方的守护兽,

    语文
  • 不收费的情感挽回专家电话,情感挽回免费咨询

    免费的情感挽回机构(揭秘情感挽回机构骗局)1、牛牛(化名)向上海市公安局金山分局报案,称自己为了挽回与女友的感情,被一家名为“实花教育咨询”的情感咨询机构诈骗4万余元。

    语文