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\ScheduleHostCheckCommandForm;
|
|
|
|
use Icinga\Module\Monitoring\Forms\Command\Object\ScheduleHostDowntimeCommandForm;
|
2015-03-06 12:31:34 +01:00
|
|
|
use Icinga\Module\Monitoring\Forms\Command\Object\AddCommentCommandForm;
|
2014-09-24 07:47:26 +02:00
|
|
|
use Icinga\Module\Monitoring\Object\Host;
|
|
|
|
use Icinga\Module\Monitoring\Object\HostList;
|
|
|
|
use Icinga\Web\Url;
|
2015-04-02 16:25:20 +02:00
|
|
|
use Icinga\Web\Widget\Chart\InlinePie;
|
2014-09-24 07:47:26 +02:00
|
|
|
|
|
|
|
class Monitoring_HostsController extends Controller
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var HostList
|
|
|
|
*/
|
|
|
|
protected $hostList;
|
|
|
|
|
|
|
|
public function init()
|
|
|
|
{
|
2015-04-02 16:44:05 +02:00
|
|
|
// Support switching from service-view using the host and service selection. The filter would error
|
|
|
|
// on any occurrence of a filter based on service.
|
|
|
|
$filterString = preg_replace('/(service=[^)&]*)/', '', (string)$this->params);
|
|
|
|
|
2014-09-24 07:47:26 +02:00
|
|
|
$hostList = new HostList($this->backend);
|
2015-04-02 16:44:05 +02:00
|
|
|
$hostList->setFilter(Filter::fromQueryString($filterString));
|
2014-09-24 07:47:26 +02:00
|
|
|
$this->hostList = $hostList;
|
2015-04-02 16:44:05 +02:00
|
|
|
|
2015-03-06 12:53:58 +01:00
|
|
|
$this->getTabs()->add(
|
|
|
|
'show',
|
|
|
|
array(
|
|
|
|
'title' => sprintf(
|
|
|
|
$this->translate('Show summarized information for %u hosts'),
|
|
|
|
count($this->hostList)
|
|
|
|
),
|
|
|
|
'label' => $this->translate('Hosts'),
|
|
|
|
'url' => Url::fromRequest(),
|
|
|
|
'icon' => 'host'
|
|
|
|
)
|
|
|
|
)->activate('show');
|
2015-04-02 16:44:05 +02:00
|
|
|
|
|
|
|
$this->getTabs()->add(
|
|
|
|
'services',
|
|
|
|
array(
|
|
|
|
'title' => sprintf(
|
|
|
|
$this->translate('Show summarized information for related services')
|
|
|
|
),
|
|
|
|
'label' => $this->translate('Services'),
|
|
|
|
'url' => Url::fromPath('monitoring/services/show')->setParams(Url::fromRequest()->getParams()),
|
|
|
|
'icon' => 'services'
|
|
|
|
)
|
|
|
|
)->activate('show');
|
|
|
|
|
2015-04-07 17:43:45 +02:00
|
|
|
$this->view->listAllLink = Url::fromRequest()->setPath('monitoring/list/hosts')->setQueryString($filterString);
|
2014-09-24 07:47:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
protected function handleCommandForm(ObjectsCommandForm $form)
|
|
|
|
{
|
2015-02-02 16:30:52 +01:00
|
|
|
$this->hostList->setColumns(array(
|
|
|
|
'host_name',
|
|
|
|
'host_state',
|
|
|
|
'host_problem',
|
|
|
|
'host_handled',
|
|
|
|
'host_acknowledged',
|
2015-03-06 12:31:34 +01:00
|
|
|
'host_in_downtime',
|
|
|
|
'host_last_ack',
|
|
|
|
'host_is_flapping',
|
|
|
|
'host_last_comment',
|
|
|
|
'host_output',
|
|
|
|
'host_notifications_enabled'
|
2015-02-02 16:30:52 +01:00
|
|
|
));
|
|
|
|
|
2014-09-24 07:47:26 +02:00
|
|
|
$form
|
|
|
|
->setObjects($this->hostList)
|
|
|
|
->setRedirectUrl(Url::fromPath('monitoring/hosts/show')->setParams($this->params))
|
|
|
|
->handleRequest();
|
2015-02-02 16:30:52 +01:00
|
|
|
|
|
|
|
$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->hostList as $host) {
|
|
|
|
++$hostStates[$host::getStateText($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->hostList;
|
|
|
|
$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->hostList)
|
|
|
|
->handleRequest();
|
|
|
|
$this->view->checkNowForm = $checkNowForm;
|
|
|
|
$this->hostList->setColumns(array(
|
|
|
|
'host_name',
|
|
|
|
'host_state',
|
|
|
|
'host_problem',
|
|
|
|
'host_handled',
|
|
|
|
'host_acknowledged',
|
2015-03-06 12:31:34 +01:00
|
|
|
'host_in_downtime',
|
|
|
|
'host_last_ack',
|
|
|
|
'host_is_flapping',
|
|
|
|
'host_last_comment',
|
|
|
|
'host_output',
|
|
|
|
'host_notifications_enabled',/*,
|
2014-09-24 07:47:26 +02:00
|
|
|
'host_passive_checks_enabled',
|
|
|
|
'host_event_handler_enabled',
|
|
|
|
'host_flap_detection_enabled',
|
|
|
|
'host_active_checks_enabled',
|
|
|
|
'host_obsessing'*/
|
|
|
|
));
|
2015-03-06 17:52:06 +01:00
|
|
|
|
|
|
|
$acknowledgedObjects = $this->hostList->getAcknowledgedObjects();
|
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 18:03:56 +01:00
|
|
|
|
2015-04-02 16:25:20 +02:00
|
|
|
$hostStates = (object)$this->hostList->getStateSummary();
|
|
|
|
$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/hosts/reschedule-check');
|
|
|
|
$this->view->downtimeAllLink = Url::fromRequest()->setPath('monitoring/hosts/schedule-downtime');
|
2014-12-11 15:52:23 +01:00
|
|
|
$this->view->processCheckResultAllLink = Url::fromRequest()->setPath('monitoring/hosts/process-check-result');
|
2015-03-06 12:31:34 +01:00
|
|
|
$this->view->addCommentLink = Url::fromRequest()->setPath('monitoring/hosts/add-comment');
|
|
|
|
$this->view->deleteCommentLink = Url::fromRequest()->setPath('monitoring/hosts/delete-comment');
|
2015-04-02 16:25:20 +02:00
|
|
|
$this->view->stats = $hostStates;
|
2014-09-24 07:47:26 +02:00
|
|
|
$this->view->objects = $this->hostList;
|
2015-04-07 16:29:10 +02:00
|
|
|
$this->view->unhandledObjects = $this->hostList->getUnhandledObjects();
|
|
|
|
$this->view->problemObjects = $this->hostList->getProblemObjects();
|
|
|
|
|
2014-12-29 12:17:17 +01:00
|
|
|
$this->view->acknowledgeUnhandledLink = Url::fromPath('monitoring/hosts/acknowledge-problem')
|
2015-04-07 16:29:10 +02:00
|
|
|
->setQueryString($this->hostList->getUnhandledObjects()->filterFromResult());
|
2014-12-29 12:17:17 +01:00
|
|
|
$this->view->downtimeUnhandledLink = Url::fromPath('monitoring/hosts/schedule-downtime')
|
2015-04-07 16:29:10 +02:00
|
|
|
->setQueryString($this->hostList->getUnhandledObjects()->filterFromResult());
|
|
|
|
$this->view->downtimeLink = Url::fromPath('monitoring/hosts/schedule-downtime')
|
|
|
|
->setQueryString($this->hostList->getProblemObjects()->filterFromResult());
|
|
|
|
$this->view->acknowledgedObjects = $this->hostList->getAcknowledgedObjects();
|
|
|
|
$this->view->objectsInDowntime = $this->hostList->getObjectsInDowntime();
|
2014-12-29 12:19:37 +01:00
|
|
|
$this->view->inDowntimeLink = Url::fromPath('monitoring/list/downtimes')
|
2015-04-07 16:29:10 +02:00
|
|
|
->setQueryString($this->hostList->getObjectsInDowntime()->filterFromResult());
|
|
|
|
|
2015-04-02 16:51:09 +02:00
|
|
|
$this->view->commentsLink = Url::fromRequest()->setPath('monitoring/list/comments');
|
2014-09-24 07:47:26 +02:00
|
|
|
}
|
|
|
|
|
2015-03-06 12:31:34 +01:00
|
|
|
/**
|
|
|
|
* Add a host comments
|
|
|
|
*/
|
|
|
|
public function addCommentAction()
|
|
|
|
{
|
|
|
|
$this->assertPermission('monitoring/command/comment/add');
|
|
|
|
|
|
|
|
$form = new AddCommentCommandForm();
|
|
|
|
$form->setTitle($this->translate('Add Host Comments'));
|
|
|
|
$this->handleCommandForm($form);
|
|
|
|
}
|
|
|
|
|
2015-03-06 13:27:48 +01:00
|
|
|
/**
|
|
|
|
* Delete a comment
|
|
|
|
*/
|
|
|
|
public function deleteCommentAction()
|
|
|
|
{
|
|
|
|
$this->assertPermission('monitoring/command/comment/delete');
|
|
|
|
|
|
|
|
$form = new DeleteCommentCommandForm();
|
|
|
|
$form->setTitle($this->translate('Delete Host Comments'));
|
|
|
|
$this->handleCommandForm($form);
|
|
|
|
}
|
|
|
|
|
2014-09-24 07:47:26 +02:00
|
|
|
/**
|
|
|
|
* Acknowledge host 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 Host Problems'));
|
|
|
|
$this->handleCommandForm($form);
|
2014-09-24 07:47:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reschedule host 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 ScheduleHostCheckCommandForm();
|
|
|
|
$form->setTitle($this->translate('Reschedule Host Checks'));
|
|
|
|
$this->handleCommandForm($form);
|
2014-09-24 07:47:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Schedule host 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 ScheduleHostDowntimeCommandForm();
|
|
|
|
$form->setTitle($this->translate('Schedule Host Downtimes'));
|
|
|
|
$this->handleCommandForm($form);
|
2014-09-24 07:47:26 +02:00
|
|
|
}
|
2014-12-11 15:52:23 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Submit passive host 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 Host Check Results'));
|
|
|
|
$this->handleCommandForm($form);
|
2014-12-11 15:52:23 +01:00
|
|
|
}
|
2014-09-24 07:47:26 +02:00
|
|
|
}
|