C
csb
While searching for an answer to my problem, I came across this group.
Please let me know if it doesn't belong here and I'll continue my
search elsewhere.
I'm in the process of converting some shell scripts over to Perl.
I've always used Net::SNMP and it's served me without fail.
However, I'm beating my head against a wall with an issue and I
cannot figure out what I'm doing wrong.
I'm attempting to have my Perl script generate a remote ping
(icmpEchoReq) and display the response time. I currently perform this
function with 'snmpget' but I'd like it to not call external
files from Perl if at all possible.
When I perform the Net::SNMP Get, my $getresponse-> is empty. Using
Ethereal, I can see the SNMP Get request departing the target host, and
the response returning to the target host.
When I perform the same Get using 'snmpget' I display the response
properly. I suspect it has something to do with the Get and the
response to the Get not being the exact same OID. For instance, if I
use 'snmpget' and Get OID ".1.3.6.1.4.1.11.2.7.1.64.5.10.0.0.3"
(remote ping 10.0.0.3, packet size 64, timeout 5 seconds) the response
comes back as OID "1.3.6.1.4.1.11.2.7.1.0"
(hp.nm.icmp.icmpEchoReq.0).
Could this be the reason my $getresponse-> is null? How can I overcome
this using Net::SNMP?
All code and output are listed below. Any advice or direction would be
greatly appreciated.
Thanks!
Chuck
------------------------------------------
CODE (PERL): 'rping.pl'
use Net::SNMP;
$OIDicmpEchoReq1 = '1.3.6.1.4.1.11.2.7.1.64.5.10.0.0.3';
$OIDicmpEchoReq2 = '1.3.6.1.4.1.11.2.7.1.0';
$OIDifOperStatus = '1.3.6.1.2.1.2.2.1.8.1';
$Target = 'foo';
$Community = 'bar';
$Timeout = 10;
$Retries = 0;
#BEGIN
&do_snmpget($OIDicmpEchoReq1);
print "Query Response A: $retval\n";
# &do_snmpget($OIDicmpEchoReq2);
# print "Query Response B: $retval\n";
&do_snmpget($OIDifOperStatus);
print "Query Response C: $retval\n";
# END
sub do_snmpget {
($oid_to_get)=@_;
($session, $error) = Net::SNMP->session(
Timeout => $Timeout,
Retries => $Retries,
Hostname => $Target,
Community => $Community,
Port => 161,
Translate => [-all => 0x0]);
if (!defined($getresponse =
$session->get_request($oid_to_get))) {
$error_msg=$session->error; print "ERROR - Target:
$Target;
Cmty: $Community; $oid_to_get; $error_msg\n"; $session->close;}
#print "a: $getresponse->{$oid_to_get}\n";
$retval=$getresponse->{$oid_to_get}; $session->close;
#print "retval-a: $retval\n";
#$retval=unpack("A*",pack("H*",$retval)) if (retval =~ /^0x/);
#print "retval-b: $retval\n";
return($retval);}
-----------------------------------------
OUTPUT (PERL): 'perl rping.pl'
Query Response A:
Query Response C: 1
==========================================
CODE (SHELL): 'rping.sh'
snmpget -c bar foo .1.3.6.1.4.1.11.2.7.1.64.5.10.0.0.3
snmpget -c bar foo .1.3.6.1.2.1.2.2.1.8.1
------------------------------------------
OUTPUT (SHELL): 'rping.sh'
hp.nm.icmp.icmpEchoReq.0 : INTEGER: 22
interfaces.ifTable.ifEntry.ifOperStatus.1 : INTEGER: up
------------------------------------------
Please let me know if it doesn't belong here and I'll continue my
search elsewhere.
I'm in the process of converting some shell scripts over to Perl.
I've always used Net::SNMP and it's served me without fail.
However, I'm beating my head against a wall with an issue and I
cannot figure out what I'm doing wrong.
I'm attempting to have my Perl script generate a remote ping
(icmpEchoReq) and display the response time. I currently perform this
function with 'snmpget' but I'd like it to not call external
files from Perl if at all possible.
When I perform the Net::SNMP Get, my $getresponse-> is empty. Using
Ethereal, I can see the SNMP Get request departing the target host, and
the response returning to the target host.
When I perform the same Get using 'snmpget' I display the response
properly. I suspect it has something to do with the Get and the
response to the Get not being the exact same OID. For instance, if I
use 'snmpget' and Get OID ".1.3.6.1.4.1.11.2.7.1.64.5.10.0.0.3"
(remote ping 10.0.0.3, packet size 64, timeout 5 seconds) the response
comes back as OID "1.3.6.1.4.1.11.2.7.1.0"
(hp.nm.icmp.icmpEchoReq.0).
Could this be the reason my $getresponse-> is null? How can I overcome
this using Net::SNMP?
All code and output are listed below. Any advice or direction would be
greatly appreciated.
Thanks!
Chuck
------------------------------------------
CODE (PERL): 'rping.pl'
use Net::SNMP;
$OIDicmpEchoReq1 = '1.3.6.1.4.1.11.2.7.1.64.5.10.0.0.3';
$OIDicmpEchoReq2 = '1.3.6.1.4.1.11.2.7.1.0';
$OIDifOperStatus = '1.3.6.1.2.1.2.2.1.8.1';
$Target = 'foo';
$Community = 'bar';
$Timeout = 10;
$Retries = 0;
#BEGIN
&do_snmpget($OIDicmpEchoReq1);
print "Query Response A: $retval\n";
# &do_snmpget($OIDicmpEchoReq2);
# print "Query Response B: $retval\n";
&do_snmpget($OIDifOperStatus);
print "Query Response C: $retval\n";
# END
sub do_snmpget {
($oid_to_get)=@_;
($session, $error) = Net::SNMP->session(
Timeout => $Timeout,
Retries => $Retries,
Hostname => $Target,
Community => $Community,
Port => 161,
Translate => [-all => 0x0]);
if (!defined($getresponse =
$session->get_request($oid_to_get))) {
$error_msg=$session->error; print "ERROR - Target:
$Target;
Cmty: $Community; $oid_to_get; $error_msg\n"; $session->close;}
#print "a: $getresponse->{$oid_to_get}\n";
$retval=$getresponse->{$oid_to_get}; $session->close;
#print "retval-a: $retval\n";
#$retval=unpack("A*",pack("H*",$retval)) if (retval =~ /^0x/);
#print "retval-b: $retval\n";
return($retval);}
-----------------------------------------
OUTPUT (PERL): 'perl rping.pl'
Query Response A:
Query Response C: 1
==========================================
CODE (SHELL): 'rping.sh'
snmpget -c bar foo .1.3.6.1.4.1.11.2.7.1.64.5.10.0.0.3
snmpget -c bar foo .1.3.6.1.2.1.2.2.1.8.1
------------------------------------------
OUTPUT (SHELL): 'rping.sh'
hp.nm.icmp.icmpEchoReq.0 : INTEGER: 22
interfaces.ifTable.ifEntry.ifOperStatus.1 : INTEGER: up
------------------------------------------