Different kinds of log files are parsed by a collection of objects
[gnucomo.git] / src / gcm_input / error_cooker.cpp
1
2 /**************************************************************************
3 **  (c) Copyright 2002, Andromeda Technology & Automation
4 ** This is free software; you can redistribute it and/or modify it under the
5 ** terms of the GNU General Public License, see the file COPYING.
6 ***************************************************************************
7 ** MODULE INFORMATION *
8 ***********************
9 **      FILE NAME      : error_cooker.cpp
10 **      SYSTEM NAME    : 
11 **      VERSION NUMBER : $Revision: 1.1 $
12 **
13 **  DESCRIPTION      :  Cooks Apache http daemon error log lines
14 **
15 **  EXPORTED OBJECTS : 
16 **  LOCAL    OBJECTS : 
17 **  MODULES  USED    :
18 ***************************************************************************
19 **  ADMINISTRATIVE INFORMATION *
20 ********************************
21 **      ORIGINAL AUTHOR : Arjen Baart - arjen@andromeda.nl
22 **      CREATION DATE   : Aug 11, 2003
23 **      LAST UPDATE     : Aug 11, 2003
24 **      MODIFICATIONS   : 
25 **************************************************************************/
26
27 /*****************************
28    $Log: error_cooker.cpp,v $
29    Revision 1.1  2003-08-11 16:56:16  arjen
30    Different kinds of log files are parsed by a collection of objects
31    of different classes, derived from the base class line_cooker
32    Depending on the message content or the message_type element in
33    XML, one of these objects is selected.
34
35    Logrunner is integrated with gcm_input. Although its functionality
36    is still limited, a connection between logrunner and gcm_input
37    is beginning to form.
38
39 *****************************/
40
41 /* static const char *RCSID = "$Id: error_cooker.cpp,v 1.1 2003-08-11 16:56:16 arjen Exp $"; */
42
43 #include <ctype.h>
44
45 #include "error_cooker.h"
46
47 static const String unix_date_re("[[:alpha:]]{3} [[:alpha:]]{3} [ 123][0-9] [0-9]{2}:[0-9]{2}:[0-9]{2} [0-9]{4}");
48 static const regex re_errorlog("^\\[" + unix_date_re + "\\] \\[(error|notice)\\] .+");
49
50 bool error_cooker::check_pattern(String logline)
51 {
52    return logline == re_errorlog;
53 }
54
55 bool error_cooker::cook_this(String logline, UTC arrival)
56 {
57    if (check_pattern(logline))
58    {
59       String datestring = logline(regex("\\[.+\\]"));
60
61       datestring <<= 1;
62       datestring >>= 1;
63
64       date   log_date = datestring;
65       hour   log_time = datestring;
66
67       log_date = datestring;
68       log_time = datestring;
69
70       ts = UTC(log_date, log_time);
71
72       hn  = "";
73       srv = "httpd";
74
75       return true;
76    }
77    else
78    {
79       return false;
80    }
81 }
82
83