X-Git-Url: http://www.andromeda.nl/gitweb/?a=blobdiff_plain;f=src%2Fgcm_input%2Fgcm_input.cpp;h=137fb69a5666da9896fd0e6b81715bd92ddd9af0;hb=dbac585e5c4080e95d4c4507d513ac5bc2ea011c;hp=d8bdb8ae789d39a8899dd375216fc70f09ca3ebd;hpb=62e25e5ccbfba86ce29ac2484770ff4ab2e24ff5;p=gnucomo.git diff --git a/src/gcm_input/gcm_input.cpp b/src/gcm_input/gcm_input.cpp index d8bdb8a..137fb69 100644 --- a/src/gcm_input/gcm_input.cpp +++ b/src/gcm_input/gcm_input.cpp @@ -7,7 +7,7 @@ *********************** ** FILE NAME : gcm_input.cpp ** SYSTEM NAME : Gnucomo - Gnu Computer Monitoring -** VERSION NUMBER : $Revision: 1.3 $ +** VERSION NUMBER : $Revision: 1.7 $ ** ** DESCRIPTION : Application to store client messages into the database ** The client message contains a log file from one of the @@ -34,6 +34,7 @@ ** -c Configuration name (default = gnucomo). ** -d Date and time of log arrival. ** -h FQDN of the client. +** -i Incremental - partial list of parameters. ** -s Service that created the log. ** -T Test mode. Do not alter the database. ** -v Verbose (debug) output. @@ -47,13 +48,38 @@ ******************************** ** ORIGINAL AUTHOR : Arjen Baart - arjen@andromeda.nl ** CREATION DATE : Aug 29, 2002 -** LAST UPDATE : Nov 04, 2002 +** LAST UPDATE : Aug 11, 2003 ** MODIFICATIONS : **************************************************************************/ /***************************** $Log: gcm_input.cpp,v $ - Revision 1.3 2002-11-09 08:04:27 arjen + Revision 1.7 2003-08-14 10:28:37 arjen + Use parameters from a new section 'logging' with three configuration parameters: + method - Output method to use for logging. + destination - Name of the log output destination. + level - Log level: Verbose output if greater than 0. + + Revision 1.6 2003/08/11 16:56:16 arjen + Different kinds of log files are parsed by a collection of objects + of different classes, derived from the base class line_cooker + Depending on the message content or the message_type element in + XML, one of these objects is selected. + + Logrunner is integrated with gcm_input. Although its functionality + is still limited, a connection between logrunner and gcm_input + is beginning to form. + + 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 @@ -64,16 +90,24 @@ *****************************/ -static const char *RCSID = "$Id: gcm_input.cpp,v 1.3 2002-11-09 08:04:27 arjen Exp $"; +static const char *RCSID = "$Id: gcm_input.cpp,v 1.7 2003-08-14 10:28:37 arjen Exp $"; + +#include #include #include "message.h" +#include "syslog_cooker.h" +#include "irix_syslog_cooker.h" +#include "access_cooker.h" +#include "error_cooker.h" bool verbose = false; bool testmode = false; +bool incremental = false; +std::ostream *log = &std::cerr; -static char *Version = "gcm_input version 0.0.4 - Nov 05, 2002"; +static char *Version = "gcm_input version 0.0.7 - Jul 24, 2003"; /*========================================================================= @@ -91,17 +125,19 @@ static char *Version = "gcm_input version 0.0.4 - Nov 05, 2002"; ** VARS CHANGED : ** FUNCTIONS USED : ** SEE ALSO : -** LAST MODIFIED : Sep 30, 2002 +** LAST MODIFIED : Aug 11, 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 */ @@ -109,8 +145,8 @@ int main(int argc, char *argv[]) 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) { @@ -135,6 +171,10 @@ int main(int argc, char *argv[]) service = optarg; break; + case 'i': + incremental = true; + break; + case 'T': testmode = true; break; @@ -153,14 +193,6 @@ int main(int argc, char *argv[]) exit(1); } } - - if (verbose) - { - std::cout << "Hostname = " << hostname; - std::cout << " Arrival = " << arrival; - std::cout << " Service = " << service << "\n"; - } - /* Get the configuration file */ if (!cfg.read(config_name)) @@ -169,22 +201,66 @@ int main(int argc, char *argv[]) exit(1); } + String log_method = cfg.find_parameter("logging", "method"); + String log_destination = cfg.find_parameter("logging", "destination"); + int level = cfg.find_parameter("gcm_input", "level"); + + if (log_method == "file" && log_destination != "") + { + std::cerr << "Logging to " << log_destination << ".\n"; + logfile.open(log_destination, _IO_APPEND); // for gcc 2 + //logfile.open(logfile_name, std::ios_base::app); // for gcc 3 + if (!logfile) + { + std::cerr << "Can't open logfile " << log_destination << " for writing.\n"; + } + else + { + log = &logfile; + verbose = verbose || level > 0; + } + } + + *log << "Gcm_input starting at " << Now() << ".\n"; + if (verbose) { - std::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(&std::cin, db); + if (db.is_connected()) + { - if (msg.classify(hostname, arrival, service) > 0.9) + client_message msg(&std::cin, db); + syslog_cooker slc; + irix_syslog_cooker islc; + access_cooker alc; + error_cooker elc; + + msg.add_cooker(&slc); + msg.add_cooker(&islc); + msg.add_cooker(&alc); + msg.add_cooker(&elc); + + 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; }