Code

Updated statistic file generation
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Tue, 7 Sep 2010 05:51:34 +0000 (05:51 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Tue, 7 Sep 2010 05:51:34 +0000 (05:51 +0000)
-Dates were messed up, when reports were not send the same day they were created

git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@19535 594d385d-05f5-0310-b6e9-bd551577e9d8

gosa-core/include/class_stats.inc
gosa-core/plugins/generic/statistics/class_statistics.inc

index 6ea22bffcb9fe15a87af23e7c66252548437a613..ae5be145d2390369664bff3d7ea88f380e145a12 100644 (file)
@@ -334,7 +334,7 @@ class stats
     }
 
     
-    static function getLdapObjectCount($config, $statisticConformResult = FALSE)    
+    static function getLdapObjectCount($config, $statisticConformResult = FALSE, $date = "")    
     {
         $ldap = $config->get_ldap_link();
         $ldap->cd($config->current['BASE']);
@@ -399,12 +399,24 @@ class stats
             $type           = 'objectCount';
             $plugin         = '';
             $action         = '';
-            $date           = date('Y-m-d');
+            $date           = (empty($date))?date('Y-m-d'):$date;
             $memory_usage   = sqlite_escape_string(stats::get_memory_usage());
             $cpu_load       = sqlite_escape_string(number_format(stats::get_cpu_load(),4,'.',''));
             $sql = array();
             foreach($categoryCounter as $category => $amount){
-                $sql[] = array($type, $plugin, $category,$action,$uuid,$date, 0,0,$amount,$memory_usage,$cpu_load,'');
+                $sql[] = array(
+                        "type" => $type,
+                        "plugin" => $plugin,
+                        "category" => $category,
+                        "action" => $action,
+                        "uuid" => $uuid,
+                        "date" => $date,
+                        "duration" => 0,
+                        "render_time" => 0,
+                        "amount" => $amount,
+                        "mem_usage" => $memory_usage,
+                        "load" => $cpu_load,
+                        "info" => '');
             }
             return($sql);
         }else{
index 591345885fa544cf61af6f8097fbfa78c8d9db73..852c7ec6f925a0fcf077f8438b6fd5973e5f52b8 100644 (file)
@@ -158,13 +158,39 @@ class statistics extends plugin
         if(isset($_POST['transmitStatistics'])){
             $this->unsbmittedFiles = $this->getUnsubmittedStatistics();
             foreach($this->unsbmittedFiles as $filename => $date){
+
+                $strDate = date('Y-m-d', $date);
                 $tmp = stats::generateStatisticDump($filename);
                 $dump = array();
+                $invalidDateCount = 0;
                 foreach($tmp as $entry){
+                   
+                    // Check if the result date equals the report file date
+                    //  - If not update the entry. 
+                    if($entry['date'] != $strDate){
+                        $entry['date'] = $strDate;
+                        $invalidDateCount ++;
+                    }
+                    $dump[] = array_values($entry);
+                }
+
+                // Merge result with ldap object count 
+                $objectCount = stats::getLdapObjectCount($this->config, TRUE, date('Y-m-d', $date));
+                foreach($objectCount as $entry){
+
+                    // Check if the result date equals the report file date
+                    //  - If not update the entry. 
+                    if($entry['date'] != $strDate){
+                        $entry['date'] = $strDate;
+                        $invalidDateCount ++;
+                    }
                     $dump[] = array_values($entry);
                 }
-                $objectCount = stats::getLdapObjectCount($this->config, TRUE);
-                $dump = array_merge($dump, $objectCount);
+
+                // Warn about invalid dates transmitted
+                if($invalidDateCount) trigger_error(sprintf("Report contained %s entries with invalid date string!",$invalidDateCount));
+            
+                // Send in our report now.
                 $res = $this->rpcHandle->updateInstanceStatus($dump);
                 if(!$this->rpcHandle->success()){
                     msg_dialog::display(_("Error"),msgPool::rpcError($this->rpcHandle->get_error()),ERROR_DIALOG);