From 418a716cc0fb8cb19aa1b6d6aa74eb0db3a21d07 Mon Sep 17 00:00:00 2001 From: arjen Date: Wed, 5 Feb 2003 09:37:51 +0000 Subject: [PATCH] Create notifications when a new package is discovered in a 'rpm -qa' list or when the version of a package is changed. --- src/gcm_input/message.cpp | 82 ++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 66 insertions(+), 16 deletions(-) diff --git a/src/gcm_input/message.cpp b/src/gcm_input/message.cpp index dac561a..4d5b962 100644 --- a/src/gcm_input/message.cpp +++ b/src/gcm_input/message.cpp @@ -8,7 +8,7 @@ *********************** ** 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 ** @@ -20,14 +20,15 @@ ******************************** ** 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 @@ -47,7 +48,7 @@ *****************************/ -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" @@ -280,7 +281,7 @@ double client_message::classify(String host, UTC arriv, String serv) ** VARS CHANGED : ** FUNCTIONS USED : ** SEE ALSO : -** LAST MODIFIED : Nov 29, 2002 +** LAST MODIFIED : Jan 31, 2003 **========================================================================= */ @@ -289,6 +290,10 @@ int client_message::enter() 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) @@ -402,8 +407,8 @@ int client_message::enter() 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 += ")"; @@ -442,8 +447,8 @@ int client_message::enter() } 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 += ")"; @@ -476,8 +481,8 @@ int client_message::enter() } 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 += ")"; @@ -501,12 +506,20 @@ int client_message::enter() 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]))) { @@ -515,6 +528,8 @@ int client_message::enter() String package(line(0,i)); String version(line(i+1, ~line)); String paramid; + String remark; + String insert_h; if (verbose) { @@ -524,7 +539,7 @@ int client_message::enter() // 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 + "'"; @@ -544,6 +559,29 @@ int client_message::enter() { 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 { @@ -555,7 +593,6 @@ int client_message::enter() } else { - String insert_h; if (verbose) { @@ -585,7 +622,7 @@ int client_message::enter() 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) @@ -596,6 +633,19 @@ int client_message::enter() { 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); + } } } -- 2.11.0