package Monitor::snmp_trap;

require 5.001;

use strict;
use vars qw(@ISA @EXPORT $VERSION);
use Monitor::logfile;

@ISA = qw(Monitor::logfile);


sub create {
    ;
}



sub defaults {
    my( $self ) = @_;

    $self->{"defaultitem"} = "trap";
}


sub seek {
    my( $self, $pos, $whence ) = @_;

    $self->{"_buffer"} = "";
    return( seek( $self->{"fh"}, $pos, $whence ) );
}



sub readline {
    my( $self ) = @_;

    my $fh = $self->{"fh"};
    my $data = $self->{"_buffer"};
    while( <$fh> ) {
	if( /^[\r\n]+$/ ) {
	    $self->{"_buffer"} = "";
	    return $data;
	}
	$data .= $_;
    }
    $self->{"_buffer"} = $data;
    return undef;
}



sub decode {
    my( $self, $line ) = @_;
    my( $readline );

    print "snmp_trap: decodeing ".$line."\n" if( $BigSister::common::dl>7 );
    unless( $line =~ /^(\d+) trap from ([^\s]+)/ ) {
	return();
    }
    my $timestamp = $1;
    my $source = $2;
    $line = $';
    if( $line =~ /^agent=([^\r\n]+)/ ) {
	$source = $1;
    }
    return( $timestamp, $line, $source );
}

1;
