Accept a wider range of input patterns
[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.2 $
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.2  2003-12-22 10:22:22  arjen
30    Accept a wider range of input patterns
31
32    Revision 1.1  2003/08/11 16:56:16  arjen
33    Different kinds of log files are parsed by a collection of objects
34    of different classes, derived from the base class line_cooker
35    Depending on the message content or the message_type element in
36    XML, one of these objects is selected.
37
38    Logrunner is integrated with gcm_input. Although its functionality
39    is still limited, a connection between logrunner and gcm_input
40    is beginning to form.
41
42 *****************************/
43
44 /* static const char *RCSID = "$Id: error_cooker.cpp,v 1.2 2003-12-22 10:22:22 arjen Exp $"; */
45
46 #include <ctype.h>
47
48 #include "error_cooker.h"
49
50 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}");
51 static const regex re_errorlog("^\\[" + unix_date_re + "\\] \\[(error|notice|warn)\\] .+");
52
53 bool error_cooker::check_pattern(String logline)
54 {
55    return logline == re_errorlog;
56 }
57
58 bool error_cooker::cook_this(String logline, UTC arrival)
59 {
60    if (check_pattern(logline))
61    {
62       String datestring = logline(regex("\\[.+\\]"));
63
64       datestring <<= 1;
65       datestring >>= 1;
66
67       date   log_date = datestring;
68       hour   log_time = datestring;
69
70       log_date = datestring;
71       log_time = datestring;
72
73       ts = UTC(log_date, log_time);
74
75       hn  = "";
76       srv = "httpd";
77
78       return true;
79    }
80    else
81    {
82       return false;
83    }
84 }
85
86