关键词不能为空

当前您在: 主页 > 英语 >

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的相关文章