2013-10-10 14:40:13 +02:00
|
|
|
<?php
|
|
|
|
// {{{ICINGA_LICENSE_HEADER}}}
|
|
|
|
// {{{ICINGA_LICENSE_HEADER}}}
|
|
|
|
|
|
|
|
namespace Icinga\Module\Monitoring;
|
|
|
|
|
2014-06-22 13:49:21 +02:00
|
|
|
use Icinga\Web\Controller\ModuleActionController;
|
2014-06-20 12:26:00 +02:00
|
|
|
use Icinga\Web\Url;
|
2014-03-06 23:54:03 +01:00
|
|
|
use Icinga\File\Csv;
|
2013-10-10 14:40:13 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Base class for all monitoring action controller
|
|
|
|
*/
|
2014-06-22 13:49:21 +02:00
|
|
|
class Controller extends ModuleActionController
|
2013-10-10 14:40:13 +02:00
|
|
|
{
|
2014-06-17 14:55:43 +02:00
|
|
|
/**
|
|
|
|
* The backend used for this controller
|
|
|
|
*
|
|
|
|
* @var Backend
|
|
|
|
*/
|
|
|
|
protected $backend;
|
|
|
|
|
2013-10-23 15:38:06 +02:00
|
|
|
/**
|
|
|
|
* Compact layout name
|
|
|
|
*
|
|
|
|
* Set to a string containing the compact layout name to use when
|
|
|
|
* 'compact' is set as the layout parameter, otherwise null
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $compactView;
|
2013-10-17 19:48:46 +02:00
|
|
|
|
2014-06-17 14:55:43 +02:00
|
|
|
protected function moduleInit()
|
|
|
|
{
|
|
|
|
$this->backend = Backend::createBackend($this->_getParam('backend'));
|
2014-06-20 12:26:00 +02:00
|
|
|
$this->view->url = Url::fromRequest();
|
2014-06-17 14:55:43 +02:00
|
|
|
}
|
|
|
|
|
2013-10-22 15:57:30 +02:00
|
|
|
protected function handleFormatRequest($query)
|
2013-10-10 14:40:13 +02:00
|
|
|
{
|
2013-10-22 15:57:30 +02:00
|
|
|
if ($this->compactView !== null && ($this->_getParam('view', false) === 'compact')) {
|
|
|
|
$this->_helper->viewRenderer($this->compactView);
|
|
|
|
}
|
|
|
|
|
2014-03-06 10:17:55 +01:00
|
|
|
if ($this->_getParam('format') === 'sql') {
|
2013-10-10 14:40:13 +02:00
|
|
|
echo '<pre>'
|
|
|
|
. htmlspecialchars(wordwrap($query->dump()))
|
|
|
|
. '</pre>';
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
if ($this->_getParam('format') === 'json'
|
2013-10-17 21:40:02 +02:00
|
|
|
|| $this->_request->getHeader('Accept') === 'application/json') {
|
2013-10-10 14:40:13 +02:00
|
|
|
header('Content-type: application/json');
|
2014-06-21 00:09:11 +02:00
|
|
|
echo json_encode($query->getQuery()->fetchAll());
|
2013-10-10 14:40:13 +02:00
|
|
|
exit;
|
|
|
|
}
|
|
|
|
if ($this->_getParam('format') === 'csv'
|
|
|
|
|| $this->_request->getHeader('Accept') === 'text/csv') {
|
|
|
|
Csv::fromQuery($query)->dump();
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-07-16 13:59:43 +02:00
|
|
|
|