テーブルを読み取るために使用するコードを次に示します ($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