Do not add another parameter_notification record is the notification
[gnucomo.git] / src / gcm_input / message.cpp
index 93560a3..1c36a27 100644 (file)
@@ -8,7 +8,7 @@
 ***********************
 **      FILE NAME      : message.cpp
 **      SYSTEM NAME    : Gnucomo - Gnu Computer Monitoring
-**      VERSION NUMBER : $Revision: 1.13 $
+**      VERSION NUMBER : $Revision: 1.15 $
 **
 **  DESCRIPTION      :  Implementation of the message handling classes
 **
 
 /*****************************
    $Log: message.cpp,v $
-   Revision 1.13  2003-08-16 15:28:45  arjen
+   Revision 1.15  2003-10-27 11:28:27  arjen
+   Do not add another parameter_notification record is the notification
+   already exists for that parameter.
+
+   Revision 1.14  2003/09/01 06:57:14  arjen
+   Reject log entries that are found to be invalid.
+
+   Revision 1.13  2003/08/16 15:28:45  arjen
    Fixed a namespace problem
 
    Revision 1.12  2003/08/11 16:56:16  arjen
@@ -83,7 +90,7 @@
 
 *****************************/
 
-static const char *RCSID = "$Id: message.cpp,v 1.13 2003-08-16 15:28:45 arjen Exp $";
+static const char *RCSID = "$Id: message.cpp,v 1.15 2003-10-27 11:28:27 arjen Exp $";
 
 #include <algorithm>
 #include <libxml/xpath.h>
@@ -440,7 +447,7 @@ double client_message::classify(String host, UTC arriv, String serv)
    }
    else if (!arrival.proper())
    {
-      *log << "Arrival time is not knwon.\n";
+      *log << "Arrival time is not known.\n";
       certainty = 0.0;
    }
    else
@@ -786,45 +793,50 @@ int client_message::enter()
 #ifdef DEBUG
             std::cerr << "\ncooker check: " << pan->check_pattern(line) << "\n";
 #endif
-            pan->cook_this(line, arrival);
-
-            if (pan->hostname() == hostname(0,~pan->hostname()))
+            if (pan->cook_this(line, arrival))
             {
+               if (pan->hostname() == hostname(0,~pan->hostname()))
+               {
 
 #ifdef DEBUG
-               std::cerr << " Information from cooker:\n";
-               std::cerr << "     timestamp = " << pan->timestamp() << "\n";
-               std::cerr << "     hostname  = " << pan->hostname() << "\n";
-               std::cerr << "     service   = " << pan->service() << "\n";
+                  std::cerr << " Information from cooker:\n";
+                  std::cerr << "     timestamp = " << pan->timestamp() << "\n";
+                  std::cerr << "     hostname  = " << pan->hostname() << "\n";
+                  std::cerr << "     service   = " << pan->service() << "\n";
 #endif
-               /*   Insert a new record into the log table   */
+                  /*   Insert a new record into the log table   */
 
-               insertion += "'" + objectid + "',";
-               insertion += "'" + pan->service() + "',";
-               insertion += "'" + pan->timestamp().format("%Y-%m-%d %T") + "',";
-               insertion += "'" + arrival.format("%Y-%m-%d %T") + "',";
-               insertion += "'" + SQL_Escape(line) + "',FALSE";
-               insertion += ")";
+                  insertion += "'" + objectid + "',";
+                  insertion += "'" + pan->service() + "',";
+                  insertion += "'" + pan->timestamp().format("%Y-%m-%d %T") + "',";
+                  insertion += "'" + arrival.format("%Y-%m-%d %T") + "',";
+                  insertion += "'" + SQL_Escape(line) + "',FALSE";
+                  insertion += ")";
 
-               if (testmode)
-               {
-                  *log << insertion << "\n";
+                  if (testmode)
+                  {
+                     *log << insertion << "\n";
+                  }
+                  else
+                  {
+                     database.Query(insertion);
+                  }
+
+                  if (verbose)
+                  {
+                     *log << "\n\n";
+                  }
+
+                  nr_lines++;
                }
                else
                {
-                  database.Query(insertion);
-               }
-
-               if (verbose)
-               {
-                  *log << "\n\n";
+                  *log << "   Hostname " << pan->hostname() << " does not match.\n";
                }
-
-               nr_lines++;
             }
             else
             {
-               *log << "   Hostname " << pan->hostname() << " does not match.\n";
+               *log << "gcm_input WARNING: Not a valid line: " << line << "\n";
             }
             break;
 
@@ -928,15 +940,23 @@ int client_message::enter()
                   {
                      remark = "Gnucomo detected a different version for package parameter(s) ";
                      change_notification = database.new_notification(objectid, "property modified", remark);
+                     change_notification = database.new_notification(objectid, "property modified", remark);
                   }
 
                   if (change_notification != "")
                   {
-                     insertion = "insert into parameter_notification (notificationid, paramid) values ('";
-                     insertion += change_notification + "', '";
-                     insertion += paramid + "')";
+                     qry = "select * from parameter_notification where notificationid='";
+                     qry += change_notification + "' and paramid='";
+                     qry += paramid + "'";
 
-                     database.Query(insertion);
+                     if (database.Query(qry) == 0)
+                     {
+                        insertion = "insert into parameter_notification (notificationid, paramid) values ('";
+                        insertion += change_notification + "', '";
+                        insertion += paramid + "')";
+
+                        database.Query(insertion);
+                     }
                   }
                   else
                   {