/** * Output data as a JSON response. * * @api * @uses \setHttpResponseCode() * * @param mixed[] $data The data to output in JSON format. * @param int $httpResponseCode The HTTP response code to return. * * @return void */ function jsonResponse($data, $httpResponseCode = 200) { if (gettype($data) === 'resource') { throw new \InvalidArgumentException(__FUNCTION__ . ' cannot use a resource as the first argument.'); } setHttpResponseCode($httpResponseCode); // Set the HTTP headers appropriately for AJAX. header('Expires: 0'); header('Cache-Control: no-cache, must-revalidate, post-check=0, pre-check=0'); header('Pragma: no-cache'); header('Content-type: application/json; charset=utf-8'); echo json_encode($data); }
//require("login/login.php"); include 'monitor.inc'; include_once 'graph_functions.inc'; include_once 'jash/functions.inc'; include_once 'jash/staticGraphFunctions.inc'; include_once 'firephp/0.3.2/fb.php'; switch ($_GET['type']) { case 'graph': $graphType = 'graph'; break; case 'histogram': $graphType = 'histogram'; break; default: setHttpResponseCode('404'); echo 'Unknown type'; die; } $filePath = 'graph/staticGraphData/' . $graphType . '/'; $fileName = $_GET['id'] . '.json.gz'; if (!file_exists($filePath . generateSubDirs($fileName) . $fileName)) { setHttpResponseCode('404'); echo 'Data missing'; die; } $fileContent = implode(gzfile($filePath . generateSubDirs($fileName) . $fileName)); $graphCreationDate = date("Y-m-d H:i:s", filemtime($filePath . generateSubDirs($fileName) . $fileName)); $smarty->assign('data', $fileContent); $smarty->assign('graphType', $graphType); $smarty->assign('graphCreationDate', $graphCreationDate); $smarty->display('report/staticGraph.tpl');
foreach ($sanitizedData['job_id'] as $key => $jobId) { $job = $jobTable->find($jobId); $resultDataset[$jobId] = getGraphData($jobId, $sanitizedData['startTimestamp'], $sanitizedData['endTimestamp'], $sanitizedData['percentile'], $sanitizedData['trimAbove'], $sanitizedData['adjustUsing'], $sanitizedData['trimBelow'], $sanitizedData['todStartHour'], $sanitizedData['todEndHour'], $fieldsSerialized); $resultDataset[$jobId] = array('jobId' => $job['Id'], 'jobName' => $job['Label'], 'dataSet' => getResultsDataAvgMod($sanitizedData['startTimestamp'], $sanitizedData['endTimestamp'], $sanitizedData['interval'], $resultDataset[$jobId], $fieldsArray, $sanitizedData['aggregateMethod'])); } $response['status'] = 200; $response['message'] = 'OK'; $response['results']['series'] = $resultDataset; $response['results']['metrics'] = $requestData['fields']; $response['results']['jobs'] = $sanitizedData['job_id']; $response['results']['interval'] = $sanitizedData['interval']; $response['results']['datarange'] = array('start' => $sanitizedData['startTimestamp'], 'end' => $sanitizedData['endTimestamp']); } catch (exception $e) { $response['status'] = 500; $response['message'] = $e->getMessage(); setHttpResponseCode(500); } echo json_encode($response); die; /** * @param $startDateTime integer * @param $endDateTime integer * @param $interval integer * @param $datas array * @param $fields array * @param $aggregateMethod * @return array */ function getResultsDataAvgMod($startDateTime, $endDateTime, $interval, $datas, $fields, $aggregateMethod) { $results = getResultsDataAvg($startDateTime, $endDateTime, $interval, $datas, $fields, $aggregateMethod);