App-Netsync
view release on metacpan or search on metacpan
lib/App/Netsync/SNMP.pm view on Meta::CPAN
=over 3
=item C<App::Netsync::SNMP::Info $ip;>
=item C<App::Netsync::SNMP::Info App::Netsync::SNMP::Session $ip;>
=back
=cut
sub Info {
warn 'too few arguments' if @_ < 1;
warn 'too many arguments' if @_ > 1;
my ($ip) = @_;
my $session = Session $ip;
my $info = SNMP::Info->new(
'AutoSpecify' => 1,
'Session' => $session,
);
return ($session,$info);
}
=head2 get1
attempt to retrieve an OID from a provided list, stopping on success
B<Arguments>
I<( \@OIDs , $ip )>
=over 3
=item OIDs
a prioritized list of OIDs to try and retreive
=item ip
an IP address to connect to or an SNMP::Session
=back
=cut
sub get1 {
warn 'too few arguments' if @_ < 2;
warn 'too many arguments' if @_ > 2;
my ($OIDs,$ip) = @_;
my $session = $ip;
unless (blessed $session and $session->isa('SNMP::Session')) {
return undef if ref $session;
$session = SNMP $session;
return undef unless defined $session;
}
my (@objects,@IIDs);
foreach my $OID (@$OIDs) {
my $query = SNMP::Varbind->new([$OID->[0]]);
while (my $object = $session->getnext($query)) {
last unless $query->tag eq $OID->[1] and not $session->{'ErrorNum'};
last if $object =~ /^ENDOFMIBVIEW$/;
$object =~ s/^\s*(.*?)\s*$/$1/;
push (@IIDs,$query->iid);
push (@objects,$object);
}
last if @objects != 0;
}
return undef if @objects == 0;
return (\@objects,\@IIDs);
}
=head2 set
attempt to set a new value on a device using SNMP
B<Arguments>
I<( $OID , $IID , $value , $ip )>
=over 3
=item OID
the OID to write the value argument to
=item IID
the IID to write the value argument to
=item value
the value to write to OID.IID
=item ip
an IP address to connect to OR an SNMP::Session
=back
=cut
sub set {
warn 'too few arguments' if @_ < 4;
warn 'too many arguments' if @_ > 4;
my ($OID,$IID,$value,$ip) = @_;
my $session = $ip;
unless (blessed $session and $session->isa('SNMP::Session')) {
return undef if ref $session;
$session = SNMP $session;
return undef unless defined $session;
}
my $query = SNMP::Varbind->new([$OID,$IID,$value]);
$session->set($query);
return ($session->{'ErrorNum'}) ? $session->{'ErrorStr'} : 0;
}
=head1 AUTHOR
David Tucker, C<< <dmtucker at ucsc.edu> >>
=head1 BUGS
Please report any bugs or feature requests to C<bug-netsync at rt.cpan.org>, or through
the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=App-Netsync>. I will be notified, and then you'll
automatically be notified of progress on your bug as I make changes.
=head1 SUPPORT
You can find documentation for this module with the perldoc command.
perldoc App::Netsync
You can also look for information at:
=over 4
=item * RT: CPAN's request tracker (report bugs here)
L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=App-Netsync>
=item * AnnoCPAN: Annotated CPAN documentation
L<http://annocpan.org/dist/App-Netsync>
=item * CPAN Ratings
L<http://cpanratings.perl.org/d/App-Netsync>
=item * Search CPAN
L<http://search.cpan.org/dist/App-Netsync/>
=back
=head1 LICENSE
Copyright 2013 David Tucker.
This program is free software; you can redistribute it and/or modify it
under the terms of either: the GNU General Public License as published
by the Free Software Foundation; or the Artistic License.
See L<http://dev.perl.org/licenses/> for more information.
=cut
1;
( run in 0.538 second using v1.01-cache-2.11-cpan-2398b32b56e )