~ubuntu-branches/ubuntu/trusty/drizzle/trusty

« back to all changes in this revision

Viewing changes to tests/randgen/lib/GenTest/Reporter/ErrorLogAlarm.pm

  • Committer: Package Import Robot
  • Author(s): Dmitrijs Ledkovs
  • Date: 2013-10-29 15:43:40 UTC
  • mfrom: (1.2.12) (2.1.19 trusty-proposed)
  • Revision ID: package-import@ubuntu.com-20131029154340-2gp39el6cv8bwf2o
Tags: 1:7.2.3-2ubuntu1
* Merge from debian, remaining changes:
  - Link against boost_system because of boost_thread.
  - Add required libs to message/include.am
  - Add upstart job and adjust init script to be upstart compatible.
  - Disable -floop-parallelize-all due to gcc-4.8/4.9 compiler ICE
    http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57732

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (c) 2011 Oracle and/or its affiliates. All rights reserved.
2
 
# Use is subject to license terms.
3
 
#
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.
7
 
#
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.
12
 
#
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
16
 
# USA
17
 
 
18
 
package GenTest::Reporter::ErrorLogAlarm;
19
 
 
20
 
require Exporter;
21
 
@ISA = qw(GenTest::Reporter);
22
 
 
23
 
use strict;
24
 
use GenTest;
25
 
use GenTest::Reporter;
26
 
use GenTest::Constants;
27
 
 
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.
30
 
 
31
 
sub monitor {
32
 
 
33
 
    my $reporter = shift;
34
 
 
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!");
40
 
            return STATUS_OK;
41
 
        } else {
42
 
            # INFO
43
 
            say("ErrorLogAlarm Reporter will monitor the log file ".$errorlog);
44
 
        }
45
 
    }
46
 
 
47
 
    if ((-e $errorlog) && (-s $errorlog > 0)) {
48
 
        open(LOG, $errorlog);
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:");
53
 
                print($line);
54
 
                close LOG;
55
 
                return STATUS_ALARM;
56
 
            }
57
 
        }
58
 
        close LOG;
59
 
 
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;
65
 
        #}
66
 
 
67
 
    }
68
 
    return STATUS_OK;
69
 
}
70
 
 
71
 
 
72
 
sub report {
73
 
    my $reporter = shift;
74
 
    my $logfile = $reporter->serverInfo('errorlog');
75
 
    my $description = 
76
 
        'ErrorLogAlarm Reporter raised an alarm. Found pattern \''.$pattern.
77
 
        '\' in error log file '.$logfile;
78
 
    
79
 
    my $incident = GenTest::Incident->new(
80
 
        timestamp => isoTimestamp(),
81
 
        result    => 'fail',
82
 
        description => $description
83
 
        # TODO: Add matched line as signature?
84
 
    );
85
 
 
86
 
    return STATUS_OK, $incident;
87
 
}
88
 
 
89
 
 
90
 
sub type {
91
 
    return REPORTER_TYPE_PERIODIC | REPORTER_TYPE_ALWAYS;
92
 
}
93
 
 
94
 
1;