X-Git-Url: http://www.andromeda.nl/gitweb/?a=blobdiff_plain;f=src%2Fgcm_input%2Fgcm_input.cpp;fp=src%2Fgcm_input%2Fgcm_input.cpp;h=a4b8937ab564e62f517e59c6c72c2baffeed3dfc;hb=4a52cee10938e535569bce9e46f82d8e05977200;hp=8f9a6047471cc13b4db9df19e4c6d31d906e1688;hpb=a85e804fd7f87a4d067ef31a634b54bd6106c0f5;p=gnucomo.git diff --git a/src/gcm_input/gcm_input.cpp b/src/gcm_input/gcm_input.cpp index 8f9a604..a4b8937 100644 --- a/src/gcm_input/gcm_input.cpp +++ b/src/gcm_input/gcm_input.cpp @@ -125,11 +125,10 @@ *****************************/ -static const char *RCSID = "$Id: gcm_input.cpp,v 1.16 2011-03-24 10:20:37 arjen Exp $"; - #include #include +#include #include "message.h" #include "log_filter.h" @@ -147,7 +146,7 @@ bool testmode = false; bool incremental = false; std::ostream *Log = &std::cerr; -static char Version[] = "gcm_input version 0.0.11 - Nov 22, 2007"; +static char Version[] = "gcm_input version 0.0.13 - Sep 22, 2020"; /*========================================================================= @@ -280,57 +279,72 @@ int main(int argc, char *argv[]) gnucomo_database db(&cfg); - if (db.is_connected()) - { + int gcm_input_result = 0; + + + client_message msg(&std::cin, db); + + double message_probability; - client_message msg(&std::cin, db); - - double message_probability; - - message_filter shortcircuit(hostname, arrival, service); - log_filter lf(hostname, arrival, service); - rpm_filter rf(hostname, arrival, service); - df_filter df(hostname, arrival, service); - - syslog_cooker slc; - irix_syslog_cooker islc; - access_cooker alc; - error_cooker elc; - xml_cooker xlc; - rpm_cooker rlc; - df_cooker dlc; - - msg.add_cooker(&xlc, &shortcircuit); - msg.add_cooker(&slc, &lf); - msg.add_cooker(&islc, &lf); - msg.add_cooker(&alc, &lf); - msg.add_cooker(&elc, &lf); - msg.add_cooker(&rlc, &rf); - msg.add_cooker(&dlc, &df); - - message_probability = msg.classify(hostname, arrival, service); - if (message_probability > 0.75) + message_filter shortcircuit(hostname, arrival, service); + log_filter lf(hostname, arrival, service); + rpm_filter rf(hostname, arrival, service); + df_filter df(hostname, arrival, service); + + syslog_cooker slc; + irix_syslog_cooker islc; + access_cooker alc; + error_cooker elc; + xml_cooker xlc; + rpm_cooker rlc; + df_cooker dlc; + + msg.add_cooker(&xlc, &shortcircuit); + msg.add_cooker(&slc, &lf); + msg.add_cooker(&islc, &lf); + msg.add_cooker(&alc, &lf); + msg.add_cooker(&elc, &lf); + msg.add_cooker(&rlc, &rf); + msg.add_cooker(&dlc, &df); + + message_probability = msg.classify(hostname, arrival, service); + if (message_probability > 0.75) + { + try { - try + if (msg.enter() < 0) { - msg.enter(); - } - catch (std::exception &e) - { - *Log << "Caught an exception: " << e.what() << "\n"; + // Can not store the input in the database. Dump the message in a file. + + String spool_dir = cfg.find_parameter("spool", "directory"); + String pid(getpid()); + String xmlfilename; + + if (spool_dir) + { + xmlfilename = spool_dir + "/"; + } + xmlfilename += "gnucomo" + pid + ".xml"; + + msg.saveXML(xmlfilename); + + // Report the error to the log and stderr. + *Log << "Entering the content into the database failed. XML content stored in " + xmlfilename + "\n"; + std::cerr << "Entering the content into the database failed. XML content stored in " + xmlfilename + "\n"; + + gcm_input_result = 1; } } - else + catch (std::exception &e) { - *Log << "Cannot determine message type with sufficient certainty.\n"; + *Log << "Caught an exception: " << e.what() << "\n"; } - return 0; } else { - *Log << "gcm_input: Can not connect to database.\n"; - *Log << "Gcm_input finished at " << Now() << ".\n"; - return 1; + *Log << "Cannot determine message type with sufficient certainty.\n"; } + + return gcm_input_result; }