88 lines
2.7 KiB
PHP
88 lines
2.7 KiB
PHP
<?php
|
|
// {{{ICINGA_LICENSE_HEADER}}}
|
|
/**
|
|
* 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>
|
|
*
|
|
*/
|
|
// {{{ICINGA_LICENSE_HEADER}}}
|
|
|
|
namespace Icinga\Module\Monitoring;
|
|
|
|
use Icinga\Web\Controller\ActionController;
|
|
use Icinga\File\Csv;
|
|
|
|
/**
|
|
* Base class for all monitoring action controller
|
|
*/
|
|
class Controller extends ActionController
|
|
{
|
|
/**
|
|
* The backend used for this controller
|
|
*
|
|
* @var Backend
|
|
*/
|
|
protected $backend;
|
|
|
|
/**
|
|
* 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;
|
|
|
|
protected function moduleInit()
|
|
{
|
|
$this->backend = Backend::createBackend($this->_getParam('backend'));
|
|
}
|
|
|
|
protected function handleFormatRequest($query)
|
|
{
|
|
if ($this->compactView !== null && ($this->_getParam('view', false) === 'compact')) {
|
|
$this->_helper->viewRenderer($this->compactView);
|
|
}
|
|
|
|
if ($this->_getParam('format') === 'sql') {
|
|
echo '<pre>'
|
|
. htmlspecialchars(wordwrap($query->dump()))
|
|
. '</pre>';
|
|
exit;
|
|
}
|
|
if ($this->_getParam('format') === 'json'
|
|
|| $this->_request->getHeader('Accept') === 'application/json') {
|
|
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
|