Different kinds of log files are parsed by a collection of objects
[gnucomo.git] / doc / design.xml
1 <?xml version="1.0"?>
2 <!DOCTYPE doc SYSTEM "/usr/local/xslt/doc.dtd">
3 <?xml-stylesheet type="text/xsl" href="/usr/local/xslt/html.xsl"?>
4 <doc style="main.css">
5
6 <!--
7       XML documentation system
8       Original author :  Arjen Baart - arjen@andromeda.nl
9       Version         : $Revision: 1.5 $
10
11       This document is prepared for XMLDoc. Transform to HTML,
12       LaTeX, Postscript or plain text with XMLDoc utilities and
13       XSLT sheets from http://www.andromeda.nl/projects/xmldoc/
14 -->
15
16 <book>
17 <titlepage>
18    <title>Gnucomo - Computer Monitoring</title>
19    <subtitle>Design description</subtitle>
20    <para><picture src='logo.png' eps='logo' scale='0.7'/></para>
21    <author>Arjen Baart <code>&lt;arjen@andromeda.nl&gt;</code></author>
22    <author>Brenno de Winter<code>&lt;brenno@dewinter.com&gt;</code></author>
23    <author>Peter Roozemaal<code>&lt;mathfox@xs4all.nl&gt;</code></author>
24    <date>August 06, 2003</date>
25    <docinfo>
26       <infoitem label="Version">0.5</infoitem>
27       <infoitem label="Organization">Andromeda Technology &amp; Automation</infoitem>
28       <infoitem label="Organization">De Winter Information Solutions</infoitem>
29    </docinfo>
30    <abstract>
31    </abstract>
32 </titlepage>
33
34 <toc/>
35
36 <chapter>
37 <heading>Introduction</heading>
38
39 <para>
40 <strong>Gnucomo</strong> is a system to monitor computer systems.
41 This document describes the design of the <strong>Gnucomo</strong> applications
42 and is based upon the development manifest.
43 </para>
44
45 </chapter>
46
47 <chapter>
48 <heading>Architecture</heading>
49
50 <para>
51 The architecture of <strong>gnucomo</strong> is shown in the
52 data flow diagram below:
53 </para>
54
55 <para>
56    <picture src='dataflow.png' eps='dataflow' scale='0.7'/>
57 </para>
58
59 <para>
60 At the left of the diagram, information is aquired from the monitored system.
61 Several agents can be used to obtain information from this system, in
62 active or passive ways.
63 A passive agent uses information which is available on the system anyway,
64 such as log files or other lists.
65 An active agent, requests explicit data from the monitored system.
66 One example of a passive agent is <emph>logrunner</emph>, a program which
67 monitores system log files and sends regular updates to the <strong>gnucomo</strong>
68 server.
69 The agents on the monitored system send the data to some kind of transportation channel.
70 This can be any form of transport, such as Email, SOAP, plain file copying or
71 some special network connection.
72 If desired, the transportation may provide security.
73 Once arrived at the server, the information from monitored systems is captured
74 by the <emph>gcm_input</emph> process.
75 This process can obtain the data through many forms of transport and from
76 a number of input formats.
77 <emph>Gcm_input</emph> will try to recognize as much as possible from an
78 input message and store the obtained information into the <emph>Raw Storage</emph>
79 database.
80 The <emph>Raw Storage</emph> data is processed further and analyzed by
81 the <emph>gcm_daemon</emph>, which scans the data, gathers statistics and
82 stores its results into the <emph>Derived Storage</emph> database where
83 it is available for human review and further analysis.
84 </para>
85
86 <para>
87 Architectural items to consider:
88 <itemize>
89 <item>Active and passive data acquisition</item>
90 <item>Monitoring static and dynamic system parameters</item>
91 <item>Upper and lower limits for system parameters</item>
92 </itemize>
93 </para>
94
95 <para>
96 Existing log analysis tools: logwatch, analog.
97 </para>
98 </chapter>
99
100 <chapter>
101 <heading>System design</heading>
102
103 <para>
104 <strong>Gnucomo</strong> is a collection of different application programs,
105 rather than a single application.
106 All these application programs revolve around the <strong>Gnucomo</strong>
107 database as described in the manifest.
108 </para>
109
110 <section>
111 <heading>Database design</heading>
112
113 <para>
114 The design of the database is described extensively in
115 <reference href="manifest.html">the Manifest</reference>.
116 Assuming development is done on the same system on which the real (production)
117 gnucomo database is maintained, there is a need for a separate database
118 on which to perform development and integration tests.
119 Quite often, the test database will need to be destroyed and recreated.
120 To enable testing of <strong>gnucomo</strong> applications, all programs
121 need to access either the test database or the production database.
122 To accommodate this, each application needs an option to override the
123 default name of the configuration file (gnucomo.conf).
124 </para>
125
126 <para>
127 To create a convenient programming interface for object oriented languages,
128 a class <emph>gnucomo_database</emph> provides an abstract layer which
129 hides the details of the database implementation.
130 An object of this class maintains the connection to the database server
131 and provides convenience functions for accessing information in the
132 database.
133 A constructor of the <emph>gnucomo_database</emph> is passed a reference to
134 the <emph>gnucomo_configuration</emph> object in order to access the database.
135 This accommodates for both production and test databases.
136 The constructor will immediately try to connect to the database and check its
137 validity.
138 The destructor will of course close the database connection.
139 </para>
140
141 <para>
142 Other methods provide access to the database in a low-level manner.
143 There will be lots more in the future, but here are a few to begin with:
144 <itemize>
145 <item>Send a SQL query to the database.</item>
146 <item>Read a tuple from a result set.</item>
147 <item>Obtain the userid for the current database session.</item>
148 </itemize>
149 </para>
150
151 <para>
152 The information stored in the database as tuples is represented by classes in
153 other programming languages such as C++ of PHP.
154 Each class models a particular type of tuple (an <emph>entity</emph>)
155 in the database.
156 Such classes maintain the relation with the database on one end,
157 while providing methods that are specific to the entity on the other end.
158 All database communication and SQL queries are hidden inside the
159 entity's class.
160 This includes, for example, handling database result sets and access control.
161 </para>
162 <para>
163 Properties and operations that are common to all classes that represent
164 entities in the database are caught in a common base class.
165 The base class, named <emph>database_entity</emph> provides default
166 implementations for loading and storing tuples, construction and destruction
167 and iteration.
168 Most derived classes will override these functions.
169 Two examples of classes that represent entities in the database
170 are <emph>object</emph> and <emph>service</emph>.
171 Both are derived from a <emph>database_entity</emph>, as show below:
172 <para>
173   <picture src='class-database_entity.png' eps='class-database_entity'/>
174 </para>
175 </para>
176
177 <para>
178 Constructors of classes derived from <emph>database_entity</emph> come in
179 two variaties: with or without database interaction.
180 Constructors that do not interact with the database have only one argument:
181 a reference to the <emph>gnucomo_database</emph> object which handles
182 the low-level interaction with the database server.
183 The example below shows a few of these constructors:
184 <verbatim>
185
186   database_entity::database_entity(gnucomo_database &amp;gdb)
187
188   object::object(gnucomo_database &amp;gdb)
189
190   service::service(gnucomo_database &amp;gdb)
191
192 </verbatim>
193 The objective of this type of constructor is to cerate a fresh tuple and
194 store it in the database later on.
195 All these constructors do is establish the connection to the database
196 server and fill in the defaults for the fields in the tuple.
197 A destructor will put the actual tuple into the database if any
198 information in the object has changed.
199 This mey be by sending an INSERT if the object is completely fresh
200 or an UPDATE if an already existing tuple was changed.
201 The state information about the freshness of an object is a property
202 common to all database entities and is therefore maintained in
203 the <emph>database_entity</emph> class.
204 </para>
205 <para>
206 Constructors that do interact with the database accept additional
207 arguments after the initial <emph>gnucomo_database</emph> reference.
208 These extra arguments are used to retreive a tuple from the database.
209 Examples of such constructors are:
210 <verbatim>
211
212    object::object(gnucomo_database &amp;gdb, String hostname)
213
214    object::object(gnucomo_database &amp;gdb, long long oid)
215
216    service::service(gnucomo_database &amp;gdb, String name)
217
218 </verbatim>
219 The set of arguments must of course correspond to a set of fields that
220 uniquely identify the tuple.
221 The primary key of the database table would be ideally suitable.
222 If the tuple is not found in the database, data members of the object
223 are set to default values and the object is marked as being fresh and
224 not changed.
225 </para>
226
227 <para>
228 Methods with the same name as a field in a tuple read or change the
229 value of that field.
230 Without an argument, such a method returns the current value of the field.
231 With a single argument, the field is set to the new value passed in the
232 argument and the method returns the original value.
233 Whenever a field is set to a new value, the object is marked as being
234 'changed'.
235 A destructor will then save the tuple to the database.
236 </para>
237 </section>
238
239 <section>
240 <heading>Configuration</heading>
241
242 <para>
243 Configuration parameters are stored in a XML formatted configuration file.
244 The config file contains a two-level hierarchy.
245 The first level denotes the section for which the parameter is used
246 and the second level is the parameter itself.
247 Both sections and parameters are elements in XML terminology.
248 The top-level (root) element is the configuration tree itself.
249 The root element must have the same name as the application's name
250 for which the configuration is intended.
251 The level-1 elements are sections of the configuration tree.
252 Within these section elements, the configuration has several parameter elements.
253 Each parameter is an element by itself.
254 The element's name is the name of the parameter, just as a section
255 element's name is the name of the section.
256 The content of the parameter element is the value of the parameter.
257 Attributes in either section elements or parameter elements are not used.
258 </para>
259 <para>
260 The configuration file is located in two places.
261 The is a system wide configuration in
262 <code>/usr/local/etc/gnucomo.conf</code> and each user may
263 have his or her own configuration in <code>~/.gnucomo.conf</code>.
264 The value of a user-specific configuration parameter overrides
265 the system-wide value.
266 </para>
267 <para>
268 The following sections and parameters are defined for the Gnucomo
269 configuration:
270 <itemize>
271 <item>database
272    <itemize>
273    <item>type</item>
274    <item>name</item>
275    <item>user</item>
276    <item>password</item>
277    <item>host</item>
278    <item>port</item>
279    </itemize>
280 </item>
281 <item>logging
282    <itemize>
283    <item>method</item>
284    <item>destination</item>
285    <item>level</item>
286    </itemize>
287 </item>
288 <item>gcm_input
289    <itemize>
290    <item>dbuser</item>
291    <item>password</item>
292    </itemize>
293 </item>
294 <item>gcm_daemon
295    <itemize>
296    <item>dbuser</item>
297    <item>password</item>
298    </itemize>
299 </item>
300 </itemize>
301
302 The <emph>database</emph> section defines how the database is accessed.
303 The <emph>database/type</emph> parameter must have the content <code>PostgreSQL</code>.
304 Other database systems are not supported yet.
305 The <emph>database/user</emph> and <emph>database/password</emph> provide default
306 login information onto the database server.
307 Specific user names and passwords may be specified for separate applications, such
308 as <emph>gcm_input</emph> and <emph>gcm_daemon</emph>.
309 </para>
310
311 <subsection>
312 <heading>gnucomo_config class</heading>
313
314 <para>
315 Each Gnucomo application should have exactly one object of the
316 <strong>gnucomo_config</strong> to obtain its configuration
317 parameters.
318 The following methods are supported in this class:
319
320 <itemize>
321
322 <item>
323   read(String name)
324   <para>
325   Reads the XML formatted configuration files from
326   <code>/usr/local/etc/&lt;name&gt;.conf</code> and
327   <code>~/.&lt;name&gt;.conf</code>.
328   </para>
329 </item>
330
331 <item>
332   String find_parameter(String section, String param)
333   <para>
334   Return the value of the parameter <emph>param</emph> in
335   section <emph>section</emph>.
336   </para>
337 </item>
338
339 <item>
340   String Database()
341   <para>
342   Return the database access string to be used for the PgDatabase constructor.
343   </para>
344 </item>
345
346 </itemize>
347 </para>
348
349 </subsection>
350 </section>
351
352 <section>
353 <heading>gcm_input</heading>
354
355 <para>
356 <strong>gcm_input</strong> is the application which captures messages from client
357 systems in one form or another and tries to store information from these messages
358 into the database.
359 A client message may arrive in a number of forms and through any kind of
360 transportation channel.
361 Here are a few examples:
362
363 <itemize>
364 <item>Obtained directly from a local client's file system.</item>
365 <item>From the output of another process, through standard input.</item>
366 <item>Copied remotely from a client's file system, e.g. using
367    <code>ftp</code>, <code>rcp</code> or <code>scp</code>.
368    This is usually handled through spooled files.
369 </item>
370 <item>Through an email.</item>
371 <item>As a SOAP web service, carried through HTTP or SMTP.</item>
372 <item>Through a TCP connection on a special socket.</item>
373 </itemize>
374
375 On top of that, any message may be encrypted, for example with PGP or GnuPG.
376 In any of these situations, <strong>gcm_input</strong> should be able to extract
377 as much information as possible from the client's message.
378 In case the message is encrypted, it may not be possible to run <strong>gcm_input</strong>
379 in the background, since human intervention is needed to enter the secret key.
380 </para>
381 <para>
382 The primary function of <strong>gcm_input</strong> is to store lines from a client's
383 log files into the <emph>log</emph> table or scan a report from a probe and update
384 the <emph>parameter</emph> table.
385 To do this, we need certain information about the client message that is usually not
386 in the content of a log file.
387 This information includes:
388 <itemize>
389 <item>The source of the log file, most often in the form of the client's hostname.</item>
390 <item>The time stamp of the time on which the log file arrived on the server.</item>
391 <item>The service on the client which produced the log file.</item>
392 </itemize>
393
394 Sometimes, this information is available from the message itself, as in an email header.
395 On other occasions, the information needs to be supplied externally,
396 e.g. by using command line options.
397 In any case, this type of 'header' information is relevant to the message
398 as a whole.
399 As a result, <emph>gcm_input</emph> can accept one and only one message at a time.
400 For example, it is not possible to connect the standard output of
401 <emph>logrunner</emph> to the standard input of <emph>gcm_input</emph> and have
402 a continuous stream of messages from different log sources.
403 Each message should be fed to <emph>gcm_input</emph> separately.
404 Also when <emph>logrunner</emph> uses a special socket to send logging data,
405 a new connection must be created for each message.
406 The dataflow diagram below shows how a message travels from the input source
407 to the database.
408 </para>
409
410 <para>
411    <picture src='gcm_input-dataflow.png' eps='gcm_input-dataflow'/>
412 </para>
413
414 <para>
415 Internally, <emph>gcm_input</emph> handles <ref to='XML_input'>XML input</ref>
416 and each input item must have its data fields split into appropriate XML elements.
417 when data is offered in some other form, this data must be filtered
418 and transformed into XML before <emph>gcm_input</emph> can handle it.
419 Two levels of transformation are possible.
420 At the highest level, the whole message is transformed into an XML
421 document with a <code>&lt;message&gt;</code> root element and the
422 appropriate <code>&lt;header&gt;</code> and <code>&lt;data&gt;</code>
423 elements, all of which are put in the proper namespace.
424 At the lowest level, each line of the message's data can be transformed
425 into a <code>&lt;cooked&gt; &lt;log&gt;</code> element.
426 Two classes of replaceable filter objects take care of these transformations.
427 Depending on the content of the message and/or command line options to
428 <emph>gcm_input</emph>, and appropriate filter object is inserted into
429 the data stream.
430 </para>
431
432 <para>
433 The <ref to='line_cooker'><emph>line_cooker</emph></ref>
434 operates on a node in the DOM tree which is
435 supposed to be a &lt;raw&gt; &lt;log&gt; element that contains one line
436 from a log file.
437 The <emph>line_cooker</emph> transforms a <emph>raw</emph> log line into
438 its constituent parts that make up en &lt;cooked&gt; element.
439 Since each type of logfile uses a different layout and syntax,
440 different line cookers can be used, depending on the type of log.
441 This type is indicated by the &lt;messagetype&gt; element in the header
442 part of the message.
443 Clearly, the <emph>line_cooker</emph> is a polymorphic entity.
444 Exactly which <emph>line_cooker</emph> is used is determined through
445 <ref to='classifying'>classifying</ref>
446 the content of the message or the message type indicated in the header.
447 The <emph>line_cooker</emph> base class provides a default implementation
448 for most methods, while derived classes provide the actual cooking.
449 </para>
450
451 <para>
452 Ouput created by <emph>gcm_input</emph> for logging and debugging purposes
453 can be sent to one of several destinations:
454 <itemize>
455 <item>standard error.</item>
456 <item>a log file.</item>
457 <item>the system log.</item>
458 <item>an email address.</item>
459 </itemize>
460 The actual destination is stated in the <strong>gnucomo</strong>
461 configuration file. The default is stderr.
462 A <emph>log</emph> object filters output according to the debug level.
463 </para>
464
465 <subsection>
466 <heading><label name='classifying'/>Classifying messages</heading>
467
468 <para>
469 Apart from determining information about the client's message, the content
470 of the message needs to be analyzed in order to handle it properly.
471 The body of the message may contain all sorts of information, such as:
472 <itemize>
473 <item>System log file</item>
474 <item>Apache log file</item>
475 <item>Report from a Gnucomo agent or other probe, for example "rpm -qa"
476       or "df -k".</item>
477 <item>Generic XML input</item>
478 <item>Something else...</item>
479 </itemize>
480
481 Basically, <strong>gcm_input</strong> acceepts two kinds of input: Log lines
482 and parameter reprots.
483 The message is analyzed to obtain information about what the message entails
484 and where it came from.
485 The message classification embodies the way in which a message must be
486 handled and in what way information from the message can be put into
487 the database.
488 Aspects for handling the message are for example:
489 <itemize>
490 <item>Strip lines at the beginning or end.</item>
491 <item>Store each line separately or store the message as a whole.</item>
492 <item>How to extract hostname, arrival time and service from the message.</item>
493 <item>How to break up the message into individual fields for a <emph>log</emph> record.</item>
494 </itemize>
495 These aspects are all handled in polymorphic <emph>message_filter</emph>
496 and <emph>line_cooker</emph> classes.
497 The result of classifying a message is the selection of the proper
498 objects derived from these classes from a collection of such objects.
499 </para>
500
501 <para>
502 The <strong>classify()</strong> method tries to extract that information.
503 Sometimes, this information can not be determined with absolute 100% certainty.
504 The certainty expresses how sure we are about the contents in the message.
505 Classifying a message may be performed with an algorithm as shown in
506 the following pseudo code:
507
508 <verbatim>
509 while certainty &lt; &epsilon; AND not at end
510
511    Scan for a marker
512
513    Adjust certainty
514 </verbatim>
515
516 Initially, a message is not classified and the certainty is 0.0.
517 Some lines point toward a certain class of message but do not absolutely determine
518 the class of a message. Other pieces of text are typical for a certain message class.
519 Examples of markers that determine the classification of a client message
520 are discussed below.
521
522 <verbatim>
523 From - Sat Sep 14 15:01:15 2002
524 </verbatim>
525
526 This is almost certainly a UNIX style mail header.
527 There should be lines beginning with <code>From:</code> and <code>Date:</code>
528 before the first empty line is encountered.
529 The hostname of the client that sent the message and the time of arrival
530 can be determined from these email header lines.
531 The content of the message is still to be determined by matching
532 other markers.
533
534 <verbatim>
535 -----BEGIN PGP MESSAGE-----
536 </verbatim>
537
538 Such a line in the message certainly means that the message is PGP or GnuPG
539 encrypted.
540 Decrypting is possible only if someone or something provides a secret key.
541
542 <verbatim>
543 &lt;?xml version='1.0'?&gt;
544 </verbatim>
545
546 The XML header declares the message to be generic XML input.
547 The structure of the XML message that <strong>gcm_input</strong> accepts
548 is described in the next section.
549
550 <verbatim>
551 Sep  1 04:20:00 kithira kernel: solo1: unloading
552 </verbatim>
553
554 The general pattern of a system log file is an abbreviated month name, a day,
555 a time, a name of a host without the domain, the name of a service followed
556 by a colon and finally, the message of that service.
557 We can match this with a regular expression to see if the message holds syslog lines.
558 Similar matches can be used to find Apache log lines or output from the <emph>dump</emph>
559 backup program or anything else.
560 </para>
561 </subsection>
562
563 <subsection>
564 <heading><label name='XML_input'/>Generic XML input</heading>
565
566 <para>
567
568 Since <strong>gcm_input</strong> can not understand every conceivable form
569 of input, a client can offer its input in a more generic form which reflects
570 the structure of the Gnucomo database.
571 In this case, the input is structured in an XML document that contains the input
572 data in a form that allows <strong>gcm_input</strong> to store the information
573 into the database without knowing the nature of the input.
574 The XML root element for <strong>gcm_input</strong> is a <emph>&lt;message&gt;</emph>, defined
575 in the namespace with namespace name <code>http://gnucomo.org/transport/</code>.
576 All other elements and attributes of the <emph>&lt;message&gt;</emph> must be defined
577 within this namespace.
578 </para>
579 <para>
580 Within the <emph>&lt;message&gt;</emph> element there is a <emph>&lt;header&gt;</emph>
581 and a <emph>&lt;data&gt;</emph> element.
582 The <emph>&lt;data&gt;</emph> element may contain the logdata in an externally
583 specified format.
584 The <emph>&lt;header&gt;</emph> element contains a number of elements (fields), some
585 mandatory, some optional. The text of the element contains the value of
586 the element.
587 The following elements have been defined:
588
589 <itemize>
590 <item>
591 <emph>&lt;mesagetype&gt;</emph> mandatory
592      <para>
593       The type (format) of the logdata in the data element. The message type
594       determines the way in which raw log elements are parsed and split up
595       into separate fields for insertion into the database.
596       The message types gcm_input understands are:
597       <itemize>
598       <item><code>system log</code> : The most common form of UNIX system logs.
599             Also used in most Linux distributions.
600       </item>
601       <item><code>IRIX system log</code> : Variation of system log, used by SGI.
602       </item>
603       <item><code>apache access log</code> : Access log of the Apache http daemon,
604             in default form.
605       </item>
606       <item><code>apache error log</code> : Error log of the Apache http daemon,
607             in default form.
608       </item>
609       </itemize>
610       There mnust also be a 'generic' system log in case all elements are
611       cooked already.
612      </para>
613 </item>
614 <item>
615 <emph>&lt;hostname&gt;</emph> mandatory
616      <para>
617       The name of the system that generated the data in the data block.
618       This can be different from the computer composing the message.
619      </para>
620 </item>
621 <item>
622 <emph>&lt;service&gt;</emph> optional
623      <para>
624       The (default) value of the service running on the host that
625       generated the message data. For logfiles that don't contain the
626       service name embedded in them.
627      </para>
628 </item>
629 <item>
630 <emph>&lt;time&gt;</emph> optional
631      <para>
632       The best approximation to the time that the data was generated.
633       For (log)data that doesn't contain an embedded datestamp.
634      </para>
635 </item>
636 </itemize>
637
638 The following example shows an XML message for <strong>gcm_input</strong>
639 with a filled-in header and an empty <emph>&lt;data&gt;</emph> element:
640
641 <verbatim>
642   &lt;gcmt:message xmlns:gcmt='http://gnucomo.org/transport/'&gt;
643      &lt;gcmt:header&gt;
644         &lt;gcmt:messagetype&gt;apache error log&lt;/gcmt:messagetype&gt;
645         &lt;gcmt:hostname&gt;client.gnucomo.org&lt;/gcmt:hostname&gt;
646         &lt;gcmt:service&gt;httpd&lt;/gcmt:service&gt;
647         &lt;gcmt:time&gt;2003-04-17 14:40:46.312895+01:00&lt;/gcmt:time&gt;
648      &lt;/gcmt:header&gt;
649      &lt;gcmt:data/&gt;
650   &lt;/gcmt:message&gt;
651 </verbatim>
652 </para>
653
654 <para>
655 The <emph>data</emph> element can hold one of two possible child
656 elemnts: <emph>&lt;log&gt;</emph> or <emph>&lt;parameters&gt;</emph>.
657 The <emph>&lt;log&gt;</emph> element may contain any number of lines from
658 a system's log file, each line in a separate element.
659 A single log line is the content of either a <emph>&lt;raw&gt;</emph> or
660 a <emph>&lt;cooked&gt;</emph> element.
661 The <emph>&lt;raw&gt;</emph> element contains the log line "as is" and nothing more.
662 This is the easiest way to provide XML data for <strong>gcm_input</strong>.
663 However, the log line itself must be in a form that <strong>gcm_input</strong>
664 can understand.
665 After all, <strong>gcm_input</strong> still needs to extract meaningfull information
666 from that line, such as the timestamp and the service that created the log.
667 The client can also choose to provide that information separately by encapsulating
668 the log line in a <emph>&lt;cooked&gt;</emph> element.
669 This element may have up to four child elements, two of which are mandatory:
670 <itemize>
671 <item><emph>&lt;timestamp&gt;</emph> mandatory.
672    <para>
673    The time at which the log line was generated by the client.
674    </para>
675 </item>
676 <item><emph>&lt;hostname&gt;</emph> optional.
677    <para>
678    For logs that include a hostname in each line. This hostname is checked
679    against the hostname in the <emph>&lt;header&gt;</emph> element.
680    </para>
681 </item>
682 <item><emph>&lt;service&gt;</emph> optional.
683    <para>
684    If the service that generated the log is not provided in the <emph>&lt;header&gt;</emph>
685    the service must be stated for each log line separately.
686    Othewise, each log line is assumed to be generated by the same service.
687    </para>
688 </item>
689 <item><emph>&lt;raw&gt;</emph> mandatory.
690    <para>
691    The content of the full log line. This would have the same content of the singular
692    <emph>&lt;raw&gt;</emph> element if the log line was not provided in a
693    <emph>&lt;cooked&gt;</emph> element.
694    </para>
695 </item>
696 </itemize>
697 The following shows an example of the log message with two lines in the
698 <emph>&lt;log&gt;</emph> element, one raw and one cooked:
699
700 <verbatim>
701   &lt;gcmt:data xmlns:gcmt='http://gnucomo.org/transport/'&gt;
702     &lt;gcmt:log&gt;
703      &lt;gcmt:raw&gt;
704        Apr 13 04:31:03 schiza kernel: attempt to access beyond end of device
705      &lt;/gcmt:raw&gt;
706      &lt;gcmt:cooked&gt;
707         &lt;gcmt:timestamp&gt;2003-04-13 04:31:03+02:00&lt;/gcmt:timestamp&gt;
708         &lt;gcmt:hostname&gt;schiza&lt;/gcmt:hostname&gt;
709         &lt;gcmt:service&gt;kernel&lt;/gcmt:service&gt;
710         &lt;gcmt:raw&gt;
711          Apr 13 04:31:03 schiza kernel: 03:05: rw=0, want=1061109568, limit=2522173
712         &lt;/gcmt:raw&gt;
713      &lt;/gcmt:cooked&gt;
714     &lt;/gcmt:log&gt;
715   &lt;/gcmt:data&gt;
716 </verbatim>
717 </para>
718
719 <para>
720 The <emph>&lt;parameters&gt;</emph> element contains a list of parameters
721 of the same class. The class is provided as an attribute in the
722 <emph>&lt;parameters&gt;</emph> open tag.
723 There is a <emph>&lt;parameter&gt;</emph> element for each parameter in the list.
724 The child elements of a <emph>&lt;parameter&gt;</emph> are one optional
725 <emph>&lt;description&gt;</emph> element and zero or more <emph>&lt;property&gt;</emph>
726 elements.
727 The names of a parameter and a property are provided by the mandatory <emph>name</emph>
728 attributes in the respective elements.
729 The following example shows a possible parameter report from a "df -k":
730 <verbatim>
731   &lt;gcmt:data xmlns:gcmt='http://gnucomo.org/transport/'&gt;
732     &lt;gcmt:parameters gcmt:class='filesystem'&gt;
733       &lt;gcmt:parameter gcmt:name='root'&gt;
734          &lt;gcmt:description&gt;Root filesystem&lt;/gcmt:description&gt;
735          &lt;gcmt:property gcmt:name='size'&gt;303344&lt;/gcmt:property&gt;
736          &lt;gcmt:property gcmt:name='used'&gt;104051&lt;/gcmt:property&gt;
737          &lt;gcmt:property gcmt:name='available'&gt;183632&lt;/gcmt:property&gt;
738          &lt;gcmt:property gcmt:name='device'&gt;/dev/hda1&lt;/gcmt:property&gt;
739          &lt;gcmt:property gcmt:name='mountpoint'&gt;/&lt;/gcmt:property&gt;
740       &lt;/gcmt:parameter&gt;
741       &lt;gcmt:parameter gcmt:name='usr'&gt;
742          &lt;gcmt:description&gt;Usr filesystem&lt;/gcmt:description&gt;
743          &lt;gcmt:property gcmt:name='size'&gt;5044188&lt;/gcmt:property&gt;
744          &lt;gcmt:property gcmt:name='used'&gt;3073716&lt;/gcmt:property&gt;
745          &lt;gcmt:property gcmt:name='available'&gt;1714236&lt;/gcmt:property&gt;
746          &lt;gcmt:property gcmt:name='device'&gt;/dev/hdd2&lt;/gcmt:property&gt;
747          &lt;gcmt:property gcmt:name='mountpoint'&gt;/usr&lt;/gcmt:property&gt;
748       &lt;/gcmt:parameter&gt;
749     &lt;/gcmt:parameters&gt;
750   &lt;/gcmt:data&gt;
751 </verbatim>
752 </para>
753
754 </subsection>
755
756 <subsection>
757 <heading>Gcm_input classes</heading>
758 <para>
759 The figure below shows the class diagram that is used for <strong>gcm_input</strong>:
760    <para>
761    <picture src='classes-gcm_input.png' eps='classes-gcm_input'/>
762    </para>
763
764 The heart of the application is a <emph>client_message</emph> object.
765 This object reads the message through the
766 <ref to='message_buffer'><emph>message_buffer</emph></ref> from some
767 input stream (file, string, stdin or socket), classifies the message and
768 enters information from the message into the database.
769 It has a relationship with a <emph>gnucomo_database</emph> object which
770 is an abstraction of the tables in the database.
771 These are the methods for the <emph>client_message</emph> class:
772
773 <itemize>
774 <item><code>client_message::client_message(istream *in, gnucomo_database *db)</code>
775    <para>
776    Constructor.
777    </para>
778 </item>
779 <item><code>void add_cooker(line_cooker *lc)</code>
780   <para>
781   Add another <emph>line_cooker</emph> object to the collection.
782   </para>
783 </item>
784 <item><code>double client_message::classify(String host, date arrival_d,
785                                              hour arrival_t, String serv)</code>
786   <para>
787   Try to classify the message and return the certainty with which the class of the
788   message could be determined.
789   If the hostname, arrival time and service can not be extracted from the message,
790   use the arguments as default.
791   This will try to select one of the <emph>line_cooker</emph> objects
792   from the collection built with the <emph>add_cooker</emph> method.
793   </para>
794 </item>
795 <item><code>int enter()</code>
796   <para>
797   Insert the message contents into the <emph>log</emph> table of the gnucomo
798   database.
799   Returns the number of records inserted.
800   </para>
801 </item>
802 </itemize>
803
804 </para>
805
806 <subsubsection>
807 <heading><label name='line_cooker'/>line_cooker</heading>
808 <para>
809 To turn a raw line from a log file onto separate parts that can be stored
810 in the database, i.e. parse the line, the <emph>client_message</emph>
811 object uses a <emph>line_cooker</emph> object.
812 This is a polymorphic object, so each type of log can have its own parser,
813 while the <emph>client_message</emph> object uses a common interface
814 for each one.
815 For each message, one specific <emph>line_cooker</emph> object is
816 selected as determined by the message type.
817 E.g., the derived class <emph>syslog_cooker</emph> is used for system logs.
818 When the <emph>client_message</emph> object encounters a <strong>raw</strong>
819 log element, it takes the following steps to turn this into a
820 <strong>cooked</strong> log element:
821 <enumerate>
822 <item>
823   Remove the TEXT node of the "raw" element and save its content.
824 </item>
825 <item>
826   Change the name of the element into "cooked".
827 </item>
828 <item>
829   Check if the content matches the syntax of the type of log we're
830   processing at the moment.
831   This depends on the message type and is therefore a task for the
832   <emph>line_cooker</emph> object.
833 </item>
834 <item>
835   Have the <emph>line_cooker</emph> parse the content and extract
836   the timestamp and optionally the hostname and service.
837 </item>
838 <item>
839   Insert new child elements into the cooked element.
840 </item>
841 </enumerate>
842 After that, the <emph>cooked</emph> element is ready for further processing
843 and possibly storing into the database.
844 </para>
845
846 <para>
847 The <emph>line_cooker</emph> base class holds three protected members
848 that must be filled with infomation by the derived classes:
849 <itemize>
850 <item><code>UTC ts</code> : the timestamp.</item>
851 <item><code>String hn</code> : the hostname</item>
852 <item><code>String srv</code> : the service</item>
853 </itemize>
854 Corresponding base class methods (<emph>timestamp</emph>,
855 <emph>hostname</emph> and <emph>service</emph>) will do
856 nothing more than return these values.
857 It is up to the derived class's <emph>cook_this</emph> method
858 to properly initialize these members.
859 </para>
860
861 <para>
862 The methods for the <emph>line_cooker</emph> class are:
863 <itemize>
864 <item>
865   <code>bool line_cooker::check_pattern(String logline)</code>
866   <para>
867   Tries to match the <emph>logline</emph> against that patterns
868   that describe the message syntax.
869   In the <emph>line_cooker</emph> base class, this is a pure virtual function.
870   Returns true if the log line adheres to the message-specific syntax.
871   </para>
872 </item>
873 <item>
874   <code>bool line_cooker::cook_this(String logline, UTC arrival)</code>
875   <para>
876   Extracts information from the <emph>logline</emph>.
877   The <emph>arrival</emph> can be used to make corrections to incomplete
878   time stamps in the log file.
879   The implementation in a derived class must properly initialize the protected
880   members described above.
881   In the <emph>line_cooker</emph> base class, this is a pure virtual function.
882   Returns false if the pattern does not match.
883   </para>
884 </item>
885 <item>
886   <code>String line_cooker::message_type()</code>
887   <para>
888   Return the message type for which this line cooker is intended.
889   </para>
890 </item>
891 <item>
892   <code>UTC line_cooker::timestamp()</code>
893   <para>
894   Returns the timestamp that was previously extracted from the log line
895   or a 'null' timestamp if that information could nnot be extracted.
896   </para>
897 </item>
898 <item>
899    <code>String line_cooker::hostname()</code>
900   <para>
901   Returns the hostname that was previously extracted from the log line,
902   or an empty string if that information could not be extracted.
903   </para>
904 </item>
905 <item>
906    <code>String line_cooker::service()</code>
907   <para>
908   Returns the service that was previously extracted from the log line,
909   or an empty string if that information could not be extracted.
910   </para>
911 </item>
912 </itemize>
913 </para>
914 </subsubsection>
915
916 <subsubsection>
917 <heading><label name='message_buffer'/>message_buffer</heading>
918 <para>
919 Some kind of input buffering is needed when a client message is being processed.
920 The contents of the message are not entirely clear until a few lines are analyzed,
921 and these lines probably need to be read again.
922 When the message is stored in a file, this is no problem; a simple lseek allows us
923 to read any line over and over again.
924 However, when the message comes from an input stream, like a TCP socket or just
925 plain old stdin, this is a different matter.
926 Lines of the messages that are already read will be lost forever, unless they are
927 stored somewhere.
928 To store an input stream temporarily, there are two options:
929 <enumerate>
930 <item>In an internal memory buffer.</item>
931 <item>In an external (temporary) file.</item>
932 </enumerate>
933 The <emph>message_buffer</emph> class takes care of the input buffering, thus
934 hiding these implementation details.
935 On the outside, a <emph>message_buffer</emph> can be read line by line until the
936 end of the input is reached.
937 Lines of input can be read again by backing up to the beginning of the message
938 by using the <strong>rewind()</strong> method or by backing up one line
939 with the <strong>--</strong> operator.
940 The <emph>message_buffer</emph> object maintains a pointer to the next
941 available line.
942 The <strong>++</strong> operator, being the opposite of the <strong>--</strong>
943 operator, skips one line.
944 </para>
945
946 <para>
947 The <strong>&gt;&gt;</strong> operator reads data from the message
948 into the second (String) operand, just like the <strong>&gt;&gt;</strong>
949 operator for an istream.
950 There is a small difference, though.
951 The <strong>&gt;&gt;</strong> operator for a <emph>message_buffer</emph>
952 returns a boolean value which states if there actually was input available.
953 This value will usually turn to <code>false</code> at the end of file.
954 A second difference is the fact that input data can only be read into
955 <emph>String</emph> objects a line at a time.
956 There are no functions for reading integer or floating point numbers.
957 The <strong>&gt;&gt;</strong> operator reads the next line either from
958 an internal buffer or from the external input stream if the internal
959 buffer is exhausted.
960 Lines read from the input stream are cached in the internal buffer,
961 so they are available for reading another time, e.g. after
962 rewinding to the beginning of the message.
963 </para>
964
965 <para>
966 Methods for the <emph>message_buffer</emph> class:
967
968 <itemize>
969 <item>message_buffer::message_buffer(istream *in)
970   <para>
971   Constructor.
972   </para>
973 </item>
974 <item>bool operator &gt;&gt;(message_buffer &amp;, String &amp;)
975 </item>
976 <item>message_buffer::rewind()</item>
977 <item>message_buffer::operator --</item>
978 <item>message_buffer::operator ++</item>
979 </itemize>
980 </para>
981
982 </subsubsection>
983 </subsection>
984
985 <subsection>
986
987 <heading>Command arguments</heading>
988
989 <para>
990 <strong>Gcm_input</strong> understands the following command line arguments:
991 <itemize>
992 <item>-c &lt;name&gt; : Configuration name</item>
993 <item>-d &lt;date&gt; : Arrival time of the message</item>
994 <item>-h &lt;hostname&gt; : FQDN of the client</item>
995 <item>-s &lt;service&gt; : service that created the log</item>
996 <item>-v : verbose output. Print lots of debug information</item>
997 <item>-V : Print version and exit</item>
998 </itemize>
999 </para>
1000 </subsection>
1001 </section>
1002
1003 <section>
1004 <heading>gcm_daemon</heading>
1005 <para>
1006 <strong>Gcm_daemon</strong> is the application that processes data just
1007 arrived in the database.
1008 It handles the log-information delivered by <strong>gcm_input</strong>
1009 in the <emph>log</emph> table of the database.
1010 With the data further storage and classification can be done.
1011 Where <strong>gcm_input</strong> is a highly versatile application that is
1012 loaded and ended all the time the daemon is continously available monitoring
1013 the entire system. Basically the daemon monitors everything that happens
1014 in the database and excecutes continous checks and processes all the data.
1015 The two applications (gcm_input and gcm_daemon) together are the core of the central system. 
1016 The application has the following tasks:
1017 <itemize>
1018 <item>Processing data into other tables so that easy detection can take place</item>
1019 <item>Raising notifications based on the available input</item>
1020 <item>Maintain the status of notifications and changing priority when needed</item>
1021 <item>Priodically perform checks for alerts that are communicated through the notification-table</item>
1022 <item>Perform updates on the database when a new version of the software is loaded</item>
1023 </itemize>
1024 </para>
1025
1026 <subsection>
1027 <heading>Performing checks</heading>
1028
1029 <para>
1030 One of the most difficult tasks for the daemon is performing the automatic checks.
1031 Every check is different and will be made up of several parameters that have to test negative.
1032 That makes it hard to define this in software.
1033 Another downside is that some work may be very redundant.
1034 For that reason a more generic control structure is needed based on the technologies used.
1035 The logical choice is then to focus on the capabilities in the database and perform
1036 the job by executing queries.
1037 </para>
1038 <para>
1039 Since the system is about detecting problems and issues we build the detection in
1040 such a way that queries on the database result in 'suspicious' logrecords.
1041 So called 'innocent' records can be ignored. So if a query gives a result a
1042 problem is present, if there is no result there isn't a problem.
1043 As soon as we seek for common ground in the process of identifying problems
1044 it can be said that all results are based on the log-table
1045 (as stated in the manifest the log-table is the one and only table were input
1046 will arrive and stored for later use).
1047 Furthermore there are two ways of determining if a problem is present: 
1048 <itemize>
1049 <item>
1050 A single log-record or a group of log-records is within or outside the boundaries set.
1051 If it is outside the boundaries the logrecord(s) is/are a potential problem.
1052 If there are more boundaries set all of these need to be applied.
1053 Based on fixed data results can be derived.
1054 </item>
1055 <item>
1056 A set of records outline a trend that throughout time may turnout
1057 to be a problem. These type of values are not fixed and directly legible
1058 but more or less derived data. That data is input for some checks (previous bullet).
1059 </item>
1060 </itemize>
1061 In both cases a set of queries can be run.
1062 If there are more queries to be executed the later queries can be executed on
1063 only the results. For that reason intermediate results have to be stored in a
1064 temporary table for later reuse.
1065 Saving a session in combination with the found log-records are sufficient.
1066 This is also true since logrecords are the basis of all derived presences in
1067 the numerous log_adv_xxx-tables and always have a reference to the log-table. 
1068 </para>
1069 <para>
1070 Building the checks will thus be nothing more than combining queries
1071 and adding a classification to the results of that query.
1072 If this generic structure is being built properly with a simple (easy to understand) interface,
1073 many combinations can be made. People having a logically correct idea,
1074 but insufficient skills to program will be able to build checks.
1075 As a consequence we can offer the interface to the user,
1076 that in turn can also make particular checks for the environment that is unique to him/her.
1077 This - of course - doesn't mean that a clear SQL-interface shouldn't be offered.
1078 </para>
1079 <para>
1080 Whenever something happens, that is less than standard a line will be written to the syslogd.
1081 This will enable users and developpers to trace exactly what happened.
1082 The gcm_daemon will also log startup and ending so that abrupt endings of the daemon will be detected.
1083 </para>
1084 </subsection>
1085
1086 <subsection>
1087 <heading>The initial process</heading>
1088 <para>
1089 When gcm_daemon starts first some basic actions take place that go beyond
1090 just opening a connection to the database. The following actions also need to take place:
1091 <itemize>
1092 <item>
1093 Check the database version if it is still the most recent version.
1094 The daemon will check the version-number of the database.
1095 If the database is not the same version as gcm_daemon an update will be performed.
1096 When the database is up-to-date normal processing will continue.
1097 </item>
1098 <item>
1099 If the database reflects that the used version gcm_daemon is less recent than
1100 the running version (i.e. a new version has been installed) all records
1101 in the log-table that weren't recognized before will now be set to unprocessed since
1102 there is a fair change that they might be recognized this time. This will ensure that no data is lost.
1103 </item>
1104 </itemize>
1105 </para>
1106
1107 </subsection>
1108 </section>
1109
1110 <section>
1111 <heading>Design ideas</heading>
1112
1113 <para>
1114 Use of a neural network to analyze system logs:
1115 <itemize>
1116 <item>Classify words</item>
1117 <item>Classify message based on word classification</item>
1118 </itemize>
1119 </para>
1120 </section>
1121
1122 </chapter>
1123
1124 </book>
1125 </doc>