我是 perl 的新手,但我正在尝试为 nagios 编写一个插件。我有一个失败的简单获取请求,但如果我尝试使用 snmpwalk 进行相同的请求,它就可以工作。
我的代码是:
#!/usr/bin/perl -w
use strict;
use Net::SNMP;
my $host = '10.10.10.203';
my $community = 'myComm';
my $session;
my $error;
my $response = undef;
($session, $error) = Net::SNMP->session(
-hostname => $host,
-version => 2,
-community =>$community,
-port => 161,
-timeout => 20
);
my $uptimeOID = '1.3.6.1.2.1.1.3.0';
my $myOID = '1.3.6.1.4.1.7933';
if( !defined( $response = $session->get_request($myOID)))
{
if( $session->error_status == 2)
{
my $sessionError = $session->error;
print ("($sessionError) OID not supported ($myOID).\n");
}
}
else
{
print ("$response");
}
如果我运行这个脚本,它会说 noSuchName 失败,但是如果运行:
snmpwalk -v 2c -c myComm 10.10.10.203 1.3.6.1.4.1.7933
我得到了我想要的回应。有人知道为什么这行不通吗?
如果我使用此脚本检查正常运行时间 OID,它将按应有的方式工作。