The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

SNMP:LogParserDriver

SYNOPSIS

This is base class for the usage of the logparser parsing. Usually you will implement a subclass of this class implementing the following methods:

  • new

    You can define whatever new parameters you want in this method, but usually only the object variable pattern (the regular expression to match in the file) is needed

  • evalBegin

    This is an extract of code which initializes all the variables that you might need during the run of logparser

  • evalIterate

    This method will be invoked for each line of the log file.

  • evalEnd

    This method usually records in the properties hash reference the key, value pairs that you want ot record in the output.

DESCRIPTION

For a more detailed description on how to use this class please check logparser.

This document is a detailed reference of the different methods provided in this class

METHODS

new

Receives (at the moment) no arguments. It creates an object of SNMP::LogParserDriver

name

Permits to retrieve or set the name of the object as in

 print "name: ".$self->name;

or

 $self->name("myname");

logfile

Permits to retrieve or set the logfile of the object as in

 print "logfile: ".$self->logfile;

or

 $self->logfile("/var/log/logfile");

pattern

Permits to retrieve or set the regular expression pattern of the object as in

 print "pattern: ".$self->pattern;

or

 $self->pattern("^myregex$");

savespace

Permits to retrieve or set the savespace of the object as in

 print "savespace: ".Dumper($self->savespace);

or

 $self->savespace(\%mysavespace);

The savespace is usually a reference to a hash file. The value of the savespace variable will be restored in the beginning of each invocation of logparser and saved at the end of the invocation. Tipically things like counters are saved in each invocation of the savespace.

workspace

Permits to retrieve or set a variable that will be maintained across iterative parsings of the log, but will not be maintained across logparser invocations

 print "workspace: ".Dumper($self->workspace);

or

 $self->workspace(\%workspace);

The workpace is usually a reference to a hash file. The value of the workspace variable will only last for each invocation of logparser. Tipically things like local variable are saved in in the workspace.

properties

Permits to retrieve or set the properties of the object as in

 print "properties: ".$self->properties;

or

 $self->properties(\%myproperties);

The properties of an object are the key/value pairs that will be stored in the propertiesFile of the logparser.conf file.

logger

Permits to retrieve or set the logger of the object as in

 print $self->logger->debug("debug message");

or

 $logger = Log::Log4perl->get_logger(LOG_TAG);
 $self->logger($logger);

evalBegin

This method is usually overriden in the child class. This method will be invoked before any line of the file is parsed.

Typically counters will be initialised here if they have not been initialised before:

  $self->{savespace}{counter} = 0 if (!exists($self->{savespace}{counter}));

evalIterate

This method is usually overriden in the child class. This method will be invoked for each line of the log that should be parsed.

It receives as an argument the line of the log to be parsed.

One typical implementation could be:

 sub evalIterate {
  my $self = shift;
  my ($line) = @_;
  my $pattern = $self->{pattern};
  if ($line =~ /$pattern/) {
    $self->{savespace}{counter} ++;
  }
 }

evalEnd

This method is usually overriden in the child class. This method will be invoked after all the lines have been parsed.

Typically the properties elements will be initialised here

REQUIREMENTS AND LIMITATIONS

BUGS

TODO

  • document logger.

SEE ALSO

AUTHOR

Nito at Qindel dot ES -- 7/9/2006

COPYRIGHT & LICENSE

Copyright 2007 by Qindel Formacion y Servicios SL, all rights reserved.

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