1
# Copyright (c) 2011 Oracle and/or its affiliates. All rights reserved.
2
# Use is subject to license terms.
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; version 2 of the License.
8
# This program is distributed in the hope that it will be useful, but
9
# WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
# General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
18
package GenTest::Reporter::ErrorLogAlarm;
21
@ISA = qw(GenTest::Reporter);
25
use GenTest::Reporter;
26
use GenTest::Constants;
28
my $pattern = "^ERROR"; # Modify this to look for other patterns in the error log
29
my $errorlog; # Path to error log. Is assigned first time monitor() is called.
35
if (not defined $errorlog) {
36
$errorlog = $reporter->serverInfo('errorlog');
37
if ($errorlog eq '') {
38
# Error log was not found. Report the issue and continue.
39
say("WARNING: Error log not found! ErrorLogAlarm Reporter does not work as intended!");
43
say("ErrorLogAlarm Reporter will monitor the log file ".$errorlog);
47
if ((-e $errorlog) && (-s $errorlog > 0)) {
49
while(my $line = <LOG>) {
50
if($line =~ m{$pattern}) {
51
say("ALARM from ErrorLogAlarm reporter: Pattern '$pattern' was".
52
" found in error log. Matching line was:");
60
## Alternative, non-portable implementation:
61
#my $grepresult = system('grep '.$pattern.' '.$errorlog.' > /dev/null 2>&1');
62
#if ($grepresult == 0) {
63
# say("ALARM $pattern found in error log file.");
64
# return STATUS_ALARM;
74
my $logfile = $reporter->serverInfo('errorlog');
76
'ErrorLogAlarm Reporter raised an alarm. Found pattern \''.$pattern.
77
'\' in error log file '.$logfile;
79
my $incident = GenTest::Incident->new(
80
timestamp => isoTimestamp(),
82
description => $description
83
# TODO: Add matched line as signature?
86
return STATUS_OK, $incident;
91
return REPORTER_TYPE_PERIODIC | REPORTER_TYPE_ALWAYS;