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 : syslog_cooker.cpp
11 ** VERSION NUMBER : $Revision: 1.1 $
13 ** DESCRIPTION : Cooks system log lines
18 ***************************************************************************
19 ** ADMINISTRATIVE INFORMATION *
20 ********************************
21 ** ORIGINAL AUTHOR : Arjen Baart - arjen@andromeda.nl
22 ** CREATION DATE : Aug 06, 2003
23 ** LAST UPDATE : Aug 06, 2003
25 **************************************************************************/
27 /*****************************
28 $Log: syslog_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.
35 Logrunner is integrated with gcm_input. Although its functionality
36 is still limited, a connection between logrunner and gcm_input
39 *****************************/
41 /* static const char *RCSID = "$Id: syslog_cooker.cpp,v 1.1 2003-08-11 16:56:16 arjen Exp $"; */
45 #include "syslog_cooker.h"
47 static const String syslog_date_re("[[:alpha:]]{3} [ 123][0-9] [0-9]{2}:[0-9]{2}:[0-9]{2}");
48 static const regex re_syslog(syslog_date_re + " [[:alnum:]]+ [[:alpha:]]+.*:.+");
50 bool syslog_cooker::check_pattern(String logline)
52 return logline == re_syslog;
55 bool syslog_cooker::cook_this(String logline, UTC arrival)
57 if (check_pattern(logline))
59 String datestring = logline(0,16);
60 date log_date = datestring;
61 hour log_time = datestring;
62 String rest; // Rest of the line to be parsed
65 if (log_date.Year() < 0 || log_date.Year() > 2500)
67 // The year is not in the log file. Assume the year of arrival,
68 // unless this puts the log entry at a later date than the arrival date.
69 // This happens e.g. when a log entry from December arrives in Januari.
71 log_date = date(log_date.Day(), log_date.Month(), date(arrival).Year());
72 if (log_date > date(arrival))
74 log_date = date(log_date.Day(), log_date.Month(), date(arrival).Year() - 1);
78 ts = UTC(log_date, log_time);
80 // Extract the hostname
86 // Extract the service
89 for (i = 0; isalpha(rest[i]) && i < ~rest; i++);