2014-09-24 07:47:26 +02:00
|
|
|
<?php
|
2015-02-04 10:46:36 +01:00
|
|
|
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
|
2014-09-24 07:47:26 +02:00
|
|
|
|
|
|
|
use Icinga\Data\Filter\Filter;
|
|
|
|
use Icinga\Module\Monitoring\Controller;
|
2014-11-14 11:17:22 +01:00
|
|
|
use Icinga\Module\Monitoring\Forms\Command\Object\AcknowledgeProblemCommandForm;
|
|
|
|
use Icinga\Module\Monitoring\Forms\Command\Object\CheckNowCommandForm;
|
|
|
|
use Icinga\Module\Monitoring\Forms\Command\Object\ObjectsCommandForm;
|
2014-12-12 12:44:31 +01:00
|
|
|
use Icinga\Module\Monitoring\Forms\Command\Object\ProcessCheckResultCommandForm;
|
2014-11-14 11:17:22 +01:00
|
|
|
use Icinga\Module\Monitoring\Forms\Command\Object\RemoveAcknowledgementCommandForm;
|
|
|
|
use Icinga\Module\Monitoring\Forms\Command\Object\ScheduleServiceCheckCommandForm;
|
|
|
|
use Icinga\Module\Monitoring\Forms\Command\Object\ScheduleServiceDowntimeCommandForm;
|
2015-03-06 09:23:11 +01:00
|
|
|
use Icinga\Module\Monitoring\Forms\Command\Object\AddCommentCommandForm;
|
|
|
|
use Icinga\Module\Monitoring\Forms\Command\Object\DeleteCommentCommandForm;
|
2014-09-24 07:47:26 +02:00
|
|
|
use Icinga\Module\Monitoring\Object\Host;
|
|
|
|
use Icinga\Module\Monitoring\Object\Service;
|
|
|
|
use Icinga\Module\Monitoring\Object\ServiceList;
|
2015-04-02 16:25:20 +02:00
|
|
|
use Icinga\Util\String;
|
2014-09-24 07:47:26 +02:00
|
|
|
use Icinga\Web\Url;
|
2015-04-07 16:29:10 +02:00
|
|
|
use Icinga\Web\UrlParams;
|
2015-04-02 16:25:20 +02:00
|
|
|
use Icinga\Web\Widget\Chart\InlinePie;
|
2014-09-24 07:47:26 +02:00
|
|
|
|
|
|
|
class Monitoring_ServicesController extends Controller
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var ServiceList
|
|
|
|
*/
|
|
|
|
protected $serviceList;
|
|
|
|
|
|
|
|
public function init()
|
|
|
|
{
|
|
|
|
$serviceList = new ServiceList($this->backend);
|
2014-11-20 17:45:18 +01:00
|
|
|
$serviceList->setFilter(Filter::fromQueryString((string) $this->params->without('service_problem', 'service_handled')));
|
2014-09-24 07:47:26 +02:00
|
|
|
$this->serviceList = $serviceList;
|
2015-03-05 18:32:38 +01:00
|
|
|
$this->view->listAllLink = Url::fromRequest()->setPath('monitoring/list/services');
|
2015-04-02 16:44:05 +02:00
|
|
|
|
|
|
|
$this->getTabs()->add(
|
|
|
|
'hosts',
|
|
|
|
array(
|
|
|
|
'title' => sprintf(
|
|
|
|
$this->translate('Show summarized information for hosts')
|
|
|
|
),
|
|
|
|
'label' => $this->translate('Hosts'),
|
|
|
|
'url' => Url::fromPath('monitoring/hosts/show')->setParams(Url::fromRequest()->getParams()),
|
|
|
|
'icon' => 'host'
|
|
|
|
)
|
|
|
|
)->activate('show');
|
|
|
|
|
2015-03-05 18:32:38 +01:00
|
|
|
$this->getTabs()->add(
|
|
|
|
'show',
|
|
|
|
array(
|
|
|
|
'title' => sprintf(
|
|
|
|
$this->translate('Show summarized information for %u services'),
|
|
|
|
count($this->serviceList)
|
|
|
|
),
|
|
|
|
'label' => $this->translate('Services'),
|
|
|
|
'url' => Url::fromRequest(),
|
|
|
|
'icon' => 'services'
|
|
|
|
)
|
|
|
|
)->activate('show');
|
2014-09-24 07:47:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
protected function handleCommandForm(ObjectsCommandForm $form)
|
|
|
|
{
|
2015-02-02 16:30:52 +01:00
|
|
|
$this->serviceList->setColumns(array(
|
|
|
|
'host_name',
|
2015-04-09 13:53:05 +02:00
|
|
|
'host_output',
|
2015-02-02 16:30:52 +01:00
|
|
|
'host_state',
|
2015-04-09 13:53:05 +02:00
|
|
|
'host_problem',
|
|
|
|
'host_handled',
|
2015-02-02 16:30:52 +01:00
|
|
|
'service_description',
|
|
|
|
'service_state',
|
|
|
|
'service_problem',
|
|
|
|
'service_handled',
|
|
|
|
'service_acknowledged',
|
2015-03-05 18:32:38 +01:00
|
|
|
'service_in_downtime',
|
|
|
|
'service_is_flapping',
|
|
|
|
'service_notifications_enabled',
|
|
|
|
'service_output',
|
2015-03-06 09:23:11 +01:00
|
|
|
'service_last_ack',
|
2015-04-09 15:44:21 +02:00
|
|
|
'service_last_comment',
|
|
|
|
'service_active_checks_enabled',
|
|
|
|
'service_passive_checks_enabled'
|
2015-02-02 16:30:52 +01:00
|
|
|
));
|
|
|
|
|
2014-09-24 07:47:26 +02:00
|
|
|
$form
|
|
|
|
->setObjects($this->serviceList)
|
|
|
|
->setRedirectUrl(Url::fromPath('monitoring/services/show')->setParams($this->params))
|
|
|
|
->handleRequest();
|
2015-02-02 16:30:52 +01:00
|
|
|
|
2014-09-24 07:47:26 +02:00
|
|
|
$this->view->form = $form;
|
2015-02-02 16:30:52 +01:00
|
|
|
$this->view->objects = $this->serviceList;
|
2015-04-09 13:53:05 +02:00
|
|
|
$this->view->stats = $this->serviceList->getServiceStateSummary();
|
|
|
|
$this->view->serviceStates = true;
|
|
|
|
$this->view->serviceStatesPieChart = InlinePie::createFromStateSummary(
|
|
|
|
$this->view->stats,
|
|
|
|
$this->translate('Service State'),
|
|
|
|
InlinePie::$colorsServiceStatesHandleUnhandled
|
|
|
|
);
|
|
|
|
$this->view->hostStates = $this->serviceList->getHostStateSummary();
|
|
|
|
$this->view->hostStatesPieChart = InlinePie::createFromStateSummary(
|
|
|
|
$this->view->hostStates,
|
|
|
|
$this->translate('Service State'),
|
|
|
|
InlinePie::$colorsHostStatesHandledUnhandled
|
|
|
|
);
|
2015-02-02 16:30:52 +01:00
|
|
|
$this->_helper->viewRenderer('partials/command/objects-command-form', null, true);
|
2014-09-24 07:47:26 +02:00
|
|
|
return $form;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function showAction()
|
|
|
|
{
|
|
|
|
$this->setAutorefreshInterval(15);
|
|
|
|
$checkNowForm = new CheckNowCommandForm();
|
|
|
|
$checkNowForm
|
|
|
|
->setObjects($this->serviceList)
|
|
|
|
->handleRequest();
|
|
|
|
$this->view->checkNowForm = $checkNowForm;
|
|
|
|
$this->serviceList->setColumns(array(
|
|
|
|
'host_name',
|
2015-03-05 18:32:38 +01:00
|
|
|
'host_output',
|
2014-09-24 07:47:26 +02:00
|
|
|
'host_state',
|
2015-04-02 16:25:20 +02:00
|
|
|
'host_problem',
|
|
|
|
'host_handled',
|
2015-03-05 18:32:38 +01:00
|
|
|
'service_output',
|
2014-09-24 07:47:26 +02:00
|
|
|
'service_description',
|
|
|
|
'service_state',
|
|
|
|
'service_problem',
|
|
|
|
'service_handled',
|
|
|
|
'service_acknowledged',
|
2015-03-05 18:32:38 +01:00
|
|
|
'service_in_downtime',
|
|
|
|
'service_is_flapping',
|
2014-09-24 07:47:26 +02:00
|
|
|
'service_notifications_enabled',
|
2015-03-05 18:32:38 +01:00
|
|
|
'service_last_comment',
|
2015-04-09 15:44:21 +02:00
|
|
|
'service_last_ack',
|
|
|
|
'service_active_checks_enabled',
|
|
|
|
'service_passive_checks_enabled'
|
|
|
|
/*
|
2014-09-24 07:47:26 +02:00
|
|
|
'service_event_handler_enabled',
|
|
|
|
'service_flap_detection_enabled',
|
|
|
|
'service_obsessing'*/
|
|
|
|
));
|
2015-03-06 17:52:06 +01:00
|
|
|
|
|
|
|
$acknowledgedObjects = $this->serviceList->getAcknowledgedObjects();
|
2014-09-24 07:47:26 +02:00
|
|
|
if (! empty($acknowledgedObjects)) {
|
|
|
|
$removeAckForm = new RemoveAcknowledgementCommandForm();
|
|
|
|
$removeAckForm
|
|
|
|
->setObjects($acknowledgedObjects)
|
|
|
|
->handleRequest();
|
|
|
|
$this->view->removeAckForm = $removeAckForm;
|
|
|
|
}
|
2015-04-02 16:25:20 +02:00
|
|
|
|
|
|
|
$serviceStates = $this->serviceList->getServiceStateSummary();
|
|
|
|
$this->view->serviceStatesPieChart = InlinePie::createFromStateSummary(
|
|
|
|
$serviceStates,
|
|
|
|
$this->translate('Service State'),
|
|
|
|
InlinePie::$colorsServiceStatesHandleUnhandled
|
|
|
|
);
|
|
|
|
|
|
|
|
$hostStates = $this->serviceList->getHostStateSummary();
|
|
|
|
$this->view->hostStatesPieChart = InlinePie::createFromStateSummary(
|
|
|
|
$hostStates,
|
|
|
|
$this->translate('Host State'),
|
|
|
|
InlinePie::$colorsHostStatesHandledUnhandled
|
|
|
|
);
|
2014-09-24 07:47:26 +02:00
|
|
|
$this->setAutorefreshInterval(15);
|
|
|
|
$this->view->rescheduleAllLink = Url::fromRequest()->setPath('monitoring/services/reschedule-check');
|
|
|
|
$this->view->downtimeAllLink = Url::fromRequest()->setPath('monitoring/services/schedule-downtime');
|
2014-12-11 15:52:23 +01:00
|
|
|
$this->view->processCheckResultAllLink = Url::fromRequest()->setPath(
|
|
|
|
'monitoring/services/process-check-result'
|
|
|
|
);
|
2015-03-06 09:23:11 +01:00
|
|
|
$this->view->addCommentLink = Url::fromRequest()->setPath('monitoring/services/add-comment');
|
|
|
|
$this->view->deleteCommentLink = Url::fromRequest()->setPath('monitoring/services/delete-comment');
|
2015-04-02 16:25:20 +02:00
|
|
|
$this->view->stats = $serviceStates;
|
|
|
|
$this->view->hostStats = $hostStates;
|
2014-09-24 07:47:26 +02:00
|
|
|
$this->view->objects = $this->serviceList;
|
2015-04-07 16:29:10 +02:00
|
|
|
$this->view->unhandledObjects = $this->serviceList->getUnhandledObjects();
|
|
|
|
$this->view->problemObjects = $this->serviceList->getProblemObjects();
|
2014-12-29 12:11:49 +01:00
|
|
|
$this->view->acknowledgeUnhandledLink = Url::fromPath('monitoring/services/acknowledge-problem')
|
2015-04-09 11:19:13 +02:00
|
|
|
->setQueryString($this->serviceList->getUnhandledObjects()->objectsFilter()->toQueryString());
|
2014-12-29 12:11:49 +01:00
|
|
|
$this->view->downtimeUnhandledLink = Url::fromPath('monitoring/services/schedule-downtime')
|
2015-04-09 11:19:13 +02:00
|
|
|
->setQueryString($this->serviceList->getUnhandledObjects()->objectsFilter()->toQueryString());
|
2015-04-07 16:29:10 +02:00
|
|
|
$this->view->downtimeLink = Url::fromPath('monitoring/services/schedule-downtime')
|
2015-04-09 11:19:13 +02:00
|
|
|
->setQueryString($this->serviceList->getProblemObjects()->objectsFilter()->toQueryString());
|
2014-09-24 07:47:26 +02:00
|
|
|
$this->view->acknowledgedObjects = $acknowledgedObjects;
|
2015-04-07 16:29:10 +02:00
|
|
|
$this->view->objectsInDowntime = $this->serviceList->getObjectsInDowntime();
|
2014-12-29 12:25:41 +01:00
|
|
|
$this->view->inDowntimeLink = Url::fromPath('monitoring/list/downtimes')
|
2015-04-09 11:19:13 +02:00
|
|
|
->setQueryString($this->serviceList->getObjectsInDowntime()
|
|
|
|
->objectsFilter(array('host' => 'downtime_host', 'service' => 'downtime_service'))->toQueryString());
|
2015-02-03 12:35:06 +01:00
|
|
|
$this->view->commentsLink = Url::fromRequest()
|
2014-09-24 07:47:26 +02:00
|
|
|
->setPath('monitoring/list/comments');
|
2015-04-07 18:00:36 +02:00
|
|
|
$this->view->baseFilter = $this->serviceList->getFilter();
|
2014-09-24 07:47:26 +02:00
|
|
|
}
|
|
|
|
|
2015-03-06 09:23:11 +01:00
|
|
|
/**
|
|
|
|
* Add a service comment
|
|
|
|
*/
|
|
|
|
public function addCommentAction()
|
|
|
|
{
|
|
|
|
$this->assertPermission('monitoring/command/comment/add');
|
|
|
|
|
|
|
|
$form = new AddCommentCommandForm();
|
|
|
|
$form->setTitle($this->translate('Add Service Comments'));
|
|
|
|
$this->handleCommandForm($form);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Delete a comment
|
|
|
|
*/
|
|
|
|
public function deleteCommentAction()
|
|
|
|
{
|
|
|
|
$this->assertPermission('monitoring/command/comment/delete');
|
|
|
|
|
|
|
|
$form = new DeleteCommentCommandForm();
|
|
|
|
$form->setTitle($this->translate('Delete Service Comments'));
|
|
|
|
$this->handleCommandForm($form);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-09-24 07:47:26 +02:00
|
|
|
/**
|
|
|
|
* Acknowledge service problems
|
|
|
|
*/
|
|
|
|
public function acknowledgeProblemAction()
|
|
|
|
{
|
2015-02-03 17:36:16 +01:00
|
|
|
$this->assertPermission('monitoring/command/acknowledge-problem');
|
|
|
|
|
2015-03-02 18:39:10 +01:00
|
|
|
$form = new AcknowledgeProblemCommandForm();
|
|
|
|
$form->setTitle($this->translate('Acknowledge Service Problems'));
|
|
|
|
$this->handleCommandForm($form);
|
2014-09-24 07:47:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reschedule service checks
|
|
|
|
*/
|
|
|
|
public function rescheduleCheckAction()
|
|
|
|
{
|
2015-02-03 17:36:16 +01:00
|
|
|
$this->assertPermission('monitoring/command/schedule-check');
|
|
|
|
|
2015-03-02 18:39:10 +01:00
|
|
|
$form = new ScheduleServiceCheckCommandForm();
|
|
|
|
$form->setTitle($this->translate('Reschedule Service Checks'));
|
|
|
|
$this->handleCommandForm($form);
|
2014-09-24 07:47:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Schedule service downtimes
|
|
|
|
*/
|
|
|
|
public function scheduleDowntimeAction()
|
|
|
|
{
|
2015-02-03 17:36:16 +01:00
|
|
|
$this->assertPermission('monitoring/command/downtime/schedule');
|
|
|
|
|
2015-03-02 18:39:10 +01:00
|
|
|
$form = new ScheduleServiceDowntimeCommandForm();
|
|
|
|
$form->setTitle($this->translate('Schedule Service Downtimes'));
|
|
|
|
$this->handleCommandForm($form);
|
2014-09-24 07:47:26 +02:00
|
|
|
}
|
2014-12-11 15:52:23 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Submit passive service check results
|
|
|
|
*/
|
|
|
|
public function processCheckResultAction()
|
|
|
|
{
|
2015-02-03 17:36:16 +01:00
|
|
|
$this->assertPermission('monitoring/command/process-check-result');
|
|
|
|
|
2015-03-02 18:39:10 +01:00
|
|
|
$form = new ProcessCheckResultCommandForm();
|
|
|
|
$form->setTitle($this->translate('Submit Passive Service Check Results'));
|
|
|
|
$this->handleCommandForm($form);
|
2014-12-11 15:52:23 +01:00
|
|
|
}
|
2014-09-24 07:47:26 +02:00
|
|
|
}
|