When extracting the service name for a log entry, the '/' character
[gnucomo.git] / src / gcm_input / irix_syslog_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      : irix_syslog_cooker.cpp
10 **      SYSTEM NAME    : 
11 **      VERSION NUMBER : $Revision: 1.4 $
12 **
13 **  DESCRIPTION      :  Cooks IRIX system 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 09, 2003
23 **      LAST UPDATE     : Aug 09, 2003
24 **      MODIFICATIONS   : 
25 **************************************************************************/
26
27 /*****************************
28    $Log: irix_syslog_cooker.cpp,v $
29    Revision 1.4  2007-10-19 07:22:12  arjen
30    When extracting the service name for a log entry, the '/' character
31    is not considered part of that name.
32
33    Revision 1.3  2007/01/11 13:51:40  arjen
34    The '-' character is part of the service name.
35
36    Revision 1.2  2004/01/13 12:20:13  arjen
37    Accept '/' and '.' characters within the service name
38
39    Revision 1.1  2003/08/11 16:56:16  arjen
40    Different kinds of log files are parsed by a collection of objects
41    of different classes, derived from the base class line_cooker
42    Depending on the message content or the message_type element in
43    XML, one of these objects is selected.
44
45    Logrunner is integrated with gcm_input. Although its functionality
46    is still limited, a connection between logrunner and gcm_input
47    is beginning to form.
48
49 *****************************/
50
51 /* static const char *RCSID = "$Id: irix_syslog_cooker.cpp,v 1.4 2007-10-19 07:22:12 arjen Exp $"; */
52
53 #include <ctype.h>
54
55 #include "irix_syslog_cooker.h"
56
57 static const String syslog_date_re("[[:alpha:]]{3} [ 123][0-9] [0-9]{2}:[0-9]{2}:[0-9]{2}");
58 static const regex re_syslog_irix(syslog_date_re + " [0-7][A-T]:[[:alnum:]]+ [[:alpha:]/]+.*:.+");
59
60 bool irix_syslog_cooker::check_pattern(String logline)
61 {
62    return logline == re_syslog_irix;
63 }
64
65 bool irix_syslog_cooker::cook_this(String logline, UTC arrival)
66 {
67    if (check_pattern(logline))
68    {
69       String datestring = logline(0,16);
70       date   log_date = datestring;
71       hour   log_time = datestring;
72       String rest;   //  Rest of the line to be parsed
73       int    i;
74
75       if (log_date.Year() < 0 || log_date.Year() > 2500)
76       {
77          //  The year is not in the log file. Assume the year of arrival,
78          //  unless this puts the log entry at a later date than the arrival date.
79          //  This happens e.g. when a log entry from December arrives in Januari.
80
81          log_date = date(log_date.Day(), log_date.Month(), date(arrival).Year());
82          if (log_date > date(arrival))
83          {
84             log_date = date(log_date.Day(), log_date.Month(), date(arrival).Year() - 1);
85          }
86       }
87
88       ts = UTC(log_date, log_time);
89
90       //  Extract the hostname
91  
92       rest = logline << 19;
93       i = rest.index(' ');
94       hn = rest(0,i);
95
96       //  Extract the service
97
98       rest <<= i + 1;
99       for (i = 0; (isalpha(rest[i])  || rest[i] == '.' || rest[i] == '-') && i < ~rest; i++);
100       srv = rest(0, i);
101
102       return true;
103    }
104    else
105    {
106       return false;
107    }
108 }
109
110