1 | package PB::Log::Item;
|
---|
2 |
|
---|
3 | # Each PB::Log::Item represents one machine
|
---|
4 |
|
---|
5 | use strict;
|
---|
6 |
|
---|
7 | # the *matches represents strings, which a line must contain, to be recognized as a corresponding found
|
---|
8 | # the *exludes can be used to exclude a string (if the string contains a *match and a *exclude, the line is ignored)
|
---|
9 | # the name is by default the name of the vm (e.g. ubuntu-10.04-i386)
|
---|
10 | sub new {
|
---|
11 | # contains the object name (here PBLog)
|
---|
12 | my $object = shift;
|
---|
13 | my $vmname = shift || "";
|
---|
14 | my $log = shift || "";
|
---|
15 |
|
---|
16 | my $self = {};
|
---|
17 | # $ref should point to an object of type $object
|
---|
18 | bless($self, $object);
|
---|
19 |
|
---|
20 | # array of strings, which are indicating errors or warnings (case insensitive)
|
---|
21 | $self->{'errormatches'} = [];
|
---|
22 | $self->{'warningmatches'} = [];
|
---|
23 | # array of strings, which are excluded from error lines (case insensitive)
|
---|
24 | $self->{'errorexcludes'} = [];
|
---|
25 | $self->{'warningexcludes'} = [];
|
---|
26 |
|
---|
27 |
|
---|
28 | push(@{$self->{'errormatches'}}, "error");
|
---|
29 | push(@{$self->{'errormatches'}}, "fehler");
|
---|
30 |
|
---|
31 | push(@{$self->{'warningmatches'}}, "warning");
|
---|
32 | push(@{$self->{'warningmatches'}}, "warnung");
|
---|
33 |
|
---|
34 | # init default values
|
---|
35 | $self->setName($vmname);
|
---|
36 | $self->setLog($log);
|
---|
37 |
|
---|
38 | return($self);
|
---|
39 | }
|
---|
40 |
|
---|
41 | #set's the name
|
---|
42 | sub setName {
|
---|
43 | my $self = shift;
|
---|
44 | my $vmname = shift;
|
---|
45 | $self->{'vmname'} = $vmname;
|
---|
46 | }
|
---|
47 |
|
---|
48 | # returns the name
|
---|
49 | sub name {
|
---|
50 | my $self = shift;
|
---|
51 | return $self->{'vmname'};
|
---|
52 | }
|
---|
53 |
|
---|
54 | # set's the log and calls the analyzer (parseLog())
|
---|
55 | sub setLog {
|
---|
56 | my $self = shift;
|
---|
57 | my $log = shift;
|
---|
58 |
|
---|
59 | $self->{'qawarnings'} = [];
|
---|
60 | $self->{'qaerrors'} = [];
|
---|
61 | $self->{'warnings'} = [];
|
---|
62 | $self->{'errors'} = [];
|
---|
63 | $self->{'log'} = $log;
|
---|
64 | $self->parseLog;
|
---|
65 | }
|
---|
66 |
|
---|
67 | # returns the "raw" log text
|
---|
68 | sub log {
|
---|
69 | my $self = shift;
|
---|
70 | return $self->{'log'};
|
---|
71 | }
|
---|
72 |
|
---|
73 | # returns the number of warnings and errors reported by lintian or rpmlint
|
---|
74 | sub numQaIssues {
|
---|
75 | my $self = shift;
|
---|
76 | return scalar($self->qaIssues);
|
---|
77 | }
|
---|
78 |
|
---|
79 | # returns the issues itself
|
---|
80 | sub qaIssues {
|
---|
81 | my $self = shift;
|
---|
82 | my @result = $self->qaErrors;
|
---|
83 | push(@result, $self->qaWarnings);
|
---|
84 | return @result;
|
---|
85 | }
|
---|
86 |
|
---|
87 | #returns only the warnings
|
---|
88 | sub qaWarnings {
|
---|
89 | my $self = shift;
|
---|
90 | return @{$self->{'qawarnings'}};
|
---|
91 | }
|
---|
92 |
|
---|
93 | # returns only the errors
|
---|
94 | sub qaErrors {
|
---|
95 | my $self = shift;
|
---|
96 | return @{$self->{'qaerrors'}};
|
---|
97 | }
|
---|
98 |
|
---|
99 | # returns the number of compile errors
|
---|
100 | # or better, all other than lintian and rpmlint
|
---|
101 | sub numErrors {
|
---|
102 | my $self = shift;
|
---|
103 | return scalar($self->errors);
|
---|
104 | }
|
---|
105 |
|
---|
106 | # returns the errors itself
|
---|
107 | sub errors {
|
---|
108 | my $self = shift;
|
---|
109 | return @{$self->{'errors'}};
|
---|
110 | }
|
---|
111 |
|
---|
112 | # same for warnings
|
---|
113 | sub numWarnings {
|
---|
114 | my $self = shift;
|
---|
115 | return scalar($self->warnings);
|
---|
116 | }
|
---|
117 |
|
---|
118 | # same for warnings
|
---|
119 | sub warnings {
|
---|
120 | my $self = shift;
|
---|
121 | return @{$self->{'warnings'}};
|
---|
122 | }
|
---|
123 |
|
---|
124 | # private part
|
---|
125 |
|
---|
126 | # parses the log
|
---|
127 | sub parseLog {
|
---|
128 | my $self = shift;
|
---|
129 |
|
---|
130 | my @lines = split("\n", $self->{'log'});
|
---|
131 | foreach my $line (@lines){
|
---|
132 | # check for lintian or rpmlint errors
|
---|
133 | if($line =~ m/^W:/){
|
---|
134 | push(@{$self->{'qawarnings'}}, $line);
|
---|
135 | }
|
---|
136 | elsif($line =~ m/^E:/){
|
---|
137 | push(@{$self->{'qaerrors'}}, $line);
|
---|
138 | }
|
---|
139 | else{
|
---|
140 | # error detect
|
---|
141 | my $iserror = 0;
|
---|
142 | foreach my $errormatch (@{$self->{'errormatches'}}){
|
---|
143 | if($line =~ m/$errormatch/){
|
---|
144 | # check wether an exclude is also true
|
---|
145 | my $isexcluded = 0;
|
---|
146 | foreach my $exclude (@{$self->{'errorexcludes'}}){
|
---|
147 | if($line =~ m/$exclude/){
|
---|
148 | $isexcluded = 1;
|
---|
149 | last;
|
---|
150 | }
|
---|
151 | }
|
---|
152 | if($isexcluded == 0){
|
---|
153 | # it is an error and not excluded, so add it to array
|
---|
154 | push(@{$self->{'errors'}}, $line);
|
---|
155 | $iserror = 1;
|
---|
156 | last;
|
---|
157 | }
|
---|
158 | }
|
---|
159 | }
|
---|
160 |
|
---|
161 | # warning detect
|
---|
162 | if($iserror == 0){
|
---|
163 | foreach my $match (@{$self->{'warningmatches'}}){
|
---|
164 | if($line =~ m/$match/){
|
---|
165 | # check wether an exclude is also true
|
---|
166 | my $isexcluded = 0;
|
---|
167 | foreach my $exclude (@{$self->{'warningexcludes'}}){
|
---|
168 | if($line =~ m/$exclude/){
|
---|
169 | $isexcluded = 1;
|
---|
170 | last;
|
---|
171 | }
|
---|
172 | }
|
---|
173 | if($isexcluded == 0){
|
---|
174 | # it is an error and not excluded, so add it to array
|
---|
175 | push(@{$self->{'warnings'}}, $line);
|
---|
176 | $iserror = 1;
|
---|
177 | last;
|
---|
178 | }
|
---|
179 | }
|
---|
180 | }
|
---|
181 | }
|
---|
182 | }
|
---|
183 | }
|
---|
184 | }
|
---|
185 |
|
---|
186 | 1;
|
---|