mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-09-22 17:37:45 +02:00
Allow monitoring/Controller to handle rendering errors while serving JSON or CSV
refs #13623
This commit is contained in:
parent
75ad40f5a3
commit
735a4cb152
@ -25,6 +25,7 @@ class Csv
|
||||
{
|
||||
$csv = new static();
|
||||
$csv->query = $query;
|
||||
$csv->render();
|
||||
return $csv;
|
||||
}
|
||||
|
||||
@ -50,10 +51,10 @@ class Csv
|
||||
$first = true;
|
||||
foreach ($this->query as $row) {
|
||||
if ($first) {
|
||||
$this->renderBuffer->append($this->renderRow(array_keys((array)$row)));
|
||||
$this->renderBuffer->append($this->renderRow(array_keys((array) $row)));
|
||||
$first = false;
|
||||
}
|
||||
$this->renderBuffer->append($this->renderRow(array_values((array)$row)));
|
||||
$this->renderBuffer->append($this->renderRow(array_values((array) $row)));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -35,6 +35,7 @@ class Json
|
||||
protected function __construct(Traversable $query)
|
||||
{
|
||||
$this->query = $query;
|
||||
$this->render();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -52,6 +52,8 @@ class Controller extends IcingaWebController
|
||||
. '</pre>';
|
||||
exit;
|
||||
case 'json':
|
||||
$json = Json::create($query);
|
||||
|
||||
$response = $this->getResponse();
|
||||
$response
|
||||
->setHeader('Content-Type', 'application/json')
|
||||
@ -65,10 +67,12 @@ class Controller extends IcingaWebController
|
||||
while (ob_get_level()) {
|
||||
ob_end_clean();
|
||||
}
|
||||
Json::create($query)->dump();
|
||||
$json->dump();
|
||||
|
||||
exit;
|
||||
case 'csv':
|
||||
$csv = Csv::fromQuery($query);
|
||||
|
||||
$response = $this->getResponse();
|
||||
$response
|
||||
->setHeader('Content-Type', 'text/csv')
|
||||
@ -82,7 +86,7 @@ class Controller extends IcingaWebController
|
||||
while (ob_get_level()) {
|
||||
ob_end_clean();
|
||||
}
|
||||
Csv::fromQuery($query)->dump();
|
||||
$csv->dump();
|
||||
|
||||
exit;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user