Major redesign. All input is handled through XML. Raw input data is first
[gnucomo.git] / src / gcm_input / message.h
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      : message.h
10 **      SYSTEM NAME    : 
11 **      VERSION NUMBER : $Revision: 1.8 $
12 **
13 **  DESCRIPTION      :  Classes to for handling client messages
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   : Sep 16, 2002
23 **      LAST UPDATE     : Aug 06, 2003
24 **      MODIFICATIONS   : 
25 **************************************************************************/
26
27 /*****************************
28    $Log: message.h,v $
29    Revision 1.8  2003-12-04 10:38:09  arjen
30    Major redesign. All input is handled through XML. Raw input data is first
31    transformed into an XML document for further processing.
32    A collection of polymorphic classes handle the transformation of various
33    input formats into XML.
34    Classifying input data is done with a finite improbability calculation.
35
36    Revision 1.7  2003/08/11 16:56:16  arjen
37    Different kinds of log files are parsed by a collection of objects
38    of different classes, derived from the base class line_cooker
39    Depending on the message content or the message_type element in
40    XML, one of these objects is selected.
41
42    Logrunner is integrated with gcm_input. Although its functionality
43    is still limited, a connection between logrunner and gcm_input
44    is beginning to form.
45
46    Revision 1.6  2003/04/29 09:16:44  arjen
47    Read XML input,
48    Only cooked log entries for now.
49
50    Revision 1.5  2003/03/16 09:42:40  arjen
51    Read IRIX system logs.
52
53    Revision 1.4  2002/12/06 22:26:28  arjen
54    Set the value of log.processed to FALSE when inserting a
55    new log entry into the database
56    When a syslog entry arrives from last year, gcm_input subtracts one from the
57    year of arrival to create the year of the log entry.
58    Read output from "rpm -qa" and enter packages in the parameter table.
59
60    Revision 1.3  2002/11/09 08:04:27  arjen
61    Added a reference to the GPL
62
63    Revision 1.2  2002/11/04 10:13:36  arjen
64    Use proper namespace for iostream classes
65
66    Revision 1.1  2002/10/05 10:25:49  arjen
67    Creation of gcm_input and a first approach to a web interface
68
69 *****************************/
70
71 /* static const char *RCSID = "$Id: message.h,v 1.8 2003-12-04 10:38:09 arjen Exp $"; */
72
73 #include <iostream>
74 #include <list>
75 #include <AXE/String.h>
76 #include <AXE/date.h>
77
78 #include <libxml/parser.h>
79
80 #include "message_filter.h"
81 #include "line_cooker.h"
82 #include "database.h"
83
84 //  Associates line cookers and message filters
85
86 struct xform
87 {
88    message_filter    *mf;
89    line_cooker       *lc;
90    double            uncertainty;
91
92    xform()
93    {
94       mf = NULL;
95       lc = NULL;
96       uncertainty = 1.0;
97    }
98
99    xform(message_filter *m, line_cooker *l)
100    {
101       mf = m;
102       lc = l;
103       uncertainty = 1.0;
104    }
105 };
106
107 /*
108 ///////////////////////////////////////////////////////////////////////////
109 //  NAME           : client_message
110 //  BASECLASS      : 
111 //  MEMBERS        :
112 //  OPERATORS      :
113 //  METHODS        : classify()
114 //                   enter()
115 //
116 //  DESCRIPTION    : 
117 //
118 //  RELATIONS      :
119 //  SEE ALSO       :
120 //  LAST MODIFIED  : Aug 06, 2003
121 ///////////////////////////////////////////////////////////////////////////
122 */
123
124 class client_message
125 {
126    String     hostname;      //  Where the message came from (FQDN)
127    UTC        arrival;       //  When we got the message.
128    String     service;       //  Service that created the message
129
130    std::list<xform>  kitchen;   //  The collection of message filters and line cookers
131    xform             pan;       //  The one we cook this log with
132
133    bool       mail_header;   //  Does the message contain a mail header ?
134    bool       gpg_encrypted; //  Is the message encrypted ?
135
136    std::strstream  xmlBuffer;
137    xmlDocPtr       xmlDom;
138
139    double     certainty;     //  How certain are we about the message
140    enum
141    {
142       UNKNOWN,  RPMLIST, XML, COOKER_OBJECT
143    }  classification;
144
145
146    message_buffer    input;
147    gnucomo_database  database;
148
149    void    enterXML();
150    bool    extractHeader();
151
152 public:
153
154    client_message(std::istream *in, gnucomo_database db);
155
156    void   add_cooker(line_cooker *lc, message_filter *mf)
157    {
158       xform x(mf, lc);
159
160       kitchen.push_back(x);
161    }
162
163    double classify(String host, UTC arrival = Now(), String serv = "");
164    int    enter();
165 };
166