***********************
** FILE NAME : message.cpp
** SYSTEM NAME : Gnucomo - Gnu Computer Monitoring
-** VERSION NUMBER : $Revision: 1.3 $
+** VERSION NUMBER : $Revision: 1.4 $
**
** DESCRIPTION : Implementation of the message handling classes
**
********************************
** ORIGINAL AUTHOR : Arjen Baart - arjen@andromeda.nl
** CREATION DATE : Sep 16, 2002
-** LAST UPDATE : Nov 04, 2002
+** LAST UPDATE : Nov 29, 2002
** MODIFICATIONS :
**************************************************************************/
/*****************************
$Log: message.cpp,v $
- Revision 1.3 2002-11-09 08:04:27 arjen
+ Revision 1.4 2002-12-06 22:26:28 arjen
+ Set the value of log.processed to FALSE when inserting a
+ new log entry into the database
+ When a syslog entry arrives from last year, gcm_input subtracts one from the
+ year of arrival to create the year of the log entry.
+ Read output from "rpm -qa" and enter packages in the parameter table.
+
+ 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
*****************************/
-static const char *RCSID = "$Id: message.cpp,v 1.3 2002-11-09 08:04:27 arjen Exp $";
+static const char *RCSID = "$Id: message.cpp,v 1.4 2002-12-06 22:26:28 arjen Exp $";
#include "message.h"
static const regex re_dump("^ *DUMP: Date of this level");
static const regex re_accesslog("(GET|POST) .+ HTTP");
static const regex re_errorlog("^\\[" + unix_date_re + "\\] \\[(error|notice)\\] .+");
+static const regex re_rpm("[[:alnum:]+-]+-[0-9][[:alnum:].-]");
static const regex re_syslog_date("[[:alpha:]]{3} [ 123][0-9] [0-9]{2}:[0-9]{2}:[0-9]{2}");
static const regex re_uxmail_from("^From - " + unix_date_re);
** VARS CHANGED :
** FUNCTIONS USED :
** SEE ALSO :
-** LAST MODIFIED : Nov 04, 2002
+** LAST MODIFIED : Nov 16, 2002
**=========================================================================
*/
std::cout << "HTTP error log detected.\n";
}
}
+ else if (line == re_rpm)
+ {
+ certainty = 1.0;
+ classification = RPMLIST;
+ service = "";
+ if (verbose)
+ {
+ std::cout << "RPM package list detected.\n";
+ }
+ }
}
input.rewind();
** VARS CHANGED :
** FUNCTIONS USED :
** SEE ALSO :
-** LAST MODIFIED : Nov 04, 2002
+** LAST MODIFIED : Nov 29, 2002
**=========================================================================
*/
case ERRORLOG:
check = &re_errorlog;
break;
+ case RPMLIST:
+ check = &re_rpm;
+ break;
}
if (line == *check)
int i;
String insertion("insert into log (objectid, servicecode,"
- " object_timestamp, timestamp, rawdata) values (");
+ " object_timestamp, timestamp, rawdata, processed) values (");
String datestring;
switch (classification)
log_time = line;
if (log_date.Year() < 0 || log_date.Year() > 2500)
{
- // The year is not in the log file. Assume the year of arrival
+ // The year is not in the log file. Assume the year of arrival,
+ // unless this puts the log entry at a later date than the arrival date.
+ // This happens e.g. when a log entry from December arrives in Januari.
log_date = date(log_date.Day(), log_date.Month(), date(arrival).Year());
+ if (log_date > date(arrival))
+ {
+ log_date = date(log_date.Day(), log_date.Month(), date(arrival).Year() - 1);
+ }
}
if (verbose)
insertion += "'" + rest(0,i) + "',";
insertion += "'" + log_date.format() + " " + log_time.format() + "',";
insertion += "'" + arrival.format() + "',";
- insertion += "'" + SQL_Escape(line) + "'";
+ insertion += "'" + SQL_Escape(line) + "',FALSE";
insertion += ")";
if (testmode)
insertion += "'" + service + "',";
insertion += "'" + log_date.format() + " " + log_time.format() + "',";
insertion += "'" + arrival.format() + "',";
- insertion += "'" + SQL_Escape(line) + "'";
+ insertion += "'" + SQL_Escape(line) + "',FALSE";
insertion += ")";
if (testmode)
insertion += "'" + service + "',";
insertion += "'" + log_date.format() + " " + log_time.format() + "',";
insertion += "'" + arrival.format() + "',";
- insertion += "'" + SQL_Escape(line) + "'";
+ insertion += "'" + SQL_Escape(line) + "',FALSE";
insertion += ")";
if (testmode)
nr_lines++;
break;
+
+ case RPMLIST:
+ // Scan a list of packages and versions from "rpm -a".
+ // A similar listing can be created on IRIX 6.5 by using the
+ // command "showprods -3 -n|awk '{printf "%s-%s\n",$2,$3}'|grep -v ^[-=] \
+ // |grep -v Version-Description".
+ //
+ // We have to separate the package name and the version.
+ // The separation is marked by a '-', followed by a digit.
+
+ i = line.index('-');
+ while (!(line[i] == '-' && isdigit(line[i + 1])))
+ {
+ i++;
+ }
+ String package(line(0,i));
+ String version(line(i+1, ~line));
+ String paramid;
+
+ if (verbose)
+ {
+ std::cout << "Package is " << package;
+ std::cout << ", version is " << version << "\n";
+ }
+
+ // Construct a qry to check the package's existance
+
+ String qry = "select paramid from parameter where objectid='";
+ qry += objectid + "' and class='package' and name='";
+ qry += package + "'";
+
+ if (database.Query(qry) == 1)
+ {
+ paramid = database.Field(0, "paramid");
+ qry = "select value from property where paramid='";
+ qry += paramid + "' and name='version'";
+ if (database.Query(qry) == 0)
+ {
+ std::cerr << "Database corruption: Package " << package;
+ std::cerr << " does not have a 'version' property.\n";
+ }
+ else if (database.Field(0, "value") != version)
+ {
+ if (verbose)
+ {
+ std::cout << " Parameter " << package << " has different version\n";
+ }
+ }
+ else
+ {
+ if (verbose)
+ {
+ std::cout << " Parameter " << package << " has not changed.\n";
+ }
+ }
+ }
+ else
+ {
+ String insert_h;
+
+ if (verbose)
+ {
+ std::cout << " Parameter " << package << " does not exist.\n";
+ }
+ // Create a new package parameter, including version property and history record
+
+ insertion = "insert into parameter (objectid, name, class, description) values ('";
+ insertion += objectid + "', '" + package + "', 'package', 'RPM package " + package + "')";
+ if (testmode)
+ {
+ paramid = "0";
+ std::cout << insertion << "\n";
+ }
+ else
+ {
+ database.Query(insertion);
+ qry = "select paramid from parameter where objectid='";
+ qry += objectid + "' and class='package' and name='";
+ qry += package + "'";
+ database.Query(qry);
+ paramid = database.Field(0, "paramid");
+ }
+
+ insertion = "insert into property (paramid, name, value, type) values ('";
+ insertion += paramid + "', 'version', '";
+ insertion += version + "', 'STATIC')";
+ insert_h = "insert into history (paramid, modified, change_nature, changed_property, new_value)";
+ insert_h += " values ('";
+ insert_h += paramid + "', '" + arrival.format() + "', 'CREATED', 'version', '";
+ insert_h += version + "')";
+
+ if (testmode)
+ {
+ std::cout << insertion << "\n" << insert_h << "\n";
+ }
+ else
+ {
+ database.Query(insertion);
+ database.Query(insert_h);
+ }
+ }
+
+ if (verbose)
+ {
+ std::cout << "\n";
+ }
+
+ nr_lines++;
+ break;
+
}
}
else