ivancheng has asked for the wisdom of the Perl Monks concerning the following question:

I would like to make use of snmpget to the MIB data as below
my ($result, $err) = snmpget( hosts => \@ARGV, snmp => \%snmparam, oids => \%hash );
The oids information will be read from the file as below. MIB_OID.dat file: interface:.1.3.6.1.2.1.2.2.1.2.1 in_octet:.1.3.6.1.2.1.2.2.1.10.1 out_octet:.1.3.6.1.2.1.2.2.1.16.1 :
use Net::SNMP::Util; open $input_fh, '<', "MIB_OID.dat" or die 'Could not open file: ', $OS +_ERROR; my %hash; while ( my $line = <$input_fh> ) { chomp $line; last if ! $line; my ( $word1 , $word2 ) = split /:/, $line, 2; $hash{$word1} = $word2; }
Kindly advise how I can extract the oids data from the $result as I have no idea for it. Ivan

Replies are listed 'Best First'.
Re: Extract data using snmpget with hash array
by tangent (Parson) on Sep 02, 2015 at 11:30 UTC
    Try something like this:
    use Data::Dumper; for my $host ( @ARGV ) { if ( $result->{$host} ) { print "Got host $host:\n", Dumper( $result->{$host} ); } else { print "Did not get host $host:\n", Dumper( $err->{$host} ); } }
    You should then be able to work out how to extract needed info.
      How can I extract the needed information? Please kindly advice. Thanks in advance. Regards, Ivan