Net::SNMP::Interfaces - provide simple methods to gain interface data via |
Net::SNMP::Interfaces - provide simple methods to gain interface data via
SNMP
use Net::SNMP::Interfaces;
my $interfaces = Net::SNMP::Interfaces->new(Hostname => 'localhost', Community => 'public' );
my @ifnames = $interfaces->all_interfaces();
Net::SNMP::Interfaces aims to provide simple object methods to obtain information about a host's network interfaces ( be it a server a router or whatever ). The motivation was largely to allow a programmer to use SNMP to obtain this information without needing to know a great deal about the gory details.
The module uses Net::SNMP under the hood to do the dirty work although the user shouldn't have to worry about that ( the Net::SNMP object is available though for those who might feel the need ).
The actual details for a particular interface are obtained from the methods
of Net::SNMP::Interfaces::Details - objects of which type can be obtained
for the methods all_interfaces()
and interface().
Of course the simpler interface has its limitations and there may well be things that you would like to do which you cant do with this module - in which case I would recommend that you get a good book on SNMP and use Net::SNMP :)
The module uses blocking SNMP requests at the current time so if some of the methods are taking too long you may want to time them out yourself using alarm().
There is a also an optional argument 'RaiseError' which determines
the behaviour of the module in the event there is an error while creating
the SNMP. Normally new()
will return undef if there was an error but if
RaiseError is set to a true value it will die()
printing the error string
to STDERR. If this is not set and an error occurs undef will be return
and the variable $Net::SNMP::Interfaces::error will contain the test of
the error.
Because the interfaces are discovered in the constructor, if the module
is to be used in a long running program to monitor a host where
interfaces might be added or removed it is recommended that the object
returned by new()
is periodically destroyed and a new one constructed.
if_names()
if_indices()
error()
session()
all_interfaces()
In addition to the methods above, you can also use the methods from Net::SNMP::Interfaces::Details but with the addition of the interface name as an argument. e.g:
$in_octs = $self->ifInOctets('eth0');
Please see the documentation for Net::SNMP::Interfaces::Details for more on these methods.
The code is host on Github at
https://github.com/jonathanstowe/Net-SNMP-Interfaces
Pull requests are welcome, especially if they help support SNMPv3 better.
Email to <bug-Net-SNMP-Interfaces@rt.cpan.org> is preferred for non-patch requests.
Jonathan Stowe <jns@gellyfish.co.uk>
Copyright (c) Jonathan Stowe 2000 -2013. All rights reserved. This is free software it can be ditributed and/or modified under the same terms as Perl itself.
perl(1), the Net::SNMP manpage, the Net::SNMP::Interfaces::Details manpage.
Net::SNMP::Interfaces - provide simple methods to gain interface data via |