2013-10-10 14:40:13 +02:00
|
|
|
<?php
|
|
|
|
// {{{ICINGA_LICENSE_HEADER}}}
|
2013-10-23 15:10:33 +02:00
|
|
|
/**
|
|
|
|
* This file is part of Icinga Web 2.
|
|
|
|
*
|
|
|
|
* Icinga Web 2 - Head for multiple monitoring backends.
|
|
|
|
* Copyright (C) 2013 Icinga Development Team
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
* @copyright 2013 Icinga Development Team <info@icinga.org>
|
|
|
|
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
|
|
|
|
* @author Icinga Development Team <info@icinga.org>
|
|
|
|
*
|
|
|
|
*/
|
2013-10-10 14:40:13 +02:00
|
|
|
// {{{ICINGA_LICENSE_HEADER}}}
|
|
|
|
|
|
|
|
namespace Icinga\Module\Monitoring;
|
|
|
|
|
|
|
|
use Icinga\Web\Controller\ActionController;
|
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
|
|
|
|
*/
|
|
|
|
class Controller extends ActionController
|
|
|
|
{
|
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'));
|
|
|
|
}
|
|
|
|
|
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');
|
|
|
|
echo json_encode($query->fetchAll());
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
if ($this->_getParam('format') === 'csv'
|
|
|
|
|| $this->_request->getHeader('Accept') === 'text/csv') {
|
|
|
|
Csv::fromQuery($query)->dump();
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// @codingStandardsIgnoreEnd
|