我有以下代码段应该通过 snmp 检索数据:
my $pl = Parallel::Loops->new(100);
$pl->share( $infohash, \%bounds);
$pl->foreach( \@servArray, sub {
my $server = $_;
my ($session, $error) = Net::SNMP->session(-hostname => $server, -community => $community_string);
if ($error) { die ("$error") };
if ($session) {
my $return = snmpwalk(
snmp => $session,
oids => $oidhash{$server},
-mycallback => sub {
my ($s, $host, $key, $val) = @_;
my @tempArray = split (/,/, $key);
$bounds{$host}{$tempArray[0]}{$$val[0][0]}{$tempArray[1]} = $$val[0][1];
}
);
$session->close();
}
else {
die ($error);
}
});
$infohash 是一个嵌套的 hashref,结构如下:
'hostname' => {
'hard_drives' => {
'serial_number' => 1
},
'system' => {
'service_tag' => 1
},
'ip_address' => {
'ip_address' => 1
},
'memory' => {
'serial_number' => 1
}
},
并且 %oidhash 包含对应的 oid 列表,如下所示:
'hostname' => {
'system,service_tag' => '1.3.6.1.4.1.674.10892.1.300.10.1.11.1',
'hard_drives,serial_number' => '1.3.6.1.4.1.674.10893.1.20.130.4.1.7',
'memory,serial_number' => '1.3.6.1.4.1.674.10892.1.1100.50.1.23.1',
'ip_address,ip_address' => '1.3.6.1.4.1.674.10892.1.1100.90.1.11.1'
},
现在,除了 system/service_tag 位之外,所有元素都可以正常工作。这是我从@return 得到的输出:
$VAR1 = \{
'memory,serial_number' => {
'10' => '874F72F8',
'12' => '874F73DF',
'11' => '874F73CD',
'1' => '874F7242',
'8' => '874F746C',
'2' => '874F7474',
'3' => '874F7477',
'5' => '874F743F',
'7' => '874F73D3',
'6' => '874F747F',
'9' => '874F73D9',
'4' => '874F7237'
},
'ip_address,ip_address' => {
'1' => '<public IP>',
'2' => '10.245.27.145'
},
'system,service_tag' => {},
'hard_drives,serial_number' => {
'6' => '9XF05FE0',
'4' => '9XF05LXB',
'1' => '9XF05GM0',
'2' => '9XF05FHH',
'3' => '9XF05FE8',
'5' => '9XF04JNK'
}
};
显然,这意味着 snmpwalk 没有按应有的方式检索所有数据,但如果我能找到原因,我会被诅咒的。如果我手动 snmpwalk 服务标签 OID,它会检索数据,所以它不是 OID,也不是我能找到的任何东西,因为所有其他数据都在检索。