0

NetSNMP::Agent在 Perl 中使用来查询一些值。现在我正在研究如何返回列表。EG 表名、进程等。

是否只是在查询每个项目时为每个项目创建一个新的树条目,或者是否有一些必须预定义的内容?在浏览预定义的 MIB 时,我会看到类似的列表。只是想知道临时值的机制是什么。

另外 - 有没有办法使用snmpget或者snmpwalk每次都需要这样的列表?

4

2 回答 2

1

这是我用来读取表的一些代码(假设 $session 是建立 Net::SNMP 会话):

# I create a large hash of all the OIDs and their names
my %oidmap = (
    'vsvrServiceName' => '.1.3.6.1.4.1.5951.4.1.3.2.1.8',
    'vsvrServiceFullName' => '.1.3.6.1.4.1.5951.4.1.3.2.1.9',
    'vserverFullName' => '.1.3.6.1.4.1.5951.4.1.3.2.1.10',
    ...
);

# Choose which column names I want to extract from table
my @columnnames = qw(
    vserverFullName
    vsvrServiceName
    vsvrServiceFullName
);

# Get ALL entries in the table for those columns
my $vsvrEntries = $session->get_entries(
    -columns => [ map { $oidmap{$_} } @columnnames ],
    -maxrepetitions => 1,
);


# Decode the result column names, column values, and index
foreach my $key ( keys %{$vsvrEntries} ) {
    my $value = $vsvrEntries->{$key};

    # scan through OIDs to see if there's a match
    foreach my $oid_name ( @columnnames ) {
        my $oid = $oidmap{ $oid_name };
        next if ( $key !~ m{^\Q$oid\E\.(.+)$} );

        my $remainder = $1;

        print( "  $oid_name.$remainder = $value\n" );
        last;
    }
}

困难的部分是获取 OID 列表。为此,您可以自己解决它们 - 或者找到一个 Linux 服务器,将您的 MIB 存储到/usr/share/snmp/mibs并从命令行使用 net-snmp 工具,例如:

user@myhost:~$ snmptranslate -I b -O n vsvrServiceName
.1.3.6.1.4.1.5951.4.1.3.2.1.8
于 2013-07-01T14:13:06.470 回答
0

I'm have little experience using NetSNMP package, I use NET::SNMP, but if you can collaborate more on what exactly you are trying to achieve and post some sample code or specific OID references I might be able to help you...

于 2013-06-30T06:55:45.070 回答