From: HansHG on 21 Feb 2007 12:44 Hi all! I have a script that returns one SNMP OID from an SNMP Agent. It works perfectly: #!/usr/bin/perl -w use strict; use IO::Handle; use Net::SNMP; my $agentIdUniqueId = '.1.3.6.1.4.1.1977.1.1.2.1.0'; sub getuid { my ($session, $error) = Net::SNMP->session ( -hostname => shift || $_[0], -community => shift || $community, -port => shift || $port ); my %hash = ($session->hostname, $result->{$agentIdUniqueId}); while ( ($k, $v) = each %hash) { print "key $k value $v\n"; } this works. But what do I do, when I have more than one varbind in my varbindlist? Like: my $result = $session->get_request(-varbindlist => [$agentIdUniqueId,$agentIdName,$agentBuildDescription, $agentBuildVersion,$agentBuildNumber,$agentIdPlatformDescription]); How do I need to change the script so that it returns all requested OIDs? The query is done from perl. I can see the OIDs getting requested in wireshark. But how do I return them? please help cheers Hans
From: sl123 on 21 Feb 2007 21:43 On 21 Feb 2007 09:44:46 -0800, "HansHG" <hgehrts(a)gmail.com> wrote: >Hi all! > >I have a script that returns one SNMP OID from an SNMP Agent. It works >perfectly: >#!/usr/bin/perl -w >use strict; >use IO::Handle; >use Net::SNMP; >my $agentIdUniqueId = '.1.3.6.1.4.1.1977.1.1.2.1.0'; >sub getuid { > my ($session, $error) = Net::SNMP->session > ( > -hostname => shift || $_[0], > -community => shift || $community, > -port => shift || $port > ); > my %hash = ($session->hostname, $result->{$agentIdUniqueId}); > >while ( ($k, $v) = each %hash) { > print "key $k value $v\n"; > } > >this works. But what do I do, when I have more than one varbind in my >varbindlist? Like: > my $result = $session->get_request(-varbindlist => >[$agentIdUniqueId,$agentIdName,$agentBuildDescription, >$agentBuildVersion,$agentBuildNumber,$agentIdPlatformDescription]); > >How do I need to change the script so that it returns all requested >OIDs? The query is done from perl. I can see the OIDs getting >requested in wireshark. But how do I return them? > >please help >cheers >Hans I'm not familiar with Net::SNMP but if it has a "get_request()" method that returns a reference to an anonymous hash or array, then just loop through it and print. Or like in your sub code there (callback?) just put the reference in as the second (value) parameter and loop through it later, or loop the return reference and add as many key value pairs as you want. The "," in the hash asignment will always separate the key and value (the way you are using it) unless it see's a "=>" separator but thats used when the lvalue is a constant.... whatever. Btw, you code didn't run on my machine. asign it to the %hash variable second parameter
|
Pages: 1 Prev: problem reading remote file. Next: Problem with Perl extensions |