package Xymon::Monitor::SNMP;
use Net::SNMP;

use Xymon::Client;
use strict;


BEGIN {
    use Exporter ();
    use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
    $VERSION     = '0.01';
    @ISA         = qw(Exporter);
    #Give a hoot don't pollute, do not export more than needed by default
    @EXPORT      = qw();
    @EXPORT_OK   = qw();
    %EXPORT_TAGS = ();
}


#################### subroutine header begin ####################

=head2 sample_function

 Usage     : How to use this function/method
 Purpose   : What it does
 Returns   : What it returns
 Argument  : What it wants to know
 Throws    : Exceptions and other anomolies
 Comment   : This is a sample subroutine header.
           : It is polite to include more pod and fewer comments.

See Also   : 

=cut

#################### subroutine header end ####################


sub new
{
    my ($class, $parm) = @_;

    my $self = bless ({}, ref ($class) || $class);
	
	$parm->{version} = $parm->{version} || "2c";
	
	($self->{session}, my $error) = Net::SNMP->session(
                           -hostname      => $parm->{hostname},
                           -version       => $parm->{version},
                           -community     => $parm->{community},   # v1/v2c
                        );
	
	
	$self->{parm} = $parm;
	$self->{OIDS} = $parm->{OIDS};

    return $self;
}

sub getValues {
	
	my $self = shift;
	
	foreach my $key ( sort keys %{$self->{OIDS}} ) {
		
	
		my $result = $self->{session}->get_request(-varbindlist => [$self->{OIDS}->{$key}]);

		if (!defined $result) {
	      	printf "ERROR: %s.\n", $self->{session}->error();
    	  	$self->{session}->close();
			exit 1;
   		}

		printf "%s:%s is %s.\n",
          $self->{parm}->{hostname},$key, $result->{$self->{OIDS}->{$key}};
		
		
	}
	
		
}

sub close {
	
	my $self = shift;
	$self->{session}->close();
	$self = "";
	
}
#################### main pod documentation begin ###################
## Below is the stub of documentation for your module. 
## You better edit it!


=head1 NAME

Xymon::SNMP - Xymon Interface to SNMP

=head1 SYNOPSIS

  use Xymon::SNMP;
  blah blah blah


=head1 DESCRIPTION

Stub documentation for this module was created by ExtUtils::ModuleMaker.
It looks like the author of the extension was negligent enough
to leave the stub unedited.

Blah blah blah.


=head1 USAGE



=head1 BUGS



=head1 SUPPORT



=head1 AUTHOR

    David Peters
    CPAN ID: DAVIDP
    davidp@electronf.com
    http://www.electronf.com

=head1 COPYRIGHT

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

The full text of the license can be found in the
LICENSE file included with this module.


=head1 SEE ALSO

perl(1).

=cut

#################### main pod documentation end ###################


1;
# The preceding line will help the module return a true value

