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.2 $
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 : Nov 04, 2002
51 **************************************************************************/
53 /*****************************
54 $Log: gcm_input.cpp,v $
55 Revision 1.2 2002-11-04 10:13:36 arjen
56 Use proper namespace for iostream classes
58 Revision 1.1 2002/10/05 10:25:49 arjen
59 Creation of gcm_input and a first approach to a web interface
61 *****************************/
63 static const char *RCSID = "$Id: gcm_input.cpp,v 1.2 2002-11-04 10:13:36 arjen Exp $";
70 bool testmode = false;
72 static char *Version = "gcm_input version 0.0.4 - Nov 05, 2002";
75 /*=========================================================================
77 ** SYNOPSIS : int main(int argc, char *argv[])
81 ** DESCRIPTION : Parse command line arguments and establish a connection
83 ** When we have a database connection, parse the log file
90 ** LAST MODIFIED : Sep 30, 2002
91 **=========================================================================
94 int main(int argc, char *argv[])
96 const char *usage = "Usage: gcm_input [-c configname] [-h hostname] [-d date]"
97 " [-s service] [-T] [-v] [-V]\n";
100 char *config_name = "gnucomo";
102 /* Parse command line arguments */
105 String hostname(""), service("");
109 while ((option = getopt(argc, argv, "c:h:d:s:TvV")) != -1)
114 config_name = optarg;
122 arrival = String(optarg);
123 if (!arrival.proper())
125 std::cerr << "gcm_input: Invalid date string: " << optarg << ".\n";
143 std::cout << Version << "\n";
155 std::cout << "Hostname = " << hostname;
156 std::cout << " Arrival = " << arrival;
157 std::cout << " Service = " << service << "\n";
160 /* Get the configuration file */
162 if (!cfg.read(config_name))
164 std::cerr << "Can not read Gnucomo configuration file for " << config_name << ".\n";
170 std::cout << "Config OK.\n";
173 /* Try to connect to the database */
175 gnucomo_database db(&cfg);
177 client_message msg(&std::cin, db);
179 if (msg.classify(hostname, arrival, service) > 0.9)