On Tue, Dec 21, 2004 at 09:45:03AM -0700, Jim wrote:
> Rob Bloodgood wrote:
> > That being said: it sounds like you're issuing 4 different OID requests.
> > It also sounds like you're
> > creating a session per VLAN.
> >
> > You ONLY create a session per VLAN *if* each VLAN has a different IP
> > address. Otherwise you simply send
> > another request to your main SNMP component instance.
>
> Each vlan has the same IP, but a different community string; is that
> sufficient for the factory to create a new session?
>
> I know that sounds odd, but to get an OID (e.g .1.3.6.1.2.1.17.4.3.1.2
> to get a list of bridge ports) for vlan 321, one uses "[EMAIL PROTECTED]" as
> the comstring (our comstring isn't "public" but you get the idea).
Did I mention I wasn't an SNMP expert? :-)
Yes, you do need a different component for each community string as well.
> > As far as the OID requests, you should be able to ask for all 4 in one
> > query (unless, of course, they're
> > all on different hosts). If you can't, or you're dealing with async
> > issues, I've solved this type of
> > situation by creating a little object class that has placeholders for each
> > expected response, and an
> > is_done() method that returns true when all placeholders are filled (and be
> > sure to code that an error
> > counts as filling the correct slot for that request's answer).
> >
> > Once you get your is_done() running true, and you're finished with said
> > host, you can then shut down the
> > component instance for that host if your program isn't a long-running
> > daemon.
>
> An important detail that I left out is that I'm using "walk" to get the
> entire table. As Net::SNMP::get_table doesn't look for array references
> as the value of -basoid, I can't get it in one request.
As far as I know, the trick with walk is to simply detect when your answer
changes OID's, like
0.0.0.0.0.1.0
0.0.0.0.0.1.1
0.0.0.0.0.1.2
0.0.0.0.0.1.3
0.0.0.0.0.1.4
0.0.0.0.0.2.0 # this one is your "last", so stop reading, you have your whole
answer.
> I just switched to getbulk as the related get_bulk_request() seems to
> support an OID list, but my test switch isn't responding correctly. I'll
> need to fiddle with that...
PoCo::SNMP is a thin wrapper over Net::SNMP. So whatever's supported in
Net::SNMP should work
essentially according to the docs. HOWEVER the test(s) might be incomplete or
inaccurate. Let me know
if you find a weakness in the implementation. Or let me know if you find the
answer.
> Have you released the class that implements is_done()? I don't imagine
> it's too difficult, but I'm lazy... :-)
Here's a snippet, from my module. There are of course other methods but here's
everything that pertains
to the is_done() functionality:
=============================
# make an entry per request
sub _init {
my $self = shift;
$self->{ _s } = { 'request1' => undef,
'request2' => undef,
'request3' => undef,
};
$self;
}
# keys of available requests
sub requests {
my $self = shift;
keys %{$self->{_s}};
}
# assign a defined result to a request
sub finish {
my $self = shift;
my ($s, $arg) = @_;
$self->{_s}{$s} = $arg;
}
# does the request have a defined result?
sub has_finished {
my $self = shift;
defined $self->{_s}{ +shift };
}
# returns true if there are no remaining requests that are not finished
sub is_done {
my $self = shift;
0 == scalar grep { ! $self->has_finished($_) } $self->requests
}
=============================
Hope this helps!
L8r,
Rob