Help-Site Computer Manuals
Software
Hardware
Programming
Networking
  Algorithms & Data Structures   Programming Languages   Revision Control
  Protocols
  Cameras   Computers   Displays   Keyboards & Mice   Motherboards   Networking   Printers & Scanners   Storage
  Windows   Linux & Unix   Mac

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

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


NAME

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


SYNOPSIS

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;

        }

 

   

=head1 METHODS

new({DestHost=>$desthost,Community=>$community,Version=>$version,DestPort=>$port})

This method creates a new session with a managed device. At this point Version can only be 1 or 2. 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.

deactivate_bulkwalks

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. =cut

sub deactivate_bulkwalks { my $self = shift(@_) or croak ``deactivate_bulkwalks called outside of an object context''; my $id = ident $self; $deactivate_bulkwalks{$id} = 1 ; return; }

sub getOid :RESTRICTED() {




        my $self = shift(@_) or croak "getvar called outside of an object context";

        my $oid = shift(@_) or croak "first arg to getvar (oid), missing";

        my $instance = shift(@_); #instance could be 0, so we do not check

        if (!defined($instance)) { confess "second arg to getvar (instance), missing" }

        my $id = ident $self;

        my $vars = new SNMP::VarList([$oid,$instance]) or confess "Internal Error: Could not create a new SNMP::VarList for $oid.$instance";

        my @a = $session{$id}->get($vars);

        ###print Dumper(@a);

        croak $session{$id}->{ErrorStr} if ($session{$id}->{ErrorNum} != 0);

        croak "Got error when tried to ask $session{$id}->{DestHost} for $oid.$instance" if ($a[0] eq "NOSUCHINSTANCE");

        return $a[0];

}

getVersion

Returns the SNMP version of the session object.

walk

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 the SNMP::Class::ResultSet manpage pod to see what's possible.

AUTOMETHOD

Using a method call that coincides with an SNMP OBJECT-TYPE name is equivalent to issuing a walk with that name as argument. This is provided as a shortcut which can result to more easy to read programs. Also, if such a method is used in a list context, it won't return an SNMP::ResultSet object, but rather a list with the ResultSet's contents. This is pretty convenient for iterating through SNMP results using few lines of code.


AUTHOR

Athanasios Douitsis, <aduitsis at cpan.org>


BUGS

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


SUPPORT

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


    perldoc SNMP::Class

You can also look for information at:


ACKNOWLEDGEMENTS

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 & LICENSE

Copyright 2007 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.

Programminig
Wy
Wy
yW
Wy
Programming
Wy
Wy
Wy
Wy