| SNMP-LogParser documentation | Contained in the SNMP-LogParser distribution. |
SNMP::LogParserDriver::ExampleDriver
This is an example Driver class to check for strings in the log file of the form "test string". Every time that this string is found the variable "counter" is incremented.
Here we show each of the functions
New is just a passthrough to the parent class
sub new {
my $class = shift;
my $self = $class->SUPER::new();
bless ($self, $class);
return $self;
}
Here we initialize the "counter" variable. We declare it in the "savespace" hash so that it is persistent across run invocations of logparser
sub evalBegin {
my $self = shift;
$self->{savespace}{counter} = 0 if (!defined($self->{savespace}{counter}));
$self->{savespace}{lines} = 0 if (!defined($self->{savespace}{counter}));
}
Here we parse each line, incrementing the counter value if it matches the string (we also keep track of lines)
sub evalIterate {
my $self = shift;
my ($line) = @_;
$self->{savespace}{lines} ++;
if ($line =~ /test string/g) {
$self->{savespace}{counter} ++;
}
}
Here we tell the system that we want to output on the properties file all the variables in the save space...
sub evalEnd {
my $self = shift;
$self->properties($self->savespace);
}
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.
| SNMP-LogParser documentation | Contained in the SNMP-LogParser distribution. |
# # $Id: ProxyLog.pm,v 1.1 2006/09/11 07:35:31 nito Exp $ # # A bit more complicated class # # Nito@Qindel.ES -- 7/9/2006 package SNMP::LogParserDriver::ExampleDriver; use SNMP::LogParserDriver; @SNMP::LogParserDriver::ExampleDriver::ISA = ('SNMP::LogParserDriver');
sub new { my $class = shift; my $self = $class->SUPER::new(); bless ($self, $class); return $self; }
# This will be invoked before the first parsing of the log sub evalBegin { my $self = shift; $self->{savespace}{counter} = 0 if (!defined($self->{savespace}{counter})); $self->{savespace}{lines} = 0 if (!defined($self->{savespace}{lines})); }
sub evalIterate { my $self = shift; my ($line) = @_; $self->{savespace}{lines} ++; if ($line =~ /test string/g) { $self->{savespace}{counter} ++; } }
sub evalEnd { my $self = shift; $self->properties($self->savespace); } 1;