我是新來的perl,但是我正在爲nagios寫一個插件。我有一個簡單的get請求失敗,但如果我使用snmpwalk嘗試相同的請求,它將起作用。當snmpwalk工作時,Perl Net :: SNMP返回noSuchName
我的代碼是:
#!/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,它將按照它應該的方式工作。