Check the log table against the servies running on an object and
authorarjen <arjen>
Wed, 3 Sep 2003 12:48:48 +0000 (12:48 +0000)
committerarjen <arjen>
Wed, 3 Sep 2003 12:48:48 +0000 (12:48 +0000)
create notifications if a service is not supposed to be available
or is not known at all.

src/gcm_daemon/gcm_daemon.php

index 7a38aba..12ccdde 100755 (executable)
    * DATES *
    First        : November 8th 2002
    Gnucomo-0.0.3: December 6th 2002
+   Gnucomo-0.0.8: September 4th 2003
 
  $Log: gcm_daemon.php,v $
- Revision 1.15  2003-09-02 12:48:09  arjen
+ Revision 1.16  2003-09-03 12:48:48  arjen
+ Check the log table against the servies running on an object and
+ create notifications if a service is not supposed to be available
+ or is not known at all.
+
+ Revision 1.15  2003/09/02 12:48:09  arjen
  BUGFIX: Secondary indices on log_notification were unique.
  Additional information in the 'usr' table: 'display_name' and 'email'.
  Added new issues and services.
@@ -50,7 +56,7 @@
 
 */
 
-// $Id: gcm_daemon.php,v 1.15 2003-09-02 12:48:09 arjen Exp $
+// $Id: gcm_daemon.php,v 1.16 2003-09-03 12:48:48 arjen Exp $
 
 ini_set('include_path', '.:./classes:../phpclasses');
 ini_set('html_errors', 'false');
@@ -188,6 +194,12 @@ if ($dbms->fetch_row() == "TRUE")
 do
 {
 
+   //At this place we start processing new log-lines
+
+   process_log ();
+   service_check();
+   find_notifications();
+
    //  Gather the statistics for each object
 
    $obj_result = $dbms->query("SELECT objectid FROM object");
@@ -198,13 +210,7 @@ do
       GatherStatistics($object->objectid);
    }
 
-  //At this place we start processing new log-lines
-
-  process_log ();
-  //service_check();
-  find_notifications();
-
-  $keep_running = false;
+   $keep_running = false;
 
 } while ($keep_running == true);
 
@@ -227,6 +233,8 @@ function process_log ()
   global $dbms_working;
   global $class_settings;
 
+  $last_log = 0;
+
   // Find records in log that still have to be processed.
 
   $local_sql = "SELECT setting_value FROM db_value WHERE setting = 'log_processing'";
@@ -445,11 +453,36 @@ function service_check()
 {
    global  $dbms;
 
-   $log_res = $dbms->query("SELECT objectid, servicecode,rawdata FROM log");
+   $unknown_notification = 0;
+   $unused_notification  = 0;
+   $last_log             = 0;
+
+   //  How far did we get last time ?
+
+   $lastlogres = $dbms->query("SELECT setting_value FROM db_value
+                               WHERE setting = 'log_servicecheck'");
+
+   if ($dbms->num_rows($lastlogres) == 1)
+   {
+     $last_log = $dbms->Field($lastlogres, 0, 'setting_value');
+   }
+   else
+   {
+      $dbms->query("INSERT INTO db_value (setting, setting_value)
+                            VALUES ('log_servicecheck', '0')");
+   }
+
+   // Query the log-table
+
+   $qry = "SELECT logid, objectid, servicecode FROM log
+           WHERE logid > CAST(".$last_log." AS BIGINT) ORDER BY logid";
+   $log_res = $dbms->query($qry);
+   //$log_res = $dbms->query("SELECT logid, objectid, servicecode,rawdata FROM log");
 
    for ($log_row = 0; $log_row < $dbms->num_rows($log_res); $log_row++)
    {
       $log_entry = $dbms->fetch_object($log_res, $log_row);
+      $last_log  = $log_entry->logid;
 
       //   Check if the service is used on the object.
 
@@ -468,19 +501,40 @@ function service_check()
 
          if ($dbms->num_rows($dbms->query($qry)) == 0)
          {
-            echo "Service " . $log_entry->servicecode . " does not exist.\n";
+            if ($unknown_notification == 0)
+            {
+               $remark = "One or more log entries from a service that is not in the database";
+               $unknown_notification = $dbms->new_notification($log_entry->objectid, 'service unknown', $remark);
+            }
+            if ($unknown_notification != 0)
+            {
+               $insertion = "INSERT INTO log_notification (notificationid, logid) VALUES ('";
+               $insertion .= $unknown_notification . "', '";
+               $insertion .= $log_entry->logid . "')";
+               $dbms->query($insertion);
+            }
          }
          else
          {
-            $qry = "SELECT objectname FROM object WHERE objectid='";
-            $qry .= $log_entry->objectid . "'";
-            $object = $dbms->fetch_object($dbms->query($qry), 0);
-            echo "Service " . $log_entry->servicecode . " is not used on ";
-            echo $object->objectname . ".\n";
+            if ($unused_notification == 0)
+            {
+               $remark = "One or more log entries from a service not running on this object";
+               $unused_notification = $dbms->new_notification($log_entry->objectid, 'service not used', $remark);
+            }
+            if ($unused_notification != 0)
+            {
+               $insertion = "INSERT INTO log_notification (notificationid, logid) VALUES ('";
+               $insertion .= $unused_notification . "', '";
+               $insertion .= $log_entry->logid . "')";
+               $dbms->query($insertion);
+            }
          }
-         echo $log_entry->rawdata . "\n";
       }
    }
+
+   $qry = "UPDATE db_value SET setting_value = '"
+                   . $last_log . "' WHERE setting = 'log_servicecheck'";
+   $dbms->query($qry);
 }
 
 function find_notifications ()