that function takes two arguments per spec
[php-utility-classes.git] / include / classes / rrdstat.php-class
index 9e2a747b9da4e41b5b6847f135f3025dc8437ee5..6eed1bf259c75360e3aab44cac1ed2cfc3a78df0 100644 (file)
@@ -138,9 +138,10 @@ class rrdstat {
         }
       }
     }
-    $output = array(); $return_var = null;
-    exec($create_cmd, $output, $return_var);
-    if ($return_var) { trigger_error('rrd create returned with value '.$return_var, E_USER_WARNING); }
+    $return = `$create_cmd 2>&1`;
+    if (strpos($return, 'ERROR') !== false) {
+      trigger_error($this->rrd_file.' - rrd create error: '.$return, E_USER_WARNING);
+    }
     else { $this->status = 'ok'; }
   }
 
@@ -156,6 +157,8 @@ class rrdstat {
         $upvals = explode("\n", ob_get_contents());
         ob_end_clean();
       }
+      $walkfunc = create_function('&$val,$key', '$val = is_numeric($val)?$val:"U";');
+      array_walk($upvals, $walkfunc);
     }
     else {
       foreach ($this->rrd_fields as $ds) {
@@ -193,9 +196,13 @@ class rrdstat {
       }
     }
     $update_cmd = 'rrdtool update '.$this->rrd_file.' N:'.implode(':', $upvals);
-    $output = array(); $return_var = null;
-    exec($update_cmd, $output, $return_var);
-    if ($return_var) { trigger_error('rrd update returned with value '.$return_var, E_USER_WARNING); }
+    $return = `$update_cmd 2>&1`;
+
+    if (strpos($return, 'ERROR') !== false) {
+      trigger_error($this->rrd_file.' - rrd update error: '.$return, E_USER_WARNING);
+      $success = false;
+    }
+    else { $success = true; }
   return ($return_var == 0);
   }
 
@@ -216,7 +223,7 @@ class rrdstat {
     $return = `$fetch_cmd 2>&1`;
 
     if (strpos($return, 'ERROR') !== false) {
-      trigger_error('rrd fetch error: '.$return, E_USER_WARNING);
+      trigger_error($this->rrd_file.' - rrd fetch error: '.$return, E_USER_WARNING);
       $fresult = false;
     }
     else {
@@ -457,7 +464,7 @@ class rrdstat {
     $return = `$graph_cmd 2>&1`;
 
     if (strpos($return, 'ERROR') !== false) {
-      trigger_error('rrd graph error: '.$return, E_USER_WARNING);
+      trigger_error($this->rrd_file.' - rrd graph error: '.$return, E_USER_WARNING);
       $return = $graph_cmd."\n\n".$return;
     }
     $return = 'file:'.$fname."\n".$return;