2 /**************************************************************************
3 ** (c) Copyright 2002, Andromeda Technology & Automation
4 ***************************************************************************
5 ** MODULE INFORMATION *
6 ***********************
7 ** FILE NAME : gcm_input.cpp
8 ** SYSTEM NAME : Gnucomo - Gnu Computer Monitoring
9 ** VERSION NUMBER : $Revision: 1.1 $
11 ** DESCRIPTION : Application to store client messages into the database
12 ** The client message contains a log file from one of the
13 ** system logs. Gcm_input parses the log file and enters
14 ** the raw data into the 'log' table of the gnucomo database.
16 ** The system log may arrive in one of several forms:
17 ** 1. Log file (archived or not) from a client machine.
18 ** 2. Log file from a client system, arriving in a clear Email.
19 ** 3. Log file from a client machine, arriving in an
22 ** additional information we need that may not be availble in
23 ** the content of the log is:
24 ** - FQDN of the client.
25 ** - Time of arrival of the log
26 ** - Service that created the log.
28 ** If the log arrives in an Email, these items probably are
29 ** available in the mail header. Otherwise, they have to be
30 ** provided as command line arguments.
32 ** Command line arguments:
33 ** -c <name> Configuration name (default = gnucomo).
34 ** -d <date> Date and time of log arrival.
35 ** -h <hostname> FQDN of the client.
36 ** -s <service> Service that created the log.
37 ** -T Test mode. Do not alter the database.
38 ** -v Verbose (debug) output.
39 ** -V Print version and exit.
44 ***************************************************************************
45 ** ADMINISTRATIVE INFORMATION *
46 ********************************
47 ** ORIGINAL AUTHOR : Arjen Baart - arjen@andromeda.nl
48 ** CREATION DATE : Aug 29, 2002
49 ** LAST UPDATE : Sep 30, 2002
51 **************************************************************************/
53 /*****************************
54 $Log: gcm_input.cpp,v $
55 Revision 1.1 2002-10-05 10:25:49 arjen
56 Creation of gcm_input and a first approach to a web interface
58 *****************************/
60 static const char *RCSID = "$Id: gcm_input.cpp,v 1.1 2002-10-05 10:25:49 arjen Exp $";
67 bool testmode = false;
69 static char *Version = "gcm_input version 0.0.3 - Sep 30, 2002";
72 /*=========================================================================
74 ** SYNOPSIS : int main(int argc, char *argv[])
78 ** DESCRIPTION : Parse command line arguments and establish a connection
80 ** When we have a database connection, parse the log file
87 ** LAST MODIFIED : Sep 30, 2002
88 **=========================================================================
91 int main(int argc, char *argv[])
93 const char *usage = "Usage: gcm_input [-c configname] [-h hostname] [-d date]"
94 " [-s service] [-T] [-v] [-V]\n";
97 char *config_name = "gnucomo";
99 /* Parse command line arguments */
102 String hostname(""), service("");
106 while ((option = getopt(argc, argv, "c:h:d:s:TvV")) != -1)
111 config_name = optarg;
119 arrival = String(optarg);
120 if (!arrival.proper())
122 cerr << "gcm_input: Invalid date string: " << optarg << ".\n";
140 cout << Version << "\n";
152 cout << "Hostname = " << hostname;
153 cout << " Arrival = " << arrival;
154 cout << " Service = " << service << "\n";
157 /* Get the configuration file */
159 if (!cfg.read(config_name))
161 cerr << "Can not read Gnucomo configuration file for " << config_name << ".\n";
167 cout << "Config OK.\n";
170 /* Try to connect to the database */
172 gnucomo_database db(&cfg);
174 client_message msg(&cin, db);
176 if (msg.classify(hostname, arrival, service) > 0.9)