Net::SNMP::Interfaces - provide simple methods to gain interface data via
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().
The constructor of the class. It takes several arguments that are passed to Net::SNMP :
The name of the host which you want to connect to. Defaults to 'localhost'.
The SNMP community string which you want to use for this session. The default is 'public'.
The UDP port that the SNMP service is listening on. The default is 161.
The SNMP version (as described in the Net::SNMP documentation) to be used. The default is 'snmpv1'. Support for SNMPv3 is currently somehwat limited.
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.
Returns a list of the interface names.
Returns a list of the indices of the interfaces - this probably shouldn't be necessary but is here for completeness anyway. If you dont know what the index is for you are safe to ignore this.
Returns the text of the last Net::SNMP error. This method only makes sense if the previous method call indicated an error by a false return.
Returns the Net::SNMP session object for this instance. Or a false value if there is no open session. This might be used to call methods on the Net::SNMP object if some facility is needed that isnt supplied by this module.
Returns a list of Net::SNMP::Interface::Details objects corresponding to the interfaces discovered on this host. In scalar context it will return a reference to an array.
Returns a Net::SNMP::Interfaces::Details object for the named interface. Returns undef if the supplied name is not a known interface.
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
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 <email@example.com>
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.