SNMP:LogParserDriver
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.
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
Receives (at the moment) no arguments. It creates an object of SNMP::LogParserDriver
Permits to retrieve or set the name of the object as in
print "name: ".$self->name;
or
$self->name("myname");
Permits to retrieve or set the logfile of the object as in
print "logfile: ".$self->logfile;
$self->logfile("/var/log/logfile");
Permits to retrieve or set the regular expression pattern of the object as in
print "pattern: ".$self->pattern;
$self->pattern("^myregex$");
Permits to retrieve or set the savespace of the object as in
print "savespace: ".Dumper($self->savespace);
$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.
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);
$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.
Permits to retrieve or set the properties of the object as in
print "properties: ".$self->properties;
$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.
Permits to retrieve or set the logger of the object as in
print $self->logger->debug("debug message");
$logger = Log::Log4perl->get_logger(LOG_TAG); $self->logger($logger);
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}));
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} ++; } }
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
document logger.
Nito at Qindel dot ES -- 7/9/2006
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.
To install SNMP::LogParser, copy and paste the appropriate command in to your terminal.
cpanm
cpanm SNMP::LogParser
CPAN shell
perl -MCPAN -e shell install SNMP::LogParser
For more information on module installation, please visit the detailed CPAN module installation guide.