XTail.pm


package XSTAB::Sensor::XTail;
# This module gathers data from a log file
# $Id: XTail.pm,v 1.3 2003/03/21 02:20:48 dranok Exp $
# This module released under the GPL
# Author: DranoK
# Email: dranok@users.sourceforge.net
# Documentation: http://xstab.sourceforge.net
#################################################


NAME

XSTAB::Sensor::XTail


DESCRIPTION

This sensor simply grabs data from tail file, similar to the UNIX command ``tail -f''


INITIALIZATION

use XSTAB::XData;
use IO::File;
use IO::Select;
use strict;

my $VERSION = "0.9";


PUBLIC METHODS

create ()
Constructor which will return the blessed object. $self->{logfh} is the filehandle to the log file, and $self->{select} is the IO::Select handle for $self->{logfh} Before the blessed object is returned, the filehandle is pointed at the end of the file (SEEK_END)
sub create
{
  my $class = shift;

  my $self = { };
  $self->{logfh} = IO::File->new($Global{Tail_logfile}) or die "Cannot open $Global{Tail_logfile}: $!\n";
  $self->{select} = IO::Select->new($self->{logfh});

  $self->{logfh}->seek(0, SEEK_END);

  bless($self, $class);
  return $self;
}

do_log (string Message, int Priority)
This is the overloaded do_log function. Purpose is to identify which module is logging the message.
sub do_log
{
  my $string = shift;
  my $prio = shift;
  XSTAB::XData::do_log("Sensor::XTail: $string", $prio);
}

whoami ()
Method to identify what sensor type this is. Returns ``XTail''
sub whoami
{
  return "XTail";
}

gather_data (string CommandList)
Although ``$command_list'' is passed as an argument, we won't actually use it here. Our only purpose is to return new lines of the log.
sub gather_data
{
  my $self = shift;
  my $command_list = shift;

  my $tcr = 0;
  my $chars_read;
  my $tmpbuf;
  my $data;
  my @readers = $self->{select}->can_read(.02);
  foreach my $reader (@readers) {
    if (defined($chars_read = $reader->sysread($tmpbuf, 65507))) {
      $tcr += $chars_read;
      $data .= "tail$Global{sp}$tmpbuf$Global{sp2}";
    }
  }
  if ($tcr) {
    return $data;
  } else {
    return;
  }
}

1;


AUTHOR

This module was coded by DranoK and is part of the core XStab modules. You may directly contact DranoK at dranok@users.sourceforge.net, or by posting to the forums at:

        http://www.oltl.net/forums/forumdisplay.php?s=&forumid=25