***********************
** FILE NAME : message.cpp
** SYSTEM NAME : Gnucomo - Gnu Computer Monitoring
-** VERSION NUMBER : $Revision: 1.5 $
+** VERSION NUMBER : $Revision: 1.6 $
**
** DESCRIPTION : Implementation of the message handling classes
**
********************************
** ORIGINAL AUTHOR : Arjen Baart - arjen@andromeda.nl
** CREATION DATE : Sep 16, 2002
-** LAST UPDATE : Dec 20, 2002
+** LAST UPDATE : Jan 31, 2003
** MODIFICATIONS :
**************************************************************************/
/*****************************
$Log: message.cpp,v $
- Revision 1.5 2002-12-20 17:42:34 arjen
- BUGFIX: The hostname in a system log may contain digits as well as letters
+ Revision 1.6 2003-02-05 09:37:51 arjen
+ Create notifications when a new package is discovered
+ in a 'rpm -qa' list or when the version of a package is changed.
Revision 1.4 2002/12/06 22:26:28 arjen
Set the value of log.processed to FALSE when inserting a
*****************************/
-static const char *RCSID = "$Id: message.cpp,v 1.5 2002-12-20 17:42:34 arjen Exp $";
+static const char *RCSID = "$Id: message.cpp,v 1.6 2003-02-05 09:37:51 arjen Exp $";
#include "message.h"
** VARS CHANGED :
** FUNCTIONS USED :
** SEE ALSO :
-** LAST MODIFIED : Nov 29, 2002
+** LAST MODIFIED : Jan 31, 2003
**=========================================================================
*/
long nr_lines = 0;
String line;
+ String change_notification("");
+ String create_notification("");
+
+
/* Double-check the classification of the message */
if (classification == UNKNOWN || certainty < 0.9 || gpg_encrypted)
insertion += "'" + objectid + "',";
insertion += "'" + rest(0,i) + "',";
- insertion += "'" + log_date.format() + " " + log_time.format() + "',";
- insertion += "'" + arrival.format() + "',";
+ insertion += "'" + log_date.format("%Y-%m-%d") + " " + log_time.format() + "',";
+ insertion += "'" + arrival.format("%Y-%m-%d %T") + "',";
insertion += "'" + SQL_Escape(line) + "',FALSE";
insertion += ")";
}
insertion += "'" + objectid + "',";
insertion += "'" + service + "',";
- insertion += "'" + log_date.format() + " " + log_time.format() + "',";
- insertion += "'" + arrival.format() + "',";
+ insertion += "'" + log_date.format("%Y-%m-%d") + " " + log_time.format() + "',";
+ insertion += "'" + arrival.format("%Y-%m-%d %T") + "',";
insertion += "'" + SQL_Escape(line) + "',FALSE";
insertion += ")";
}
insertion += "'" + objectid + "',";
insertion += "'" + service + "',";
- insertion += "'" + log_date.format() + " " + log_time.format() + "',";
- insertion += "'" + arrival.format() + "',";
+ insertion += "'" + log_date.format("%Y-%m-%d") + " " + log_time.format() + "',";
+ insertion += "'" + arrival.format("%Y-%m-%d %T") + "',";
insertion += "'" + SQL_Escape(line) + "',FALSE";
insertion += ")";
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 ^[-=] \
+ // 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.
+ String qry = "select count(paramid) from parameter where objectid='";
+ qry += objectid + "' and class='package'";
+
+ database.Query(qry);
+ long n_packages = String(database.Field(0, "count"));
+
+ bool initial_entry = n_packages == 0;
+
i = line.index('-');
while (!(line[i] == '-' && isdigit(line[i + 1])))
{
String package(line(0,i));
String version(line(i+1, ~line));
String paramid;
+ String remark;
+ String insert_h;
if (verbose)
{
// Construct a qry to check the package's existance
- String qry = "select paramid from parameter where objectid='";
+ qry = "select paramid from parameter where objectid='";
qry += objectid + "' and class='package' and name='";
qry += package + "'";
{
std::cout << " Parameter " << package << " has different version\n";
}
+ insertion = "update property set value='";
+ insertion += version + "' where paramid='";
+ insertion += paramid + "' and name='version'";
+
+ insert_h = "insert into history (paramid, modified, change_nature, changed_property, new_value)";
+ insert_h += " values ('";
+ insert_h += paramid + "', '" + arrival.format("%Y-%m-%d %T") + "', 'MODIFIED', 'version', '";
+ insert_h += version + "')";
+
+ database.Query(insertion);
+ database.Query(insert_h);
+
+ if (change_notification == "")
+ {
+ remark = "Gnucomo detected a different version for package parameter(s) ";
+ change_notification = database.new_notification(objectid, "property modified", remark);
+ }
+
+ insertion = "insert into parameter_notification (notificationid, paramid) values ('";
+ insertion += change_notification + "', '";
+ insertion += paramid + "')";
+
+ database.Query(insertion);
}
else
{
}
else
{
- String insert_h;
if (verbose)
{
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 += paramid + "', '" + arrival.format("%Y-%m-%d %T") + "', 'CREATED', 'version', '";
insert_h += version + "')";
if (testmode)
{
database.Query(insertion);
database.Query(insert_h);
+ if (!initial_entry)
+ {
+ if (create_notification == "")
+ {
+ remark = "Gnucomo detected new parameter(s) of class package";
+ create_notification = database.new_notification(objectid, "parameter created", remark);
+ }
+ insertion = "insert into parameter_notification (notificationid, paramid) values ('";
+ insertion += create_notification + "', '";
+ insertion += paramid + "')";
+
+ database.Query(insertion);
+ }
}
}