Author image Athanasios Douitsis


SNMP::Class - A convenience class around the NetSNMP perl modules.


Version 0.11


This module aims to enable snmp-related tasks to be carried out with the best possible ease and expressiveness while at the same time allowing advanced features like subclassing to be used without hassle.

        use SNMP::Class;
        #create a session to a managed device -- 
        #community will default to public, version will be autoselected from 2,1
        my $s = SNMP::Class->new({DestHost => 'myhost'});    
        #modus operandi #1
        #walk the entire table
        my $ifTable = $s->walk("ifTable");
        #-more compact- 
        my $ifTable = $s->ifTable;
        #get the ifDescr.3
        my $if_descr_3 = $ifTable->object("ifDescr")->instance("3");
        #more compact
        my $if_descr_3 = $ifTable->object(ifDescr).3;
        #iterate over interface descriptions -- method senses list context and returns array
        for my $descr ($ifTable->object"ifDescr")) { 
                print $descr->get_value,"\n";
        #get the speed of the instance for which ifDescr is en0
        my $en0_speed = $ifTable->find("ifDescr","en0")->object("ifSpeed")->get_value;  
        #modus operandi #2 - list context
        while($s->ifDescr) {
                print $_->get_value;



This method creates a new session with a managed device. Argument must be a hash reference (see Class::Std for that requirement). The members of the hash reference are the same with the arguments of the new method of the SNMP module. If Version is not present, the library will try to probe by querying sysName.0 from the device using version 2 and then version 1, whichever succeeds first. This method croaks if a session cannot be created. If the managed node cannot return the sysName.0 object, the method will also croak. Most people will want to use the method as follows and let the module figure out the rest.

 my $session = SNMP::Class->new({DestHost=>'myhost.mydomain'}); 


If called, this method will permanently deactivate usage of bulkwalk for the session. Mostly useful for broken agents, some buggy versions of Net-SNMP etc.


Returns the sysname of the machine corresponding to the session


Returns the SNMP version of the session object.


A generalized walk method. Takes 1 argument, which is the object to walk. Depending on whether the session object is version 1 or 2, it will respectively try to use either SNMP GETNEXT's or GETBULK. On all cases, an SNMP::Class::ResultSet is returned. If something goes wrong, the method will croak.

One should probably also take a look at SNMP::Class::ResultSet to see what's possible.


Athanasios Douitsis, <aduitsis at>


Please report any bugs or feature requests to bug-snmp-class at, or through the web interface at I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.


You can find documentation for this module with the perldoc command.

    perldoc SNMP::Class

You can also look for information at:


This module obviously needs the perl libraries from the excellent Net-SNMP package. Many thanks go to the people that make that package available.


Copyright 2008 Athanasios Douitsis, all rights reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.