#!/usr/bin/perl -w

use FileHandle;

my $FILEHANDLE;
my $linecount=0;
my $globalcount=0;

sub parseLine
{
  my ($line)=@_;

  my @token=split(' ',$line);
  
  if ($linecount eq 0)
  {
     print FILEHANDLE "\nHOST: ".$line;      
  }
  if ($linecount eq 1)
  {
     print FILEHANDLE "HOST IP: ".$line;      
  }
  if ($linecount eq 2)
  {
     print FILEHANDLE "SysUpTime:".$token[1];      
  }
  if ($linecount eq 3)
  {
     print FILEHANDLE " Oid:".$token[1]."\n";      
  }
  FILEHANDLE->autoflush(1);
}
sub main()
{
  open (FILEHANDLE,">>TrapReceived.txt") or die "Trap File cannot be opened";
  while (<STDIN>){
     parseLine($_); 
     if ($linecount< 4){
        $linecount++; 
     }
     else
     {
        $linecount=0; 
     }
  }
  close FILEHANDLE;
}
main();   
