-
/**************************************************************************
** (c) Copyright 2002, Andromeda Technology & Automation
+** This is free software; you can redistribute it and/or modify it under the
+** terms of the GNU General Public License, see the file COPYING.
***************************************************************************
** MODULE INFORMATION *
***********************
** FILE NAME : gcm_input.cpp
** SYSTEM NAME : Gnucomo - Gnu Computer Monitoring
-** VERSION NUMBER : $Revision: 1.1 $
+** VERSION NUMBER : $Revision: 1.5 $
**
** DESCRIPTION : Application to store client messages into the database
** The client message contains a log file from one of the
** -c <name> Configuration name (default = gnucomo).
** -d <date> Date and time of log arrival.
** -h <hostname> FQDN of the client.
+** -i Incremental - partial list of parameters.
** -s <service> Service that created the log.
** -T Test mode. Do not alter the database.
** -v Verbose (debug) output.
********************************
** ORIGINAL AUTHOR : Arjen Baart - arjen@andromeda.nl
** CREATION DATE : Aug 29, 2002
-** LAST UPDATE : Sep 30, 2002
+** LAST UPDATE : Jul 24, 2003
** MODIFICATIONS :
**************************************************************************/
/*****************************
$Log: gcm_input.cpp,v $
- Revision 1.1 2002-10-05 10:25:49 arjen
+ Revision 1.5 2003-08-05 08:11:06 arjen
+ Added two configuration parameters:
+ logfile - Log to this file instead of stderr.
+ verbosity - Verbose output if greater than 0.
+ Added '-i' option for incremental parameter updates
+
+ Revision 1.4 2003/03/29 08:42:00 arjen
+ Exit without reading any input if the database connection fails.
+
+ Revision 1.3 2002/11/09 08:04:27 arjen
+ Added a reference to the GPL
+
+ Revision 1.2 2002/11/04 10:13:36 arjen
+ Use proper namespace for iostream classes
+
+ Revision 1.1 2002/10/05 10:25:49 arjen
Creation of gcm_input and a first approach to a web interface
*****************************/
-static const char *RCSID = "$Id: gcm_input.cpp,v 1.1 2002-10-05 10:25:49 arjen Exp $";
+static const char *RCSID = "$Id: gcm_input.cpp,v 1.5 2003-08-05 08:11:06 arjen Exp $";
+
+#include <fstream>
#include <getopt.h>
bool verbose = false;
bool testmode = false;
+bool incremental = false;
+std::ostream *log = &std::cerr;
-static char *Version = "gcm_input version 0.0.3 - Sep 30, 2002";
+static char *Version = "gcm_input version 0.0.7 - Jul 24, 2003";
/*=========================================================================
** VARS CHANGED :
** FUNCTIONS USED :
** SEE ALSO :
-** LAST MODIFIED : Sep 30, 2002
+** LAST MODIFIED : Jul 24, 2003
**=========================================================================
*/
int main(int argc, char *argv[])
{
- const char *usage = "Usage: gcm_input [-c configname] [-h hostname] [-d date]"
+ const char *usage = "Usage: gcm_input [-c configname] [-h hostname] [-i] [-d date]"
" [-s service] [-T] [-v] [-V]\n";
gnucomo_config cfg;
char *config_name = "gnucomo";
+ std::ofstream logfile;
+
/* Parse command line arguments */
String hostname(""), service("");
int option;
-
- while ((option = getopt(argc, argv, "c:h:d:s:TvV")) != -1)
+
+ while ((option = getopt(argc, argv, "c:h:d:s:iTvV")) != -1)
{
switch (option)
{
arrival = String(optarg);
if (!arrival.proper())
{
- cerr << "gcm_input: Invalid date string: " << optarg << ".\n";
+ std::cerr << "gcm_input: Invalid date string: " << optarg << ".\n";
exit(1);
}
break;
service = optarg;
break;
+ case 'i':
+ incremental = true;
+ break;
+
case 'T':
testmode = true;
break;
break;
case 'V':
- cout << Version << "\n";
+ std::cout << Version << "\n";
exit(0);
case '?':
case ':':
- cerr << usage;
+ std::cerr << usage;
exit(1);
}
}
+ /* Get the configuration file */
- if (verbose)
+ if (!cfg.read(config_name))
{
- cout << "Hostname = " << hostname;
- cout << " Arrival = " << arrival;
- cout << " Service = " << service << "\n";
+ std::cerr << "Can not read Gnucomo configuration file for " << config_name << ".\n";
+ exit(1);
}
- /* Get the configuration file */
+ String logfile_name = cfg.find_parameter("gcm_input", "logfile");
+ int verbosity = cfg.find_parameter("gcm_input", "verbosity");
- if (!cfg.read(config_name))
+ if (logfile_name != "")
{
- cerr << "Can not read Gnucomo configuration file for " << config_name << ".\n";
- exit(1);
+ std::cerr << "Logging to " << logfile_name << ".\n";
+ logfile.open(logfile_name, _IO_APPEND); // for gcc 2
+ //logfile.open(logfile_name, std::ios_base::app); // for gcc 3
+ if (!logfile)
+ {
+ std::cerr << "Can't open logfile " << logfile_name << " for writing.\n";
+ }
+ else
+ {
+ log = &logfile;
+ verbose = verbose || verbosity > 0;
+ }
}
+ *log << "Gcm_input starting at " << Now() << ".\n";
+
if (verbose)
{
- cout << "Config OK.\n";
+ *log << "Hostname = " << hostname;
+ *log << " Arrival = " << arrival;
+ *log << " Service = " << service << "\n";
+ *log << "Config OK.\n";
}
/* Try to connect to the database */
gnucomo_database db(&cfg);
- client_message msg(&cin, db);
+ if (db.is_connected())
+ {
+
+ client_message msg(&std::cin, db);
- if (msg.classify(hostname, arrival, service) > 0.9)
+ if (msg.classify(hostname, arrival, service) > 0.9)
+ {
+ msg.enter();
+ }
+ *log << "Gcm_input finished at " << Now() << ".\n";
+ return 0;
+ }
+ else
{
- msg.enter();
+ *log << "gcm_input: Can not connect to database.\n";
+ *log << "Gcm_input finished at " << Now() << ".\n";
+ return 1;
}
-
- return 0;
}