2013-06-27 10:14:41 +02:00
|
|
|
<?php
|
2013-08-14 12:42:32 +02:00
|
|
|
// @codingStandardsIgnoreStart
|
|
|
|
// {{{ICINGA_LICENSE_HEADER}}}
|
|
|
|
/**
|
|
|
|
* This file is part of Icinga 2 Web.
|
|
|
|
*
|
|
|
|
* Icinga 2 Web - 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}}}
|
2013-08-12 15:58:26 +02:00
|
|
|
use Icinga\Web\Controller\ModuleActionController;
|
2013-06-27 10:14:41 +02:00
|
|
|
use Icinga\Web\Hook;
|
2013-07-12 14:33:17 +02:00
|
|
|
use Icinga\File\Csv;
|
2013-07-15 12:16:14 +02:00
|
|
|
use Monitoring\Backend;
|
2013-07-12 13:53:11 +02:00
|
|
|
use Icinga\Application\Benchmark;
|
2013-08-06 18:00:33 +02:00
|
|
|
use Icinga\Web\Widget\Tabs;
|
2013-06-27 10:14:41 +02:00
|
|
|
|
|
|
|
class Monitoring_ListController extends ModuleActionController
|
|
|
|
{
|
2013-08-14 12:42:32 +02:00
|
|
|
/**
|
|
|
|
* The backend used for this controller
|
|
|
|
*
|
|
|
|
* @var \Icinga\Backend
|
|
|
|
*/
|
2013-06-27 10:14:41 +02:00
|
|
|
protected $backend;
|
2013-08-14 12:42:32 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set to a string containing the compact layout name to use when
|
|
|
|
* 'compact' is set as the layout parameter, otherwise null
|
|
|
|
*
|
|
|
|
* @var string|null
|
|
|
|
*/
|
2013-08-06 11:53:42 +02:00
|
|
|
private $compactView = null;
|
2013-06-27 10:14:41 +02:00
|
|
|
|
2013-08-14 12:42:32 +02:00
|
|
|
/**
|
|
|
|
* Retrieve backend and hooks for this controller
|
|
|
|
*
|
|
|
|
* @see ActionController::init
|
|
|
|
*/
|
2013-06-27 10:14:41 +02:00
|
|
|
public function init()
|
|
|
|
{
|
|
|
|
$this->view->tabs = $this->getTabs()
|
|
|
|
->activate($this->action_name)
|
|
|
|
->enableSpecialActions();
|
|
|
|
$this->backend = Backend::getInstance($this->_getParam('backend'));
|
|
|
|
$this->view->grapher = Hook::get('grapher');
|
|
|
|
}
|
|
|
|
|
2013-08-14 12:42:32 +02:00
|
|
|
/**
|
|
|
|
* Display host list
|
|
|
|
*/
|
2013-06-27 10:14:41 +02:00
|
|
|
public function hostsAction()
|
|
|
|
{
|
2013-07-12 13:53:11 +02:00
|
|
|
Benchmark::measure("hostsAction::query()");
|
2013-08-06 11:53:42 +02:00
|
|
|
$this->compactView = "hosts-compact";
|
2013-07-19 18:04:13 +02:00
|
|
|
$this->view->hosts = $this->query(
|
2013-07-12 13:53:11 +02:00
|
|
|
'status',
|
|
|
|
array(
|
|
|
|
'host_icon_image',
|
|
|
|
'host_name',
|
|
|
|
'host_state',
|
|
|
|
'host_address',
|
|
|
|
'host_acknowledged',
|
|
|
|
'host_output',
|
2013-07-19 11:29:51 +02:00
|
|
|
'host_long_output',
|
2013-07-12 13:53:11 +02:00
|
|
|
'host_in_downtime',
|
2013-07-12 15:14:55 +02:00
|
|
|
'host_is_flapping',
|
|
|
|
'host_state_type',
|
2013-07-12 13:53:11 +02:00
|
|
|
'host_handled',
|
2013-07-19 11:29:51 +02:00
|
|
|
'host_last_check',
|
2013-07-12 13:53:11 +02:00
|
|
|
'host_last_state_change',
|
2013-07-12 15:14:55 +02:00
|
|
|
'host_notifications_enabled',
|
2013-07-16 16:16:56 +02:00
|
|
|
'host_unhandled_service_count',
|
2013-07-15 13:21:48 +02:00
|
|
|
'host_action_url',
|
|
|
|
'host_notes_url',
|
|
|
|
'host_last_comment'
|
2013-07-12 13:53:11 +02:00
|
|
|
)
|
|
|
|
);
|
2013-06-27 10:14:41 +02:00
|
|
|
}
|
|
|
|
|
2013-08-14 12:42:32 +02:00
|
|
|
/**
|
|
|
|
* Display service list
|
|
|
|
*/
|
2013-06-27 10:14:41 +02:00
|
|
|
public function servicesAction()
|
|
|
|
{
|
|
|
|
$state_type = $this->_getParam('_statetype', 'soft');
|
|
|
|
if ($state_type = 'soft') {
|
|
|
|
$state_column = 'service_state';
|
|
|
|
$state_change_column = 'service_last_state_change';
|
|
|
|
} else {
|
|
|
|
$state_column = 'service_hard_state';
|
|
|
|
$state_change_column = 'service_last_hard_state_change';
|
|
|
|
}
|
2013-08-07 17:44:18 +02:00
|
|
|
$this->compactView = "services-compact";
|
|
|
|
|
2013-07-12 14:33:17 +02:00
|
|
|
|
|
|
|
$this->view->services = $this->query('status', array(
|
2013-06-27 10:14:41 +02:00
|
|
|
'host_name',
|
2013-07-19 17:45:51 +02:00
|
|
|
'host_state',
|
|
|
|
'host_state_type',
|
|
|
|
'host_last_state_change',
|
|
|
|
'host_address',
|
|
|
|
'host_handled',
|
2013-06-27 10:14:41 +02:00
|
|
|
'service_description',
|
2013-07-19 17:45:51 +02:00
|
|
|
'service_display_name',
|
2013-06-27 10:14:41 +02:00
|
|
|
'service_state' => $state_column,
|
|
|
|
'service_in_downtime',
|
|
|
|
'service_acknowledged',
|
|
|
|
'service_handled',
|
|
|
|
'service_output',
|
2013-07-19 17:45:51 +02:00
|
|
|
'service_last_state_change' => $state_change_column,
|
|
|
|
'service_icon_image',
|
|
|
|
'service_long_output',
|
|
|
|
'service_is_flapping',
|
|
|
|
'service_state_type',
|
|
|
|
'service_handled',
|
|
|
|
'service_severity',
|
|
|
|
'service_last_check',
|
|
|
|
'service_notifications_enabled',
|
|
|
|
'service_action_url',
|
|
|
|
'service_notes_url',
|
|
|
|
'service_last_comment'
|
2013-07-12 14:33:17 +02:00
|
|
|
));
|
2013-07-30 17:17:19 +02:00
|
|
|
$this->inheritCurrentSortColumn();
|
2013-06-27 10:14:41 +02:00
|
|
|
}
|
|
|
|
|
2013-08-14 12:42:32 +02:00
|
|
|
/**
|
|
|
|
* Display hostgroup list
|
|
|
|
*
|
|
|
|
* @TODO Implement hostgroup overview (feature #4184)
|
|
|
|
*/
|
2013-06-27 10:14:41 +02:00
|
|
|
public function hostgroupsAction()
|
|
|
|
{
|
|
|
|
$this->view->hostgroups = $this->backend->select()
|
|
|
|
->from('hostgroup', array(
|
|
|
|
'hostgroup_name',
|
|
|
|
'hostgroup_alias',
|
|
|
|
))->applyRequest($this->_request);
|
|
|
|
}
|
|
|
|
|
2013-08-14 12:42:32 +02:00
|
|
|
/**
|
|
|
|
* Display servicegroup list
|
|
|
|
*
|
|
|
|
* @TODO Implement servicegroup overview (feature #4185)
|
|
|
|
*/
|
2013-06-27 10:14:41 +02:00
|
|
|
public function servicegroupsAction()
|
|
|
|
{
|
|
|
|
$this->view->servicegroups = $this->backend->select()
|
|
|
|
->from('servicegroup', array(
|
|
|
|
'servicegroup_name',
|
|
|
|
'servicegroup_alias',
|
|
|
|
))->applyRequest($this->_request);
|
|
|
|
}
|
|
|
|
|
2013-08-14 12:42:32 +02:00
|
|
|
/**
|
|
|
|
* Display contactgroups overview
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
2013-06-27 10:14:41 +02:00
|
|
|
public function contactgroupsAction()
|
|
|
|
{
|
|
|
|
$this->view->contactgroups = $this->backend->select()
|
|
|
|
->from('contactgroup', array(
|
|
|
|
'contactgroup_name',
|
|
|
|
'contactgroup_alias',
|
|
|
|
))->applyRequest($this->_request);
|
|
|
|
}
|
|
|
|
|
2013-07-30 17:17:19 +02:00
|
|
|
/**
|
|
|
|
* Fetch the current downtimes and put them into the view
|
|
|
|
* property 'downtimes'
|
|
|
|
*/
|
|
|
|
public function downtimesAction()
|
|
|
|
{
|
|
|
|
$query = $this->backend->select()
|
|
|
|
->from('downtime',array(
|
|
|
|
'host_name',
|
|
|
|
'object_type',
|
|
|
|
'service_description',
|
|
|
|
'downtime_entry_time',
|
|
|
|
'downtime_internal_downtime_id',
|
|
|
|
'downtime_author_name',
|
|
|
|
'downtime_comment_data',
|
|
|
|
'downtime_duration',
|
|
|
|
'downtime_scheduled_start_time',
|
|
|
|
'downtime_scheduled_end_time',
|
|
|
|
'downtime_is_fixed',
|
|
|
|
'downtime_is_in_effect',
|
|
|
|
'downtime_triggered_by_id',
|
|
|
|
'downtime_trigger_time'
|
|
|
|
));
|
|
|
|
if (!$this->_getParam('sort')) {
|
|
|
|
$query->order('downtime_is_in_effect');
|
|
|
|
}
|
|
|
|
$this->view->downtimes = $query->applyRequest($this->_request);
|
|
|
|
$this->inheritCurrentSortColumn();
|
|
|
|
}
|
|
|
|
|
2013-08-14 12:42:32 +02:00
|
|
|
/**
|
|
|
|
* Create a query for the given view
|
|
|
|
*
|
|
|
|
* @param string $view An string identifying view to query
|
|
|
|
* @param array $columns An array with the column names to display
|
|
|
|
*
|
|
|
|
* @return \Icinga\Data\Db\Query
|
|
|
|
*/
|
2013-07-12 14:33:17 +02:00
|
|
|
protected function query($view, $columns)
|
|
|
|
{
|
|
|
|
$extra = preg_split(
|
|
|
|
'~,~',
|
|
|
|
$this->_getParam('extracolumns', ''),
|
|
|
|
-1,
|
|
|
|
PREG_SPLIT_NO_EMPTY
|
|
|
|
);
|
2013-07-23 12:18:27 +02:00
|
|
|
|
2013-07-12 14:33:17 +02:00
|
|
|
$this->view->extraColumns = $extra;
|
|
|
|
$query = $this->backend->select()
|
|
|
|
->from($view, array_merge($columns, $extra))
|
|
|
|
->applyRequest($this->_request);
|
|
|
|
$this->handleFormatRequest($query);
|
|
|
|
return $query;
|
|
|
|
}
|
|
|
|
|
2013-08-14 12:42:32 +02:00
|
|
|
/**
|
|
|
|
* Handle the 'format' and 'view' parameter
|
|
|
|
*
|
|
|
|
* @param \Icinga\Data\Db\Query $query The current query
|
|
|
|
*/
|
2013-07-12 14:33:17 +02:00
|
|
|
protected function handleFormatRequest($query)
|
|
|
|
{
|
2013-08-08 16:33:42 +02:00
|
|
|
if ($this->compactView !== null && ($this->_getParam('view', false) === 'compact')) {
|
2013-08-06 11:53:42 +02:00
|
|
|
$this->_helper->viewRenderer($this->compactView);
|
|
|
|
}
|
|
|
|
|
2013-07-12 14:33:17 +02:00
|
|
|
if ($this->_getParam('format') === 'sql') {
|
|
|
|
echo '<pre>'
|
|
|
|
. htmlspecialchars(wordwrap($query->getQuery()->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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-14 12:42:32 +02:00
|
|
|
/**
|
|
|
|
* Return all tabs for this controller
|
|
|
|
*
|
|
|
|
* @return Tabs
|
|
|
|
*/
|
2013-06-27 10:14:41 +02:00
|
|
|
protected function getTabs()
|
|
|
|
{
|
2013-08-06 18:00:33 +02:00
|
|
|
$tabs = new Tabs();
|
2013-06-27 10:14:41 +02:00
|
|
|
$tabs->add('services', array(
|
2013-07-12 14:33:17 +02:00
|
|
|
'title' => 'All services',
|
2013-06-27 10:14:41 +02:00
|
|
|
'icon' => 'img/classic/service.png',
|
|
|
|
'url' => 'monitoring/list/services',
|
|
|
|
));
|
|
|
|
$tabs->add('hosts', array(
|
2013-07-12 14:33:17 +02:00
|
|
|
'title' => 'All hosts',
|
2013-06-27 10:14:41 +02:00
|
|
|
'icon' => 'img/classic/server.png',
|
|
|
|
'url' => 'monitoring/list/hosts',
|
|
|
|
));
|
2013-07-30 17:17:19 +02:00
|
|
|
$tabs->add('downtimes', array(
|
|
|
|
'title' => 'Downtimes',
|
|
|
|
'icon' => 'img/classic/downtime.gif',
|
|
|
|
'url' => 'monitoring/list/downtimes',
|
|
|
|
));
|
2013-07-12 14:33:17 +02:00
|
|
|
/*
|
2013-06-27 10:14:41 +02:00
|
|
|
$tabs->add('hostgroups', array(
|
|
|
|
'title' => 'Hostgroups',
|
|
|
|
'icon' => 'img/classic/servers-network.png',
|
|
|
|
'url' => 'monitoring/list/hostgroups',
|
|
|
|
));
|
|
|
|
$tabs->add('servicegroups', array(
|
|
|
|
'title' => 'Servicegroups',
|
|
|
|
'icon' => 'img/classic/servers-network.png',
|
|
|
|
'url' => 'monitoring/list/servicegroups',
|
|
|
|
));
|
|
|
|
$tabs->add('contacts', array(
|
|
|
|
'title' => 'Contacts',
|
|
|
|
'icon' => 'img/classic/servers-network.png',
|
|
|
|
'url' => 'monitoring/list/contacts',
|
|
|
|
));
|
|
|
|
$tabs->add('contactgroups', array(
|
|
|
|
'title' => 'Contactgroups',
|
|
|
|
'icon' => 'img/classic/servers-network.png',
|
|
|
|
'url' => 'monitoring/list/contactgroups',
|
|
|
|
));
|
2013-07-12 14:33:17 +02:00
|
|
|
*/
|
2013-06-27 10:14:41 +02:00
|
|
|
return $tabs;
|
|
|
|
}
|
2013-07-30 17:17:19 +02:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Let the current response inherit the used sort column by applying it to the
|
|
|
|
* view property 'sort'
|
|
|
|
*/
|
|
|
|
private function inheritCurrentSortColumn()
|
|
|
|
{
|
|
|
|
if ($this->_getParam('sort')) {
|
|
|
|
$this->view->sort = $this->_getParam('sort');
|
|
|
|
}
|
|
|
|
}
|
2013-06-27 10:14:41 +02:00
|
|
|
}
|
2013-08-14 12:42:32 +02:00
|
|
|
// @codingStandardsIgnoreEnd
|