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); }
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.