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