Private GIT

Skip to content
Snippets Groups Projects
Commit 07654f91 authored by loiclau's avatar loiclau Committed by Kevin Duret
Browse files

fix(graph) fix export with empty metric

parent 37927ea9
Branches
Tags
No related merge requests found
......@@ -33,7 +33,8 @@
*
*/
function get_error($str){
function get_error($str)
{
echo $str . "<br />";
exit(0);
}
......@@ -55,7 +56,7 @@ if (isset($sid)){
get_error('need session id !');
}
isset($_GET["index"]) ? $index = htmlentities($_GET["index"], ENT_QUOTES, "UTF-8") : $index = NULL;
isset($_GET["index"]) ? $index = htmlentities($_GET["index"], ENT_QUOTES, "UTF-8") : $index = null;
isset($_POST["index"]) ? $index = htmlentities($_POST["index"], ENT_QUOTES, "UTF-8") : $index = $index;
$period = (isset($_POST["period"])) ? htmlentities($_POST["period"], ENT_QUOTES, "UTF-8") : "today";
......@@ -76,10 +77,18 @@ if (isset($hName) && isset($sName)) {
$listMetric = array();
$datas = array();
$DBRESULT = $pearDBO->query("SELECT DISTINCT metric_id, metric_name FROM metrics, index_data WHERE metrics.index_id = index_data.id AND id = '$index' ORDER BY metric_name");
$listEmptyMetric = array();
$query = "SELECT DISTINCT metric_id, metric_name FROM metrics, index_data " .
"WHERE metrics.index_id = index_data.id AND id = '$index' ORDER BY metric_name";
$DBRESULT = $pearDBO->query($query);
while ($index_data = $DBRESULT->fetchRow()) {
$listMetric[$index_data["metric_id"]] = $index_data["metric_name"];
$DBRESULT2 = $pearDBO->query("SELECT ctime,value FROM data_bin WHERE id_metric = '".$index_data["metric_id"]."' AND ctime >= '".htmlentities($_GET["start"], ENT_QUOTES, "UTF-8")."' AND ctime < '".htmlentities($_GET["end"], ENT_QUOTES, "UTF-8")."'");
$listEmptyMetric[$index_data["metric_id"]] = '';
$query2 = "SELECT ctime,value FROM data_bin WHERE id_metric = '" . $index_data["metric_id"] .
"' AND ctime >= '" . htmlentities($_GET["start"], ENT_QUOTES, "UTF-8") .
"' AND ctime < '" . htmlentities($_GET["end"], ENT_QUOTES, "UTF-8") . "'";
$DBRESULT2 = $pearDBO->query($query2);
while ($data = $DBRESULT2->fetchRow()) {
$datas[$data["ctime"]][$index_data["metric_id"]] = $data["value"];
}
......@@ -87,6 +96,11 @@ while ($index_data = $DBRESULT->fetchRow()){
# Order by timestamp
ksort($datas);
foreach ($datas as $key => $data) {
$datas[$key] = $data + $listEmptyMetric;
# Order by metric
ksort($datas[$key]);
}
print "time;humantime";
if (count($listMetric)) {
......@@ -97,7 +111,11 @@ print "\n";
foreach ($datas as $ctime => $tab) {
print $ctime . ";" . date("Y-m-d H:i:s", $ctime);
foreach ($tab as $metric_value) {
if ($metric_value !== '') {
printf(";%f", $metric_value);
} else {
print(";");
}
}
print "\n";
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment