line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# |
2
|
|
|
|
|
|
|
# $Id: ExampleDriver.pm 14990 2012-04-10 12:57:24Z rporres $ |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# A bit more complicated class |
5
|
|
|
|
|
|
|
# |
6
|
|
|
|
|
|
|
# Nito@Qindel.ES -- 7/9/2006 |
7
|
|
|
|
|
|
|
package SNMP::LogParserDriver::ExampleDriver; |
8
|
1
|
|
|
1
|
|
3552
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
24
|
|
9
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
25
|
|
10
|
1
|
|
|
1
|
|
812
|
use parent 'SNMP::LogParserDriver'; |
|
1
|
|
|
|
|
289
|
|
|
1
|
|
|
|
|
6
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 NAME |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
SNMP::LogParserDriver::ExampleDriver |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 SYNOPSIS |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
This is an example Driver class to check for strings in the log file |
19
|
|
|
|
|
|
|
of the form "test string". Every time that this string is found |
20
|
|
|
|
|
|
|
the variable "counter" is incremented. |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=head1 DESCRIPTION |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
Here we show each of the functions |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=head2 new |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
New is just a passthrough to the parent class |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub new { |
32
|
|
|
|
|
|
|
my $class = shift; |
33
|
|
|
|
|
|
|
my $self = $class->SUPER::new(); |
34
|
|
|
|
|
|
|
bless ($self, $class); |
35
|
|
|
|
|
|
|
return $self; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=cut |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub new { |
41
|
0
|
|
|
0
|
1
|
|
my $class = shift; |
42
|
0
|
|
|
|
|
|
my $self = $class->SUPER::new(); |
43
|
0
|
|
|
|
|
|
bless ($self, $class); |
44
|
0
|
|
|
|
|
|
return $self; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=head2 evalBegin |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
Here we initialize the "counter" variable. We declare it in the |
51
|
|
|
|
|
|
|
"savespace" hash so that it is persistent across run invocations |
52
|
|
|
|
|
|
|
of logparser |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub evalBegin { |
55
|
|
|
|
|
|
|
my $self = shift; |
56
|
|
|
|
|
|
|
$self->{savespace}{counter} = 0 if (!defined($self->{savespace}{counter})); |
57
|
|
|
|
|
|
|
$self->{savespace}{lines} = 0 if (!defined($self->{savespace}{counter})); |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=cut |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
# This will be invoked before the first parsing of the log |
63
|
|
|
|
|
|
|
sub evalBegin { |
64
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
65
|
|
|
|
|
|
|
|
66
|
0
|
0
|
|
|
|
|
$self->{savespace}{counter} = 0 if (!defined($self->{savespace}{counter})); |
67
|
0
|
0
|
|
|
|
|
$self->{savespace}{lines} = 0 if (!defined($self->{savespace}{lines})); |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=head2 evalIterate |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
Here we parse each line, incrementing the counter value if it matches the |
73
|
|
|
|
|
|
|
string (we also keep track of lines) |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub evalIterate { |
76
|
|
|
|
|
|
|
my $self = shift; |
77
|
|
|
|
|
|
|
my ($line) = @_; |
78
|
|
|
|
|
|
|
$self->{savespace}{lines} ++; |
79
|
|
|
|
|
|
|
if ($line =~ /test string/g) { |
80
|
|
|
|
|
|
|
$self->{savespace}{counter} ++; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=cut |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub evalIterate { |
87
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
88
|
0
|
|
|
|
|
|
my ($line) = @_; |
89
|
0
|
|
|
|
|
|
$self->{savespace}{lines} ++; |
90
|
0
|
0
|
|
|
|
|
if ($line =~ /test string/g) { |
91
|
0
|
|
|
|
|
|
$self->{savespace}{counter} ++; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head2 evalEnd |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
Here we tell the system that we want to output on the properties file |
98
|
|
|
|
|
|
|
all the variables in the save space... |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub evalEnd { |
101
|
|
|
|
|
|
|
my $self = shift; |
102
|
|
|
|
|
|
|
$self->properties($self->savespace); |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=cut |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub evalEnd { |
108
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
109
|
0
|
|
|
|
|
|
$self->properties($self->savespace); |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
1; |
113
|
|
|
|
|
|
|
=head1 REQUIREMENTS AND LIMITATIONS |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=head1 OPTIONS |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=head1 BUGS |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=head1 TODO |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=over 8 |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=item * document logger. |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=back |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=head1 SEE ALSO |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=head1 AUTHOR |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
Nito at Qindel dot ES -- 7/9/2006 |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
Copyright 2007 by Qindel Formacion y Servicios SL, all rights reserved. |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
138
|
|
|
|
|
|
|
under the same terms as Perl itself. |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=cut |