Skip to content

Commit

Permalink
Merge pull request #136 from frgithubaccount/timestamp_added_to_csv_e…
Browse files Browse the repository at this point in the history
…xport

address behaviour of rrdtool1.5+ to not export timestamp by default
  • Loading branch information
lingej committed Jul 25, 2017
2 parents 9b236ab + a6d949d commit 1480aa0
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion share/pnp/application/models/data.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -1019,13 +1019,23 @@ public function xml2csv($string){
foreach($xml->meta->legend->entry as $key=>$value){ foreach($xml->meta->legend->entry as $key=>$value){
$csv .= ";" . $value ; $csv .= ";" . $value ;
} }

/*
* from rrdtool 1.5 on, timestamp ( value->t ) is not set anymore
* from 1.6 on it can be reactivated by -- showrime option to rrdtool xport
* here we take care of the timestamp ourselves regardless which
* rrdtool version is used
*/
$timestamp2 = $xml->meta->start;
$step = $xml->meta->step;
$csv .= "\n"; $csv .= "\n";
foreach($xml->data->row as $key=>$value){ foreach($xml->data->row as $key=>$value){
$csv .= (string) $value->t ; $csv .= $timestamp2;
foreach($value->v as $item){ foreach($value->v as $item){
$csv .= ";".floatval((string) $item); $csv .= ";".floatval((string) $item);
} }
$csv .= "\n"; $csv .= "\n";
$timestamp2 = $timestamp2 + $step;
} }
return $csv; return $csv;
} }
Expand Down

0 comments on commit 1480aa0

Please sign in to comment.