apply converting non-numeric values to 'U' after converting 'L' so that 'L' can retur...
[php-utility-classes.git] / include / classes / rrdstat.php-class
index 7810b78a369ed6582b6e3f15f118acccacde9804..5c64af169d9836575b43780619418903b24a5fcf 100644 (file)
@@ -297,8 +297,6 @@ class rrdstat {
         if (strlen($ret)) { $upvals = explode("\n", $ret); }
         ob_end_clean();
       }
-      $walkfunc = create_function('&$val,$key', '$val = is_numeric(trim($val))?trim($val):"U";');
-      array_walk($upvals, $walkfunc);
     }
     else {
       foreach ($this->rrd_fields as $ds) {
@@ -332,9 +330,19 @@ class rrdstat {
           }
         }
         else { $val = null; }
-        $upvals[] = is_null($val)?'U':$val;
       }
     }
+    if (in_array('L', $upvals)) {
+      // for at least one value, we need to set the same as the last recorded value
+      $fvals = $this->fetch();
+      $rowids = array_shift($fvals);
+      $lastvals = array_shift($fvals);
+      foreach (array_keys($upvals, 'L') as $akey) {
+        $upvals[$akey] = $lastvals[$rowids[$akey]];
+      }
+    }
+    $walkfunc = create_function('&$val,$key', '$val = is_numeric(trim($val))?trim($val):"U";');
+    array_walk($upvals, $walkfunc);
     $return = null;
     if (count($upvals)) {
       $update_cmd = 'rrdtool update '.$this->rrd_file.' N:'.implode(':', $upvals);
@@ -378,7 +386,7 @@ class rrdstat {
         foreach ($rows as $row) {
           if (strlen(trim($row))) {
             $rvals = preg_split('/\s+/', $row);
-            $rtime = array_shift($rvals);
+            $rtime = str_replace(':', '', array_shift($rvals));
             $rv_array = array();
             foreach ($rvals as $key=>$rval) {
               $rv_array[$fields[$key]] = ($rval=='nan')?null:floatval($rval);