Set the value of log.processed to FALSE when inserting a
authorarjen <arjen>
Fri, 6 Dec 2002 22:26:28 +0000 (22:26 +0000)
committerarjen <arjen>
Fri, 6 Dec 2002 22:26:28 +0000 (22:26 +0000)
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.

src/gcm_input/message.cpp
src/gcm_input/message.h

index 0859655..282df52 100644 (file)
@@ -8,7 +8,7 @@
 ***********************
 **      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
@@ -37,7 +44,7 @@
 
 *****************************/
 
-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"
 
@@ -112,6 +119,7 @@ static const regex re_PGP("-----BEGIN PGP MESSAGE-----");
 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);
@@ -132,7 +140,7 @@ static const regex re_email_user("[[:alnum:]_.-]+@");
 **  VARS CHANGED   :
 **  FUNCTIONS USED :
 **  SEE ALSO       :
-**  LAST MODIFIED  : Nov 04, 2002
+**  LAST MODIFIED  : Nov 16, 2002
 **=========================================================================
 */
 
@@ -226,6 +234,16 @@ double client_message::classify(String host, UTC arriv, String serv)
              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();
 
@@ -259,7 +277,7 @@ double client_message::classify(String host, UTC arriv, String serv)
 **  VARS CHANGED   :
 **  FUNCTIONS USED :
 **  SEE ALSO       :
-**  LAST MODIFIED  : Nov 04, 2002
+**  LAST MODIFIED  : Nov 29, 2002
 **=========================================================================
 */
 
@@ -324,6 +342,9 @@ int client_message::enter()
       case ERRORLOG:
             check = &re_errorlog;
             break;
+      case RPMLIST:
+            check = &re_rpm;
+            break;
       }
 
       if (line == *check)
@@ -333,7 +354,7 @@ int client_message::enter()
          int    i;
 
          String insertion("insert into log (objectid, servicecode,"
-                           " object_timestamp, timestamp, rawdata) values (");
+                           " object_timestamp, timestamp, rawdata, processed) values (");
          String datestring;
 
          switch (classification)
@@ -343,9 +364,15 @@ int client_message::enter()
             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)
@@ -374,7 +401,7 @@ int client_message::enter()
                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)
@@ -414,7 +441,7 @@ int client_message::enter()
             insertion += "'" + service + "',";
             insertion += "'" + log_date.format() + " " + log_time.format() + "',";
             insertion += "'" + arrival.format() + "',";
-            insertion += "'" + SQL_Escape(line) + "'";
+            insertion += "'" + SQL_Escape(line) + "',FALSE";
             insertion += ")";
             
             if (testmode)
@@ -448,7 +475,7 @@ int client_message::enter()
             insertion += "'" + service + "',";
             insertion += "'" + log_date.format() + " " + log_time.format() + "',";
             insertion += "'" + arrival.format() + "',";
-            insertion += "'" + SQL_Escape(line) + "'";
+            insertion += "'" + SQL_Escape(line) + "',FALSE";
             insertion += ")";
             
             if (testmode)
@@ -467,6 +494,116 @@ int client_message::enter()
 
             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
index baba95d..c4489e3 100644 (file)
@@ -8,7 +8,7 @@
 ***********************
 **      FILE NAME      : message.h
 **      SYSTEM NAME    : 
-**      VERSION NUMBER : $Revision: 1.3 $
+**      VERSION NUMBER : $Revision: 1.4 $
 **
 **  DESCRIPTION      :  Classes to for handling client messages
 **
 
 /*****************************
    $Log: message.h,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
@@ -37,7 +44,7 @@
 
 *****************************/
 
-/* static const char *RCSID = "$Id: message.h,v 1.3 2002-11-09 08:04:27 arjen Exp $"; */
+/* static const char *RCSID = "$Id: message.h,v 1.4 2002-12-06 22:26:28 arjen Exp $"; */
 
 #include <iostream>
 #include <list>
@@ -141,7 +148,7 @@ class client_message
    double     certainty;     //  How certain are we about the message
    enum
    {
-      UNKNOWN, SYSLOG, ACCESSLOG, ERRORLOG
+      UNKNOWN, SYSLOG, ACCESSLOG, ERRORLOG, RPMLIST
    }  classification;