*****************************/
-static const char *RCSID = "$Id: gcm_input.cpp,v 1.16 2011-03-24 10:20:37 arjen Exp $";
-
#include <fstream>
#include <getopt.h>
+#include <unistd.h>
#include "message.h"
#include "log_filter.h"
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";
/*=========================================================================
" [-s service] [-T] [-v] [-V]\n";
gnucomo_config cfg;
- char *config_name = "gnucomo";
+ String config_name("gnucomo");
std::ofstream logfile;
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;
}