2013-06-27 10:14:41 +02:00
|
|
|
<?php
|
2014-07-15 13:39:22 +02:00
|
|
|
// {{{ICINGA_LICENSE_HEADER}}}
|
|
|
|
// {{{ICINGA_LICENSE_HEADER}}}
|
2013-08-20 11:44:05 +02:00
|
|
|
|
2014-03-08 18:49:31 +01:00
|
|
|
use Icinga\Module\Monitoring\Controller;
|
2014-06-06 09:37:37 +02:00
|
|
|
use Icinga\Module\Monitoring\Backend;
|
|
|
|
use Icinga\Web\Url;
|
2013-10-09 16:38:46 +02:00
|
|
|
use Icinga\Web\Hook;
|
|
|
|
use Icinga\Web\Widget\Tabextension\DashboardAction;
|
|
|
|
use Icinga\Web\Widget\Tabextension\OutputFormat;
|
|
|
|
use Icinga\Web\Widget\Tabs;
|
|
|
|
use Icinga\Web\Widget\SortBox;
|
2013-10-14 13:25:25 +02:00
|
|
|
use Icinga\Web\Widget\FilterBox;
|
2014-03-05 20:12:45 +01:00
|
|
|
use Icinga\Web\Widget\Chart\HistoryColorGrid;
|
2014-06-06 09:37:37 +02:00
|
|
|
use Icinga\Data\Filter\Filter;
|
|
|
|
use Icinga\Web\Widget;
|
2014-09-16 15:58:24 +02:00
|
|
|
use Icinga\Module\Monitoring\Web\Widget\SelectBox;
|
2013-09-24 15:26:10 +02:00
|
|
|
|
2014-03-08 18:49:31 +01:00
|
|
|
class Monitoring_ListController extends Controller
|
2013-06-27 10:14:41 +02:00
|
|
|
{
|
2014-06-06 09:37:37 +02:00
|
|
|
protected $url;
|
|
|
|
|
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()
|
|
|
|
{
|
2013-08-08 16:22:22 +02:00
|
|
|
$this->createTabs();
|
2014-06-06 09:37:37 +02:00
|
|
|
$this->view->compact = $this->_request->getParam('view') === 'compact';
|
|
|
|
$this->url = Url::fromRequest();
|
2013-06-27 10:14:41 +02:00
|
|
|
}
|
|
|
|
|
2014-06-06 09:37:37 +02:00
|
|
|
protected function hasBetterUrl()
|
2014-03-21 11:24:17 +01:00
|
|
|
{
|
2014-09-02 13:07:20 +02:00
|
|
|
$request = $this->getRequest();
|
2014-06-06 09:37:37 +02:00
|
|
|
$url = clone($this->url);
|
2014-09-02 13:07:20 +02:00
|
|
|
|
2014-06-25 10:34:09 +02:00
|
|
|
if ($this->getRequest()->isPost()) {
|
2014-09-02 13:07:20 +02:00
|
|
|
|
|
|
|
if ($request->getPost('sort')) {
|
|
|
|
$url->setParam('sort', $request->getPost('sort'));
|
|
|
|
if ($request->getPost('dir')) {
|
|
|
|
$url->setParam('dir', $request->getPost('dir'));
|
|
|
|
} else {
|
|
|
|
$url->removeParam('dir');
|
|
|
|
}
|
|
|
|
return $url;
|
|
|
|
}
|
|
|
|
|
2014-06-25 10:34:09 +02:00
|
|
|
$q = $this->getRequest()->getPost('q');
|
2014-09-04 15:12:49 +02:00
|
|
|
if ($q) {
|
|
|
|
list($k, $v) = preg_split('/=/', $q);
|
|
|
|
$url->addParams(array($k => $v));
|
|
|
|
return $url;
|
|
|
|
}
|
2014-06-25 10:34:09 +02:00
|
|
|
} else {
|
|
|
|
$q = $url->shift('q');
|
2014-09-04 16:31:10 +02:00
|
|
|
if ($q !== null) {
|
2014-09-04 15:12:49 +02:00
|
|
|
$action = $this->_request->getActionName();
|
|
|
|
switch($action) {
|
|
|
|
case 'services':
|
|
|
|
$this->params->remove('q')->set('service_description', '*' . $q . '*');
|
|
|
|
break;
|
|
|
|
case 'hosts':
|
|
|
|
$this->params->remove('q')->set('host_name', '*' . $q . '*');
|
|
|
|
break;
|
|
|
|
case 'hostgroups':
|
2014-09-04 16:31:10 +02:00
|
|
|
$this->params->remove('q')->set('hostgroup', '*' . $q . '*');
|
2014-09-04 15:12:49 +02:00
|
|
|
break;
|
|
|
|
case 'servicegroups':
|
|
|
|
$this->params->remove('q')->set('servicegroup', '*' . $q . '*');
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2014-06-06 09:37:37 +02:00
|
|
|
}
|
|
|
|
return false;
|
2014-03-21 11:24:17 +01:00
|
|
|
}
|
|
|
|
|
2013-08-30 15:50:49 +02:00
|
|
|
/**
|
|
|
|
* Overwrite the backend to use (used for testing)
|
|
|
|
*
|
|
|
|
* @param Backend $backend The Backend that should be used for querying
|
|
|
|
*/
|
|
|
|
public function setBackend($backend)
|
|
|
|
{
|
|
|
|
$this->backend = $backend;
|
|
|
|
}
|
|
|
|
|
2013-08-14 12:42:32 +02:00
|
|
|
/**
|
|
|
|
* Display host list
|
|
|
|
*/
|
2013-06-27 10:14:41 +02:00
|
|
|
public function hostsAction()
|
|
|
|
{
|
2014-06-25 10:34:09 +02:00
|
|
|
if ($url = $this->hasBetterUrl()) {
|
|
|
|
return $this->redirectNow($url);
|
|
|
|
}
|
2014-06-26 00:42:38 +02:00
|
|
|
|
|
|
|
// Handle soft and hard states
|
|
|
|
$stateType = $this->params->shift('stateType', 'soft');
|
|
|
|
if ($stateType == 'hard') {
|
|
|
|
$stateColumn = 'host_hard_state';
|
|
|
|
$stateChangeColumn = 'host_last_hard_state_change';
|
|
|
|
} else {
|
2014-07-16 17:49:25 +02:00
|
|
|
$stateType = 'soft';
|
2014-06-26 00:42:38 +02:00
|
|
|
$stateColumn = 'host_state';
|
|
|
|
$stateChangeColumn = 'host_last_state_change';
|
|
|
|
}
|
|
|
|
|
2014-06-06 09:37:37 +02:00
|
|
|
$this->addTitleTab('hosts');
|
2014-03-04 13:33:02 +01:00
|
|
|
$this->setAutorefreshInterval(10);
|
2014-06-24 21:12:55 +02:00
|
|
|
$query = $this->backend->select()->from('hostStatus', array_merge(array(
|
2014-06-06 09:37:37 +02:00
|
|
|
'host_icon_image',
|
|
|
|
'host_name',
|
2014-06-26 00:42:38 +02:00
|
|
|
'host_state' => $stateColumn,
|
2014-06-06 09:37:37 +02:00
|
|
|
'host_address',
|
|
|
|
'host_acknowledged',
|
|
|
|
'host_output',
|
2014-08-22 11:23:45 +02:00
|
|
|
'host_attempt',
|
2014-06-06 09:37:37 +02:00
|
|
|
'host_in_downtime',
|
|
|
|
'host_is_flapping',
|
|
|
|
'host_state_type',
|
|
|
|
'host_handled',
|
|
|
|
'host_last_check',
|
2014-06-26 00:42:38 +02:00
|
|
|
'host_last_state_change' => $stateChangeColumn,
|
2014-06-06 09:37:37 +02:00
|
|
|
'host_notifications_enabled',
|
2014-06-25 21:38:55 +02:00
|
|
|
'host_unhandled_services',
|
2014-06-06 09:37:37 +02:00
|
|
|
'host_action_url',
|
|
|
|
'host_notes_url',
|
2014-06-25 21:38:55 +02:00
|
|
|
'host_last_comment',
|
|
|
|
'host_last_ack',
|
|
|
|
'host_last_downtime',
|
2014-06-06 09:37:37 +02:00
|
|
|
'host_active_checks_enabled',
|
|
|
|
'host_passive_checks_enabled',
|
|
|
|
'host_current_check_attempt',
|
|
|
|
'host_max_check_attempts'
|
2014-06-24 21:12:55 +02:00
|
|
|
), $this->extraColumns()));
|
2014-01-22 14:34:39 +01:00
|
|
|
|
2014-06-06 09:37:37 +02:00
|
|
|
$this->applyFilters($query);
|
2013-10-17 19:48:46 +02:00
|
|
|
|
2013-09-03 18:43:17 +02:00
|
|
|
$this->setupSortControl(array(
|
2014-06-20 13:24:32 +02:00
|
|
|
'host_last_check' => 'Last Check',
|
|
|
|
'host_severity' => 'Severity',
|
|
|
|
'host_name' => 'Hostname',
|
2013-09-03 18:43:17 +02:00
|
|
|
'host_address' => 'Address',
|
2014-06-20 13:24:32 +02:00
|
|
|
'host_state' => 'Current State',
|
2013-09-03 18:43:17 +02:00
|
|
|
'host_state' => 'Hard State'
|
|
|
|
));
|
2014-06-06 09:37:37 +02:00
|
|
|
$this->view->hosts = $query->paginate();
|
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()
|
|
|
|
{
|
2014-06-06 09:37:37 +02:00
|
|
|
if ($url = $this->hasBetterUrl()) {
|
|
|
|
return $this->redirectNow($url);
|
|
|
|
}
|
2014-06-26 00:42:38 +02:00
|
|
|
|
|
|
|
// Handle soft and hard states
|
|
|
|
$stateType = $this->params->shift('stateType', 'soft');
|
|
|
|
if ($stateType == 'hard') {
|
|
|
|
$stateColumn = 'service_hard_state';
|
|
|
|
$stateChangeColumn = 'service_last_hard_state_change';
|
|
|
|
} else {
|
|
|
|
$stateColumn = 'service_state';
|
|
|
|
$stateChangeColumn = 'service_last_state_change';
|
|
|
|
$stateType = 'soft';
|
|
|
|
}
|
|
|
|
|
2014-06-06 09:37:37 +02:00
|
|
|
$this->addTitleTab('services');
|
2014-03-08 01:00:21 +01:00
|
|
|
$this->view->showHost = true;
|
|
|
|
if ($host = $this->_getParam('host')) {
|
|
|
|
if (strpos($host, '*') === false) {
|
|
|
|
$this->view->showHost = false;
|
|
|
|
}
|
|
|
|
}
|
2014-03-04 13:33:02 +01:00
|
|
|
$this->setAutorefreshInterval(10);
|
2014-07-16 17:49:25 +02:00
|
|
|
|
2014-06-06 09:37:37 +02:00
|
|
|
$columns = array_merge(array(
|
|
|
|
'host_name',
|
|
|
|
'host_state',
|
|
|
|
'host_state_type',
|
|
|
|
'host_last_state_change',
|
|
|
|
'host_address',
|
|
|
|
'host_handled',
|
|
|
|
'service_description',
|
|
|
|
'service_display_name',
|
2014-06-26 00:42:38 +02:00
|
|
|
'service_state' => $stateColumn,
|
2014-06-06 09:37:37 +02:00
|
|
|
'service_in_downtime',
|
|
|
|
'service_acknowledged',
|
|
|
|
'service_handled',
|
|
|
|
'service_output',
|
|
|
|
'service_perfdata',
|
|
|
|
'service_attempt',
|
2014-06-26 00:42:38 +02:00
|
|
|
'service_last_state_change' => $stateChangeColumn,
|
2014-06-06 09:37:37 +02:00
|
|
|
'service_icon_image',
|
|
|
|
'service_is_flapping',
|
|
|
|
'service_state_type',
|
|
|
|
'service_handled',
|
|
|
|
'service_severity',
|
|
|
|
'service_last_check',
|
|
|
|
'service_notifications_enabled',
|
|
|
|
'service_action_url',
|
|
|
|
'service_notes_url',
|
2014-06-25 21:38:55 +02:00
|
|
|
'service_last_comment',
|
|
|
|
'service_last_ack',
|
|
|
|
'service_last_downtime',
|
2014-06-06 09:37:37 +02:00
|
|
|
'service_active_checks_enabled',
|
|
|
|
'service_passive_checks_enabled',
|
|
|
|
'current_check_attempt' => 'service_current_check_attempt',
|
|
|
|
'max_check_attempts' => 'service_max_check_attempts'
|
|
|
|
), $this->extraColumns());
|
|
|
|
$query = $this->backend->select()->from('serviceStatus', $columns);
|
2013-10-17 19:48:46 +02:00
|
|
|
|
2014-06-06 09:37:37 +02:00
|
|
|
$this->applyFilters($query);
|
2013-09-03 18:43:17 +02:00
|
|
|
$this->setupSortControl(array(
|
|
|
|
'service_last_check' => 'Last Service Check',
|
|
|
|
'service_severity' => 'Severity',
|
|
|
|
'service_state' => 'Current Service State',
|
|
|
|
'service_description' => 'Service Name',
|
|
|
|
'service_state_type' => 'Hard State',
|
|
|
|
'host_severity' => 'Host Severity',
|
|
|
|
'host_state' => 'Current Host State',
|
|
|
|
'host_name' => 'Host Name',
|
|
|
|
'host_address' => 'Host Address',
|
|
|
|
'host_last_check' => 'Last Host Check'
|
2013-09-24 15:26:10 +02:00
|
|
|
));
|
2014-06-25 20:45:08 +02:00
|
|
|
$limit = $this->params->get('limit');
|
|
|
|
$this->view->limit = $limit;
|
2014-06-26 16:34:37 +02:00
|
|
|
if ($limit === 0) {
|
|
|
|
$this->view->services = $query->getQuery()->fetchAll();
|
|
|
|
} else {
|
2014-06-26 00:39:10 +02:00
|
|
|
// TODO: Workaround, paginate should be able to fetch limit from new params
|
2014-06-26 00:42:38 +02:00
|
|
|
$this->view->services = $query->paginate($this->params->get('limit'));
|
2014-06-25 20:45:08 +02:00
|
|
|
}
|
2014-09-05 17:40:57 +02:00
|
|
|
|
|
|
|
$this->view->stats = $this->backend->select()->from('statusSummary', array(
|
|
|
|
'services_total',
|
|
|
|
'services_ok',
|
|
|
|
'services_problem',
|
|
|
|
'services_problem_handled',
|
|
|
|
'services_problem_unhandled',
|
|
|
|
'services_critical',
|
|
|
|
'services_critical_unhandled',
|
|
|
|
'services_critical_handled',
|
|
|
|
'services_warning',
|
|
|
|
'services_warning_unhandled',
|
|
|
|
'services_warning_handled',
|
|
|
|
'services_unknown',
|
|
|
|
'services_unknown_unhandled',
|
|
|
|
'services_unknown_handled',
|
|
|
|
'services_pending',
|
|
|
|
))->getQuery()->fetchRow();
|
|
|
|
|
2013-06-27 10:14:41 +02:00
|
|
|
}
|
|
|
|
|
2013-07-30 17:17:19 +02:00
|
|
|
/**
|
2013-08-20 11:44:05 +02:00
|
|
|
* Fetch the current downtimes and put them into the view property `downtimes`
|
2013-07-30 17:17:19 +02:00
|
|
|
*/
|
|
|
|
public function downtimesAction()
|
|
|
|
{
|
2014-06-06 09:37:37 +02:00
|
|
|
$this->addTitleTab('downtimes');
|
2014-03-09 21:58:01 +01:00
|
|
|
$this->setAutorefreshInterval(12);
|
2014-06-06 09:37:37 +02:00
|
|
|
$query = $this->backend->select()->from('downtime', array(
|
|
|
|
'id' => 'downtime_internal_id',
|
|
|
|
'objecttype' => 'downtime_objecttype',
|
|
|
|
'comment' => 'downtime_comment',
|
|
|
|
'author' => 'downtime_author',
|
|
|
|
'start' => 'downtime_start',
|
|
|
|
'scheduled_start' => 'downtime_scheduled_start',
|
2014-08-19 17:03:35 +02:00
|
|
|
'scheduled_end' => 'downtime_scheduled_end',
|
2014-06-06 09:37:37 +02:00
|
|
|
'end' => 'downtime_end',
|
|
|
|
'duration' => 'downtime_duration',
|
|
|
|
'is_flexible' => 'downtime_is_flexible',
|
|
|
|
'is_fixed' => 'downtime_is_fixed',
|
|
|
|
'is_in_effect' => 'downtime_is_in_effect',
|
|
|
|
'entry_time' => 'downtime_entry_time',
|
|
|
|
'host' => 'downtime_host',
|
2014-08-19 17:03:35 +02:00
|
|
|
'service' => 'downtime_service',
|
|
|
|
'host_state' => 'downtime_host_state',
|
|
|
|
'service_state' => 'downtime_service_state'
|
2014-06-06 09:37:37 +02:00
|
|
|
))->order('downtime_is_in_effect', 'DESC')
|
|
|
|
->order('downtime_scheduled_start', 'DESC');
|
|
|
|
|
|
|
|
$this->applyFilters($query);
|
2013-09-24 15:26:10 +02:00
|
|
|
$this->view->downtimes = $query->paginate();
|
2013-09-03 18:43:17 +02:00
|
|
|
$this->setupSortControl(array(
|
2014-06-06 09:37:37 +02:00
|
|
|
'downtime_is_in_effect' => 'Is In Effect',
|
|
|
|
'downtime_host' => 'Host / Service',
|
|
|
|
'downtime_entry_time' => 'Entry Time',
|
|
|
|
'downtime_author' => 'Author',
|
|
|
|
'downtime_start' => 'Start Time',
|
|
|
|
'downtime_start' => 'End Time',
|
2014-03-09 22:35:33 +01:00
|
|
|
'downtime_scheduled_start' => 'Scheduled Start',
|
|
|
|
'downtime_scheduled_end' => 'Scheduled End',
|
2014-06-06 09:37:37 +02:00
|
|
|
'downtime_duration' => 'Duration',
|
2013-09-24 15:26:10 +02:00
|
|
|
));
|
2013-07-30 17:17:19 +02:00
|
|
|
}
|
|
|
|
|
2013-08-14 12:42:32 +02:00
|
|
|
/**
|
2013-08-09 11:23:42 +02:00
|
|
|
* Display notification overview
|
2013-08-14 12:42:32 +02:00
|
|
|
*/
|
2013-08-09 11:23:42 +02:00
|
|
|
public function notificationsAction()
|
|
|
|
{
|
2014-02-21 11:42:03 +01:00
|
|
|
$this->addTitleTab('notifications');
|
2014-05-09 18:01:47 +02:00
|
|
|
$this->setAutorefreshInterval(15);
|
2014-06-20 19:12:10 +02:00
|
|
|
$query = $this->backend->select()->from('notification', array(
|
|
|
|
'host',
|
|
|
|
'service',
|
|
|
|
'notification_output',
|
|
|
|
'notification_contact',
|
|
|
|
'notification_start_time',
|
|
|
|
'notification_state'
|
|
|
|
));
|
2014-06-06 09:37:37 +02:00
|
|
|
$this->applyFilters($query);
|
2013-09-24 15:26:10 +02:00
|
|
|
$this->view->notifications = $query->paginate();
|
2013-09-03 18:43:17 +02:00
|
|
|
$this->setupSortControl(array(
|
2013-10-04 10:09:00 +02:00
|
|
|
'notification_start_time' => 'Notification Start'
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function contactsAction()
|
|
|
|
{
|
2014-06-06 09:37:37 +02:00
|
|
|
$this->addTitleTab('contacts');
|
|
|
|
$query = $this->backend->select()->from('contact', array(
|
|
|
|
'contact_name',
|
|
|
|
'contact_id',
|
|
|
|
'contact_alias',
|
|
|
|
'contact_email',
|
|
|
|
'contact_pager',
|
|
|
|
'contact_notify_service_timeperiod',
|
|
|
|
'contact_notify_service_recovery',
|
|
|
|
'contact_notify_service_warning',
|
|
|
|
'contact_notify_service_critical',
|
|
|
|
'contact_notify_service_unknown',
|
|
|
|
'contact_notify_service_flapping',
|
|
|
|
'contact_notify_service_downtime',
|
|
|
|
'contact_notify_host_timeperiod',
|
|
|
|
'contact_notify_host_recovery',
|
|
|
|
'contact_notify_host_down',
|
|
|
|
'contact_notify_host_unreachable',
|
|
|
|
'contact_notify_host_flapping',
|
|
|
|
'contact_notify_host_downtime',
|
|
|
|
));
|
|
|
|
$this->applyFilters($query);
|
2013-10-04 10:09:00 +02:00
|
|
|
$this->view->contacts = $query->paginate();
|
2014-06-03 17:59:22 +02:00
|
|
|
|
2013-10-04 10:09:00 +02:00
|
|
|
$this->setupSortControl(array(
|
|
|
|
'contact_name' => 'Name',
|
|
|
|
'contact_alias' => 'Alias',
|
|
|
|
'contact_email' => 'Email',
|
|
|
|
'contact_pager' => 'Pager Address / Number',
|
|
|
|
'contact_notify_service_timeperiod' => 'Service Notification Timeperiod',
|
|
|
|
'contact_notify_host_timeperiod' => 'Host Notification Timeperiod'
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
2014-02-21 11:44:03 +01:00
|
|
|
public function statehistorysummaryAction()
|
|
|
|
{
|
2014-09-16 15:58:24 +02:00
|
|
|
$this->view->from = $this->params->shift('from', '3 months ago');
|
|
|
|
$this->addTitleTab('statehistorysummary', 'State Summary');
|
|
|
|
$selections = array(
|
|
|
|
'critical' => array(
|
|
|
|
'column' => 'cnt_critical',
|
|
|
|
'filter' => Filter::matchAll(
|
|
|
|
Filter::expression('object_type', '=', 'service'),
|
|
|
|
Filter::expression('state', '=', '2')
|
|
|
|
),
|
|
|
|
'tooltip' => t('%d critical events on %s'),
|
|
|
|
'color' => '#ff5566', 'opacity' => '0.9'
|
|
|
|
),
|
|
|
|
'warning' => array(
|
|
|
|
'column' => 'cnt_warning',
|
|
|
|
'filter' => Filter::matchAll(
|
|
|
|
Filter::expression('object_type', '=', 'service'),
|
|
|
|
Filter::expression('state', '=', '1')
|
|
|
|
),
|
|
|
|
'tooltip' => t('%d warning events on %s'),
|
|
|
|
'color' => '#ffaa44', 'opacity' => '1.0'
|
|
|
|
),
|
|
|
|
'unknown' => array(
|
|
|
|
'column' => 'cnt_unknown',
|
|
|
|
'filter' => Filter::matchAll(
|
|
|
|
Filter::expression('object_type', '=', 'service'),
|
|
|
|
Filter::expression('state', '=', '3')
|
|
|
|
),
|
|
|
|
'tooltip' => t('%d unknown events on %s'),
|
|
|
|
'color' => '#cc77ff', 'opacity' => '0.7'
|
|
|
|
),
|
|
|
|
'ok' => array(
|
|
|
|
'column' => 'cnt_ok',
|
|
|
|
'filter' => Filter::matchAll(
|
|
|
|
Filter::expression('object_type', '=', 'service'),
|
|
|
|
Filter::expression('state', '=', '0')
|
|
|
|
),
|
|
|
|
'tooltip' => t('%d ok events on %s'),
|
|
|
|
'color' => '#49DF96', 'opacity' => '0.55'
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
$eventBox = new SelectBox(
|
|
|
|
'statehistoryfilter',
|
|
|
|
array(
|
|
|
|
'critical' => t('Critical'),
|
|
|
|
'warning' => t('Warning'),
|
|
|
|
'unknown' => t('Unknown'),
|
|
|
|
'ok' => t('Ok')
|
|
|
|
),
|
|
|
|
t('Events'),
|
|
|
|
'event'
|
|
|
|
);
|
|
|
|
$eventBox->applyRequest($this->getRequest());
|
|
|
|
|
|
|
|
$orientationBox = new SelectBox(
|
|
|
|
'orientation',
|
|
|
|
array(
|
|
|
|
'0' => t('Vertical'),
|
|
|
|
'1' => t('Horizontal')
|
|
|
|
),
|
|
|
|
t('Orientation'),
|
|
|
|
'horizontal'
|
|
|
|
);
|
|
|
|
$orientationBox->applyRequest($this->getRequest());
|
|
|
|
|
|
|
|
$intervalBox = new SelectBox(
|
|
|
|
'from',
|
|
|
|
array(
|
|
|
|
'3 months ago' => t('3 Months'),
|
|
|
|
'4 months ago' => t('4 Months'),
|
|
|
|
'8 months ago' => t('8 Months'),
|
|
|
|
'12 months ago' => t('1 Year'),
|
|
|
|
'24 months ago' => t('2 Years')
|
|
|
|
),
|
|
|
|
t('Interval'),
|
|
|
|
'from'
|
|
|
|
);
|
|
|
|
$intervalBox->applyRequest($this->getRequest());
|
|
|
|
|
|
|
|
$eventtype = $this->params->shift('event', 'critical');
|
|
|
|
$orientation = $this->params->shift('horizontal', 0) ? 'horizontal' : 'vertical';
|
|
|
|
$selection = $selections[$eventtype];
|
|
|
|
|
2014-06-06 09:37:37 +02:00
|
|
|
$query = $this->backend->select()->from(
|
|
|
|
'stateHistorySummary',
|
2014-09-16 15:58:24 +02:00
|
|
|
array('day', $selection['column'])
|
|
|
|
);
|
|
|
|
$this->applyFilters($query);
|
|
|
|
$this->view->orientationBox = $orientationBox;
|
|
|
|
$this->view->eventBox = $eventBox;
|
|
|
|
$this->view->selection = $selection;
|
|
|
|
$this->view->orientation = $orientation;
|
|
|
|
$this->view->summary = $query->getQuery()->fetchAll();
|
|
|
|
$this->view->intervalBox = $intervalBox;
|
2014-02-21 11:44:03 +01:00
|
|
|
}
|
|
|
|
|
2013-10-04 10:09:00 +02:00
|
|
|
public function contactgroupsAction()
|
|
|
|
{
|
2014-02-21 11:46:57 +01:00
|
|
|
$this->addTitleTab('contactgroups');
|
2014-06-06 09:37:37 +02:00
|
|
|
$query = $this->backend->select()->from('contactgroup', array(
|
|
|
|
'contactgroup_name',
|
|
|
|
'contactgroup_alias',
|
|
|
|
'contact_name',
|
|
|
|
'contact_alias',
|
|
|
|
'contact_email',
|
|
|
|
'contact_pager',
|
|
|
|
))->order('contactgroup_alias');
|
|
|
|
$this->applyFilters($query);
|
|
|
|
|
|
|
|
// Fetch and prepare all contact groups:
|
|
|
|
$contactgroups = $query->getQuery()->fetchAll();
|
2014-03-07 10:35:11 +01:00
|
|
|
$groupData = array();
|
|
|
|
foreach ($contactgroups as $c) {
|
|
|
|
if (!array_key_exists($c->contactgroup_name, $groupData)) {
|
|
|
|
$groupData[$c->contactgroup_name] = array(
|
|
|
|
'alias' => $c->contactgroup_alias,
|
|
|
|
'contacts' => array()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
$groupData[$c->contactgroup_name]['contacts'][] = $c;
|
|
|
|
}
|
2014-06-06 09:37:37 +02:00
|
|
|
// TODO: Find a better naming
|
2014-03-07 10:35:11 +01:00
|
|
|
$this->view->groupData = $groupData;
|
2013-07-12 14:33:17 +02:00
|
|
|
}
|
|
|
|
|
2013-09-26 17:02:56 +02:00
|
|
|
public function commentsAction()
|
|
|
|
{
|
2014-06-06 09:37:37 +02:00
|
|
|
$this->addTitleTab('comments');
|
2014-03-09 19:31:59 +01:00
|
|
|
$this->setAutorefreshInterval(12);
|
2014-06-06 09:37:37 +02:00
|
|
|
$query = $this->backend->select()->from('comment', array(
|
|
|
|
'id' => 'comment_internal_id',
|
|
|
|
'objecttype' => 'comment_objecttype',
|
|
|
|
'comment' => 'comment_data',
|
|
|
|
'author' => 'comment_author',
|
|
|
|
'timestamp' => 'comment_timestamp',
|
|
|
|
'type' => 'comment_type',
|
|
|
|
'persistent' => 'comment_is_persistent',
|
|
|
|
'expiration' => 'comment_expiration',
|
|
|
|
'host' => 'comment_host',
|
|
|
|
'service' => 'comment_service'
|
|
|
|
));
|
|
|
|
$this->applyFilters($query);
|
2013-09-26 17:02:56 +02:00
|
|
|
$this->view->comments = $query->paginate();
|
|
|
|
|
|
|
|
$this->setupSortControl(
|
|
|
|
array(
|
2014-03-09 19:39:32 +01:00
|
|
|
'comment_timestamp' => 'Comment Timestamp',
|
2014-03-09 20:05:59 +01:00
|
|
|
'comment_host' => 'Host / Service',
|
2014-03-09 19:39:32 +01:00
|
|
|
'comment_type' => 'Comment Type',
|
2014-03-09 20:05:59 +01:00
|
|
|
'comment_expiration' => 'Expiration',
|
2013-09-26 17:02:56 +02:00
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2013-10-15 12:49:58 +02:00
|
|
|
public function servicegroupsAction()
|
|
|
|
{
|
2014-09-04 16:31:10 +02:00
|
|
|
if ($url = $this->hasBetterUrl()) {
|
|
|
|
return $this->redirectNow($url);
|
|
|
|
}
|
2014-03-07 11:14:19 +01:00
|
|
|
$this->addTitleTab('servicegroups');
|
2014-06-06 09:37:37 +02:00
|
|
|
$this->setAutorefreshInterval(12);
|
|
|
|
$query = $this->backend->select()->from('groupsummary', array(
|
|
|
|
'servicegroup',
|
|
|
|
'hosts_up',
|
|
|
|
'hosts_unreachable_handled',
|
|
|
|
'hosts_unreachable_unhandled',
|
|
|
|
'hosts_down_handled',
|
|
|
|
'hosts_down_unhandled',
|
|
|
|
'hosts_pending',
|
|
|
|
'services_ok',
|
|
|
|
'services_unknown_handled',
|
|
|
|
'services_unknown_unhandled',
|
|
|
|
'services_critical_handled',
|
|
|
|
'services_critical_unhandled',
|
|
|
|
'services_warning_handled',
|
|
|
|
'services_warning_unhandled',
|
|
|
|
'services_pending'
|
|
|
|
));
|
|
|
|
$this->applyFilters($query);
|
2013-10-15 14:55:01 +02:00
|
|
|
$this->view->servicegroups = $query->paginate();
|
|
|
|
$this->setupSortControl(array(
|
|
|
|
'servicegroup_name' => 'Servicegroup Name'
|
|
|
|
));
|
2013-10-15 12:49:58 +02:00
|
|
|
}
|
|
|
|
|
2013-10-15 15:12:59 +02:00
|
|
|
public function hostgroupsAction()
|
|
|
|
{
|
2014-09-04 16:31:10 +02:00
|
|
|
if ($url = $this->hasBetterUrl()) {
|
|
|
|
return $this->redirectNow($url);
|
|
|
|
}
|
2014-02-21 11:42:03 +01:00
|
|
|
$this->addTitleTab('hostgroups');
|
2014-06-06 09:37:37 +02:00
|
|
|
$this->setAutorefreshInterval(12);
|
|
|
|
$query = $this->backend->select()->from('groupsummary', array(
|
|
|
|
'hostgroup',
|
|
|
|
'hosts_up',
|
|
|
|
'hosts_unreachable_handled',
|
|
|
|
'hosts_unreachable_unhandled',
|
|
|
|
'hosts_down_handled',
|
|
|
|
'hosts_down_unhandled',
|
|
|
|
'hosts_pending',
|
|
|
|
'services_ok',
|
|
|
|
'services_unknown_handled',
|
|
|
|
'services_unknown_unhandled',
|
|
|
|
'services_critical_handled',
|
|
|
|
'services_critical_unhandled',
|
|
|
|
'services_warning_handled',
|
|
|
|
'services_warning_unhandled',
|
|
|
|
'services_pending'
|
|
|
|
));
|
|
|
|
$this->applyFilters($query);
|
2013-10-15 15:12:59 +02:00
|
|
|
$this->view->hostgroups = $query->paginate();
|
|
|
|
$this->setupSortControl(array(
|
|
|
|
'hostgroup_name' => 'Hostgroup Name'
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
2013-10-14 12:56:06 +02:00
|
|
|
public function eventhistoryAction()
|
|
|
|
{
|
2014-03-04 13:33:02 +01:00
|
|
|
$this->addTitleTab('eventhistory');
|
2014-06-06 09:37:37 +02:00
|
|
|
$query = $this->backend->select()->from('eventHistory', array(
|
|
|
|
'host_name',
|
|
|
|
'service_description',
|
|
|
|
'object_type',
|
|
|
|
'timestamp',
|
|
|
|
'state',
|
|
|
|
'attempt',
|
|
|
|
'max_attempts',
|
|
|
|
'output',
|
|
|
|
'type',
|
|
|
|
'host',
|
|
|
|
'service'
|
|
|
|
));
|
2014-02-21 12:59:32 +01:00
|
|
|
|
2014-06-06 09:37:37 +02:00
|
|
|
$this->setupSortControl(array(
|
2014-09-05 18:44:29 +02:00
|
|
|
'timestamp' => 'Occurence'
|
2014-06-06 09:37:37 +02:00
|
|
|
));
|
|
|
|
$this->applyFilters($query);
|
2014-02-21 12:59:32 +01:00
|
|
|
$this->view->history = $query->paginate();
|
2013-10-14 12:56:06 +02:00
|
|
|
}
|
|
|
|
|
2014-03-12 14:41:17 +01:00
|
|
|
public function servicematrixAction()
|
|
|
|
{
|
|
|
|
$this->addTitleTab('servicematrix');
|
2014-06-06 09:37:37 +02:00
|
|
|
$this->setAutorefreshInterval(15);
|
2014-09-05 17:38:02 +02:00
|
|
|
$query = $this->backend->select()->from('serviceStatus', array(
|
2014-06-06 09:37:37 +02:00
|
|
|
'host_name',
|
|
|
|
'service_description',
|
|
|
|
'service_state',
|
|
|
|
'service_output',
|
|
|
|
'service_handled'
|
|
|
|
));
|
2014-09-05 17:38:02 +02:00
|
|
|
$this->applyFilters($query);
|
2014-06-06 09:37:37 +02:00
|
|
|
$this->setupSortControl(array(
|
|
|
|
'host_name' => 'Hostname',
|
|
|
|
'service_description' => 'Service description'
|
|
|
|
));
|
2014-09-05 17:38:02 +02:00
|
|
|
$pivot = $query->pivot('service_description', 'host_name');
|
2014-06-06 09:37:37 +02:00
|
|
|
$this->view->pivot = $pivot;
|
|
|
|
$this->view->horizontalPaginator = $pivot->paginateXAxis();
|
|
|
|
$this->view->verticalPaginator = $pivot->paginateYAxis();
|
|
|
|
}
|
2014-03-12 14:41:17 +01:00
|
|
|
|
2014-06-06 09:37:37 +02:00
|
|
|
protected function applyFilters($query)
|
|
|
|
{
|
2014-06-17 15:05:18 +02:00
|
|
|
$params = clone $this->params;
|
2014-06-25 11:00:10 +02:00
|
|
|
$request = $this->getRequest();
|
2014-06-17 15:05:18 +02:00
|
|
|
|
|
|
|
$limit = $params->shift('limit');
|
2014-09-02 14:07:46 +02:00
|
|
|
$sort = $params->shift('sort');
|
|
|
|
$dir = $params->shift('dir');
|
2014-06-17 15:05:18 +02:00
|
|
|
$page = $params->shift('page');
|
|
|
|
$format = $params->shift('format');
|
|
|
|
$view = $params->shift('view');
|
|
|
|
$backend = $params->shift('backend');
|
|
|
|
$modifyFilter = $params->shift('modifyFilter', false);
|
2014-06-20 13:26:10 +02:00
|
|
|
$removeFilter = $params->shift('removeFilter', false);
|
2014-06-17 15:05:18 +02:00
|
|
|
|
|
|
|
$filter = Filter::fromQueryString((string) $params);
|
2014-06-20 13:26:10 +02:00
|
|
|
$this->view->filterPreview = Widget::create('filterWidget', $filter);
|
|
|
|
|
|
|
|
if ($removeFilter) {
|
|
|
|
$redirect = $this->url->without('page');
|
|
|
|
if ($filter->getById($removeFilter)->isRootNode()) {
|
|
|
|
$redirect->setQueryString('');
|
|
|
|
} else {
|
|
|
|
$filter->removeId($removeFilter);
|
|
|
|
$redirect->setQueryString($filter->toQueryString())
|
2014-06-22 20:06:45 +02:00
|
|
|
->getParams()->add('modifyFilter');
|
2014-06-20 13:26:10 +02:00
|
|
|
}
|
|
|
|
$this->redirectNow($redirect);
|
|
|
|
}
|
|
|
|
|
2014-06-17 16:00:38 +02:00
|
|
|
if ($modifyFilter) {
|
2014-06-20 13:26:10 +02:00
|
|
|
if ($this->_request->isPost()) {
|
2014-07-17 09:26:15 +02:00
|
|
|
$filter = $filter->applyChanges($this->_request->getPost());
|
2014-06-20 13:26:10 +02:00
|
|
|
$this->redirectNow($this->url->without('page')->setQueryString($filter->toQueryString()));
|
|
|
|
}
|
|
|
|
$this->view->filterEditor = Widget::create('filterEditor', array(
|
2014-06-17 16:00:38 +02:00
|
|
|
'filter' => $filter,
|
|
|
|
'query' => $query
|
|
|
|
));
|
|
|
|
}
|
2014-07-08 16:36:05 +02:00
|
|
|
if (! $filter->isEmpty()) {
|
|
|
|
$query->applyFilter($filter);
|
|
|
|
}
|
2014-06-17 16:00:38 +02:00
|
|
|
$this->view->filter = $filter;
|
2014-09-02 14:07:46 +02:00
|
|
|
if ($sort) {
|
|
|
|
$query->order($sort, $dir);
|
|
|
|
}
|
2014-06-06 09:37:37 +02:00
|
|
|
$this->applyRestrictions($query);
|
|
|
|
$this->handleFormatRequest($query);
|
|
|
|
return $query;
|
2014-03-12 14:41:17 +01:00
|
|
|
}
|
|
|
|
|
2014-01-22 14:34:39 +01:00
|
|
|
/**
|
2014-05-07 09:40:23 +02:00
|
|
|
* Apply current user's `monitoring/filter' restrictions on the given data view
|
2014-01-22 14:34:39 +01:00
|
|
|
*/
|
2014-06-17 15:05:18 +02:00
|
|
|
protected function applyRestrictions($query)
|
2014-01-22 14:34:39 +01:00
|
|
|
{
|
|
|
|
foreach ($this->getRestrictions('monitoring/filter') as $restriction) {
|
2014-06-17 15:05:18 +02:00
|
|
|
// TODO: $query->applyFilter(Filter::fromQueryString());
|
2014-01-22 14:34:39 +01:00
|
|
|
}
|
2014-06-17 15:05:18 +02:00
|
|
|
return $query;
|
2014-01-22 14:34:39 +01:00
|
|
|
}
|
|
|
|
|
2014-06-06 09:37:37 +02:00
|
|
|
protected function extraColumns()
|
2014-03-21 11:24:17 +01:00
|
|
|
{
|
2014-06-06 09:37:37 +02:00
|
|
|
$columns = preg_split(
|
|
|
|
'~,~',
|
2014-06-17 15:05:18 +02:00
|
|
|
$this->params->shift('addcolumns', ''),
|
2014-06-06 09:37:37 +02:00
|
|
|
-1,
|
|
|
|
PREG_SPLIT_NO_EMPTY
|
|
|
|
);
|
|
|
|
$this->view->extraColumns = $columns;
|
|
|
|
return $columns;
|
2014-03-21 11:24:17 +01:00
|
|
|
}
|
|
|
|
|
2013-07-30 17:17:19 +02:00
|
|
|
/**
|
2013-09-03 18:43:17 +02:00
|
|
|
* Create a sort control box at the 'sortControl' view parameter
|
|
|
|
*
|
|
|
|
* @param array $columns An array containing the sort columns, with the
|
|
|
|
* submit value as the key and the value as the label
|
2013-07-30 17:17:19 +02:00
|
|
|
*/
|
2013-09-03 18:43:17 +02:00
|
|
|
private function setupSortControl(array $columns)
|
2013-07-30 17:17:19 +02:00
|
|
|
{
|
2013-09-03 18:43:17 +02:00
|
|
|
$this->view->sortControl = new SortBox(
|
|
|
|
$this->getRequest()->getActionName(),
|
|
|
|
$columns
|
|
|
|
);
|
|
|
|
$this->view->sortControl->applyRequest($this->getRequest());
|
|
|
|
}
|
|
|
|
|
2014-03-27 10:47:52 +01:00
|
|
|
protected function addTitleTab($action, $title = false)
|
2014-02-21 11:41:05 +01:00
|
|
|
{
|
2014-06-06 09:37:37 +02:00
|
|
|
$title = $title ?: ucfirst($action);
|
2014-02-21 11:41:05 +01:00
|
|
|
$this->getTabs()->add($action, array(
|
2014-06-06 09:37:37 +02:00
|
|
|
'title' => $title,
|
|
|
|
// 'url' => Url::fromPath('monitoring/list/' . $action)
|
|
|
|
'url' => $this->url
|
2014-02-21 11:41:05 +01:00
|
|
|
))->activate($action);
|
2014-06-06 09:37:37 +02:00
|
|
|
$this->view->title = $title;
|
2014-02-21 11:41:05 +01:00
|
|
|
}
|
|
|
|
|
2013-09-03 18:43:17 +02:00
|
|
|
/**
|
|
|
|
* Return all tabs for this controller
|
|
|
|
*
|
|
|
|
* @return Tabs
|
|
|
|
*/
|
|
|
|
private function createTabs()
|
|
|
|
{
|
|
|
|
$tabs = $this->getTabs();
|
2014-03-10 01:24:45 +01:00
|
|
|
if (in_array($this->_request->getActionName(), array(
|
|
|
|
'hosts',
|
|
|
|
'services',
|
|
|
|
'eventhistory',
|
|
|
|
'notifications'
|
|
|
|
))) {
|
|
|
|
$tabs->extend(new OutputFormat())->extend(new DashboardAction());
|
|
|
|
}
|
2013-07-30 17:17:19 +02:00
|
|
|
}
|
2013-06-27 10:14:41 +02:00
|
|
|
}
|