用于SNMP V3的Perl不起作用,但适用于SNMP V1 / 2(Redhat Linux)

时间:2012-06-22 01:33:35

标签: linux perl snmp net-snmp

我有一个Perl脚本,可以注册SNMP OID。使用SNMP 1 / 2c,它能够成功注册所有OID。但是,使用SNMP V3,它只能部分工作。

如下所示,使用SNMP V3,它可以成功注册“$ root_OID.0.0.0”。但是,尝试调用“$ root_OID.0.0.1”的java代码时会超时。

有谁知道,为什么我能够在SNMP V1 / 2c中成功进行java调用,而不是SNMP V3?

非常感谢

这是我的Perl脚本:

#!/usr/bin/perl

use NetSNMP::OID (':all'); 
use NetSNMP::ASN qw(ASN_OCTET_STR ASN_INTEGER);
use NetSNMP::agent (':all');

sub myhandler { 
    my ($handler, $registration_info, $request_info, $requests) = @_; 
    my $request;
    my $root_OID = ".1.3.6.1.4.1.8072.9999.9999.0"; 

    my $CLASSPATH = "/opt/BPL/JBoss/BPL_JBossJMX.jar:/opt/jboss-5.1/client/*";
    my $CLASSNAME = "com.XXXXX.XXXXX.XXXXX.jmx.BPLJbossJMX_For_SNMP";
    my $ENV = "localhost";
    my $PORT = "8099";  
    my $LOG4JFILELOC = "/opt/BPL/JBoss/JBoss-BPL-Log4j.xml";

    for($request = $requests; $request; $request = $request->next()) { 
        my $oid = $request->getOID(); 
        if ($request_info->getMode() == MODE_GETNEXT) { 
            if ($oid < new NetSNMP::OID("$root_OID.0.0.0")) { 
                my $INPUTSTRNAME = "HeapMemoryUsageZZZZZ";
                $request->setOID("$root_OID.0.0.0"); 
                $request->setValue(ASN_OCTET_STR, $INPUTSTRNAME); 
            } elsif ($oid < new NetSNMP::OID("$root_OID.0.0.1")) {
                my $INPUTSTRNAME = "HeapMemoryUsage";
                my $OUTPUT= `java -cp $CLASSPATH $CLASSNAME $ENV $PORT $INPUTSTRNAME $LOG4JFILELOC`;
                chomp($OUTPUT);
                $request->setOID("$root_OID.0.0.1");
                $request->setValue(ASN_INTEGER, $OUTPUT);
            }
        } 
    }     
}

my $rootOID = ".1.3.6.1.4.1.8072.9999.9999.0"; 
my $regoid = new NetSNMP::OID($rootOID); 
$agent->register("BPL-JBoss", $regoid, \&myhandler);

这是我的/etc/snmp/snmpd.conf文件(禁用SNMP V1 / 2c):

###############################################################################
# snmpd.conf:
###############################################################################

#com2sec notConfigUser  default       public

#       groupName      securityModel securityName
#group   notConfigGroup v1            notConfigUser
#group   notConfigGroup v2c           notConfigUser

view   systemview    included   .1.3.6.1.4.1.8072.1.3.2
view   systemview    included   .1.3.6.1.2.1
view   systemview    included   .1.3.6.1.2.1.25.1.1
view   systemview    included   .1.3.6.1.4.1.2021       
view   systemview    included   .1.3.6.1.4.1.8072.9999.9999

#access  notConfigGroup ""      any       noauth    exact  systemview none none

###############################################################################
syslocation Unknown (edit /etc/snmp/snmpd.conf)
syscontact Root <root@localhost> (configure /etc/snmp/snmp.local.conf)

###############################################################################
pass .1.3.6.1.4.1.4413.4.1 /usr/bin/ucd5820stat

###############################################################################
perl do "/home/XXXXXXX/JBoss_hello_world.pl"
rouser TEST_USERNAME priv

以下是使用SNMPV3时SNMPWALK的结果。

-$snmpwalk -v 3 -l authPriv -a sha -A TEST_PASSWORD -x AES -X TEST_PASSWORD -u TEST_USERNAME localhost .1.3.6.1.4.1.8072.9999.9999
NET-SNMP-MIB::netSnmpPlaypen.0.0.0.0 = STRING: "HeapMemoryUsageZZZZZ"
Timeout: No Response from localhost

0 个答案:

没有答案