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;
|
|
|
|
use Icinga\Web\Url;
|
|
|
|
|
|
|
|
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');
|
|
|
|
$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',
|
|
|
|
'host_state',
|
|
|
|
'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',
|
|
|
|
'service_last_comment'
|
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
|
|
|
|
|
|
|
$serviceStates = array(
|
|
|
|
Service::getStateText(Service::STATE_OK) => 0,
|
|
|
|
Service::getStateText(Service::STATE_WARNING) => 0,
|
|
|
|
Service::getStateText(Service::STATE_CRITICAL) => 0,
|
|
|
|
Service::getStateText(Service::STATE_UNKNOWN) => 0,
|
|
|
|
Service::getStateText(Service::STATE_PENDING) => 0
|
|
|
|
);
|
|
|
|
$knownHostStates = array();
|
|
|
|
$hostStates = array(
|
|
|
|
Host::getStateText(Host::STATE_UP) => 0,
|
|
|
|
Host::getStateText(Host::STATE_DOWN) => 0,
|
|
|
|
Host::getStateText(Host::STATE_UNREACHABLE) => 0,
|
|
|
|
Host::getStateText(Host::STATE_PENDING) => 0,
|
|
|
|
);
|
|
|
|
foreach ($this->serviceList as $service) {
|
|
|
|
++$serviceStates[$service::getStateText($service->state)];
|
|
|
|
if (! isset($knownHostStates[$service->getHost()->getName()])) {
|
|
|
|
$knownHostStates[$service->getHost()->getName()] = true;
|
|
|
|
++$hostStates[$service->getHost()->getStateText($service->host_state)];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
$this->view->serviceStates = $serviceStates;
|
|
|
|
$this->view->hostStates = $hostStates;
|
|
|
|
$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-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',
|
|
|
|
'service_last_ack'
|
|
|
|
/*,
|
|
|
|
'service_passive_checks_enabled',
|
2014-09-24 07:47:26 +02:00
|
|
|
'service_event_handler_enabled',
|
|
|
|
'service_flap_detection_enabled',
|
|
|
|
'service_active_checks_enabled',
|
|
|
|
'service_obsessing'*/
|
|
|
|
));
|
|
|
|
$unhandledObjects = array();
|
2014-12-29 12:11:49 +01:00
|
|
|
$unhandledFilterExpressions = array();
|
2014-09-24 07:47:26 +02:00
|
|
|
$acknowledgedObjects = array();
|
|
|
|
$objectsInDowntime = array();
|
2014-12-29 12:25:41 +01:00
|
|
|
$downtimeFilterExpressions = array();
|
2015-03-05 18:32:38 +01:00
|
|
|
|
2015-03-06 17:30:59 +01:00
|
|
|
foreach ($this->serviceList as $service) {
|
2014-09-24 07:47:26 +02:00
|
|
|
/** @var Service $service */
|
|
|
|
if ((bool) $service->problem === true && (bool) $service->handled === false) {
|
|
|
|
$unhandledObjects[] = $service;
|
2014-12-29 12:11:49 +01:00
|
|
|
$unhandledFilterExpressions[] = Filter::matchAll(
|
|
|
|
Filter::where('host', $service->getHost()->getName()),
|
|
|
|
Filter::where('service', $service->getName())
|
|
|
|
);
|
2014-09-24 07:47:26 +02:00
|
|
|
}
|
|
|
|
if ((bool) $service->acknowledged === true) {
|
|
|
|
$acknowledgedObjects[] = $service;
|
|
|
|
}
|
|
|
|
if ((bool) $service->in_downtime === true) {
|
|
|
|
$objectsInDowntime[] = $service;
|
2014-12-29 12:25:41 +01:00
|
|
|
$downtimeFilterExpressions[] = Filter::matchAll(
|
|
|
|
Filter::where('downtime_host', $service->getHost()->getName()),
|
|
|
|
Filter::where('downtime_service', $service->getName())
|
|
|
|
);
|
2014-09-24 07:47:26 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (! empty($acknowledgedObjects)) {
|
|
|
|
$removeAckForm = new RemoveAcknowledgementCommandForm();
|
|
|
|
$removeAckForm
|
|
|
|
->setObjects($acknowledgedObjects)
|
|
|
|
->handleRequest();
|
|
|
|
$this->view->removeAckForm = $removeAckForm;
|
|
|
|
}
|
2015-03-06 09:23:11 +01:00
|
|
|
/*
|
2015-03-05 18:32:38 +01:00
|
|
|
if (! empty($objectsInDowntime)) {
|
|
|
|
$removeDowntimeForm = new DeleteDowntimeCommandForm();
|
2015-03-06 09:23:11 +01:00
|
|
|
$removeDowntimeForm
|
|
|
|
->setObjects($objectsInDowntime)
|
2015-03-05 18:32:38 +01:00
|
|
|
->handleRequest();
|
|
|
|
$this->view->removeDowntimeForm = $removeDowntimeForm;
|
|
|
|
}
|
2015-03-06 09:23:11 +01:00
|
|
|
*/
|
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-03-06 17:30:59 +01:00
|
|
|
$this->view->stats = $this->serviceList->getStateSummary();
|
2014-09-24 07:47:26 +02:00
|
|
|
$this->view->objects = $this->serviceList;
|
|
|
|
$this->view->unhandledObjects = $unhandledObjects;
|
2014-12-29 12:11:49 +01:00
|
|
|
$unhandledFilterQueryString = Filter::matchAny($unhandledFilterExpressions)->toQueryString();
|
|
|
|
$this->view->acknowledgeUnhandledLink = Url::fromPath('monitoring/services/acknowledge-problem')
|
|
|
|
->setQueryString($unhandledFilterQueryString);
|
|
|
|
$this->view->downtimeUnhandledLink = Url::fromPath('monitoring/services/schedule-downtime')
|
|
|
|
->setQueryString($unhandledFilterQueryString);
|
2014-09-24 07:47:26 +02:00
|
|
|
$this->view->acknowledgedObjects = $acknowledgedObjects;
|
|
|
|
$this->view->objectsInDowntime = $objectsInDowntime;
|
2014-12-29 12:25:41 +01:00
|
|
|
$this->view->inDowntimeLink = Url::fromPath('monitoring/list/downtimes')
|
|
|
|
->setQueryString(Filter::matchAny($downtimeFilterExpressions)->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-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
|
|
|
}
|