Skip to content

Commit

Permalink
Implement new layout for service multi-view
Browse files Browse the repository at this point in the history
refs #8565
  • Loading branch information
majentsch committed Mar 5, 2015
1 parent e2887df commit 860cc59
Show file tree
Hide file tree
Showing 12 changed files with 425 additions and 172 deletions.
Expand Up @@ -77,7 +77,8 @@ public function showAction()
count($this->hostList)
),
'label' => $this->translate('Hosts'),
'url' => Url::fromRequest()
'url' => Url::fromRequest(),
'icon' => 'host'
)
)->activate('show');
$this->setAutorefreshInterval(15);
Expand Down
89 changes: 61 additions & 28 deletions modules/monitoring/application/controllers/ServicesController.php
Expand Up @@ -10,6 +10,7 @@
use Icinga\Module\Monitoring\Forms\Command\Object\RemoveAcknowledgementCommandForm;
use Icinga\Module\Monitoring\Forms\Command\Object\ScheduleServiceCheckCommandForm;
use Icinga\Module\Monitoring\Forms\Command\Object\ScheduleServiceDowntimeCommandForm;
use Icinga\Module\Monitoring\Forms\Command\Object\DeleteDowntimeCommandForm;
use Icinga\Module\Monitoring\Object\Host;
use Icinga\Module\Monitoring\Object\Service;
use Icinga\Module\Monitoring\Object\ServiceList;
Expand All @@ -28,6 +29,19 @@ public function init()
$serviceList = new ServiceList($this->backend);
$serviceList->setFilter(Filter::fromQueryString((string) $this->params->without('service_problem', 'service_handled')));
$this->serviceList = $serviceList;
$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');
}

protected function handleCommandForm(ObjectsCommandForm $form)
Expand All @@ -40,7 +54,11 @@ protected function handleCommandForm(ObjectsCommandForm $form)
'service_problem',
'service_handled',
'service_acknowledged',
'service_in_downtime'
'service_in_downtime',
'service_is_flapping',
'service_notifications_enabled',
'service_output',
'service_last_ack'
));

$form
Expand Down Expand Up @@ -90,17 +108,6 @@ protected function handleCommandForm(ObjectsCommandForm $form)

public function showAction()
{
$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()
)
)->activate('show');
$this->setAutorefreshInterval(15);
$checkNowForm = new CheckNowCommandForm();
$checkNowForm
Expand All @@ -109,15 +116,21 @@ public function showAction()
$this->view->checkNowForm = $checkNowForm;
$this->serviceList->setColumns(array(
'host_name',
'host_output',
'host_state',
'service_output',
'service_description',
'service_state',
'service_problem',
'service_handled',
'service_acknowledged',
'service_in_downtime'/*,
'service_passive_checks_enabled',
'service_in_downtime',
'service_is_flapping',
'service_notifications_enabled',
'service_last_comment',
'service_last_ack'
/*,
'service_passive_checks_enabled',
'service_event_handler_enabled',
'service_flap_detection_enabled',
'service_active_checks_enabled',
Expand All @@ -129,22 +142,34 @@ public function showAction()
$objectsInDowntime = array();
$downtimeFilterExpressions = array();
$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
'services_' . Service::getStateText(Service::STATE_OK) => 0,
'services_' . Service::getStateText(Service::STATE_OK) . '_unhandled' => 0,
'services_' . Service::getStateText(Service::STATE_WARNING) => 0,
'services_' . Service::getStateText(Service::STATE_WARNING) . '_unhandled' => 0,
'services_' . Service::getStateText(Service::STATE_CRITICAL) => 0,
'services_' . Service::getStateText(Service::STATE_CRITICAL) . '_unhandled' => 0,
'services_' . Service::getStateText(Service::STATE_UNKNOWN) => 0,
'services_' . Service::getStateText(Service::STATE_UNKNOWN) . '_unhandled' => 0,
'services_' . Service::getStateText(Service::STATE_PENDING) => 0,
'services_' . Service::getStateText(Service::STATE_PENDING) . '_unhandled' => 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,
'hosts_' . Host::getStateText(Host::STATE_UP) => 0,
'hosts_' . Host::getStateText(Host::STATE_UP) . '_unhandled' => 0,
'hosts_' . Host::getStateText(Host::STATE_DOWN) => 0,
'hosts_' . Host::getStateText(Host::STATE_DOWN) . '_unhandled' => 0,
'hosts_' . Host::getStateText(Host::STATE_UNREACHABLE) => 0,
'hosts_' . Host::getStateText(Host::STATE_UNREACHABLE) . '_unhandled' => 0,
'hosts_' . Host::getStateText(Host::STATE_PENDING) => 0,
'hosts_' . Host::getStateText(Host::STATE_PENDING) . '_unhandled' => 0
);
foreach ($this->serviceList as $service) {
$unhandled = false;

/** @var Service $service */
if ((bool) $service->problem === true && (bool) $service->handled === false) {
$unhandled = true;
$unhandledObjects[] = $service;
$unhandledFilterExpressions[] = Filter::matchAll(
Filter::where('host', $service->getHost()->getName()),
Expand All @@ -161,10 +186,11 @@ public function showAction()
Filter::where('downtime_service', $service->getName())
);
}
++$serviceStates[$service::getStateText($service->state)];

++$serviceStates['services_' . $service::getStateText($service->state) . ($unhandled ? '_unhandled' : '')];
if (! isset($knownHostStates[$service->getHost()->getName()])) {
$knownHostStates[$service->getHost()->getName()] = true;
++$hostStates[$service->getHost()->getStateText($service->host_state)];
++$hostStates['hosts_' . $service->getHost()->getStateText($service->host_state)];
}
}
if (! empty($acknowledgedObjects)) {
Expand All @@ -174,15 +200,20 @@ public function showAction()
->handleRequest();
$this->view->removeAckForm = $removeAckForm;
}
if (! empty($objectsInDowntime)) {
$removeDowntimeForm = new DeleteDowntimeCommandForm();
$removeDowntimeForm->setObjects($objectsInDowntime)
->handleRequest();
$this->view->removeDowntimeForm = $removeDowntimeForm;
}
$this->setAutorefreshInterval(15);
$this->view->listAllLink = Url::fromRequest()->setPath('monitoring/list/services');
$this->view->rescheduleAllLink = Url::fromRequest()->setPath('monitoring/services/reschedule-check');
$this->view->downtimeAllLink = Url::fromRequest()->setPath('monitoring/services/schedule-downtime');
$this->view->processCheckResultAllLink = Url::fromRequest()->setPath(
'monitoring/services/process-check-result'
);
$this->view->hostStates = $hostStates;
$this->view->serviceStates = $serviceStates;
$this->view->hostStates = (object)$hostStates;
$this->view->serviceStates = (object)$serviceStates;
$this->view->objects = $this->serviceList;
$this->view->unhandledObjects = $unhandledObjects;
$unhandledFilterQueryString = Filter::matchAny($unhandledFilterExpressions)->toQueryString();
Expand All @@ -196,6 +227,7 @@ public function showAction()
->setQueryString(Filter::matchAny($downtimeFilterExpressions)->toQueryString());
$this->view->commentsLink = Url::fromRequest()
->setPath('monitoring/list/comments');
/*
$this->view->serviceStatesPieChart = $this->createPieChart(
$serviceStates,
$this->translate('Service State'),
Expand All @@ -206,6 +238,7 @@ public function showAction()
$this->translate('Host State'),
array('#44bb77', '#FF5566', '#E066FF', '#77AAFF')
);
*/
}

protected function createPieChart(array $states, $title, array $colors)
Expand Down
@@ -1,31 +1,19 @@
<div class="controls">

<?php if (! $this->compact): ?>
<?= $tabs; ?>
<?php endif ?>

<?php if (isset($serviceStates)): ?>
<h1><?= sprintf($this->translate('%d Services Selected'), count($objects)) ?></h1>
<?= $this->render('partials/service/objects-header.phtml'); ?>
<?php else: ?>
<h1><?= sprintf($this->translate('%d Hosts Selected'), count($objects)) ?></h1>
<?= $this->render('partials/host/objects-header.phtml'); ?>
<?php endif ?>
</div>

<div class="content objects-command">
<table class="objectlist">
<thead>
<tr>
<th><?= $this->icon('host'); ?> <?= $this->translate('Host'); ?></th>
<th><?= $this->icon('conf'); ?> <?= $this->translate('Service'); ?></th>
</tr>
</thead>
<tbody>
<?php foreach ($form->getObjects() as $object): /** @var \Icinga\Module\Monitoring\Object\MonitoredObject $object */ ?>
<tr>
<?php if ($object->getType() === $object::TYPE_HOST): ?>
<td colspan="2"><?= $this->escape($object->getName()); ?></td>
<?php else: ?>
<td><?= $this->escape($object->getHost()->getName()); ?></td>
<td><?= $this->escape($object->getName()); ?></td>
<?php endif ?>
</tr>
<?php endforeach ?>
</tbody>
</table>
<hr class="command-separator">
<?= $form; ?>
</div>
@@ -1,6 +1,7 @@
<?php if (! $this->compact): ?>
<?= $tabs; ?>
<?php endif ?>

<?php if (($hostCount = count($objects)) > 0): ?>
<div class="hbox-item">
<h1 tabindex="-1">
Expand All @@ -15,4 +16,4 @@
<?= sprintf('%s: %u', $this->translate(strtoupper($text)), $count); ?><br>
<?php endforeach ?>
</div>
<?php endif ?>
<?php endif ?>
Expand Up @@ -31,6 +31,7 @@ $currentUrl = Url::fromRequest()->without('limit')->getRelativeUrl();
<?php else: ?>
<?= $this->translate('No services configured on this host'); ?>
<?php endif; ?>

<span class="badges">
<?php if ($object->stats->services_ok): ?>
<span class="state ok<?= $currentUrl === $selfUrl->with('service_state', 0)->getRelativeUrl() ? ' active' : ''; ?>">
Expand Down
@@ -1,34 +1,85 @@
<?php if (! $this->compact): ?>
<?= $tabs; ?>
<?php endif ?>
<?php
use Icinga\Module\Monitoring\Object\Service;
use Icinga\Web\Url;
?>

<?php
$i = 0;
$hidden = array();
$hiddenRich = array();
?>
<?php if (($serviceCount = count($objects)) > 0): ?>
<div class="hbox">
<div class="hbox-item" style="width: 6em;">
<h1 tabindex="-1">
<?= sprintf($this->translatePlural('Service (%u)', 'Services (%u)', $serviceCount), $serviceCount); ?>
</h1>
</div>
<div class="hbox-item">
&nbsp;<?= $serviceStatesPieChart; ?>
</div>
<div class="hbox-item" style="font-size: 14px">
<?php foreach (array_filter($serviceStates) as $text => $count): ?>
<?= sprintf('%s: %u', $this->translate(strtoupper($text)), $count); ?><br>
<?php endforeach ?>
</div>
</div>
<div class="hbox">
<div class="hbox-item" style="width: 6em;">
<?php $hostCount = array_sum(array_values($hostStates)); ?>
<strong><?= sprintf($this->translatePlural('Host (%u)', 'Hosts (%u)', $hostCount), $hostCount); ?></strong>
</div>
<div class="hbox-item">
&nbsp;<?= $hostStatesPieChart; ?>
</div>
<div class="hbox-item" style="font-size: 14px">
<?php foreach (array_filter($hostStates) as $text => $count): ?>
<?= sprintf('%s: %u', $this->translate(strtoupper($text)), $count); ?><br>
<?php endforeach ?>
</div>
</div>
<?php endif ?>
<p>
<table class="state statesummary">
<thead>
<tr>
<th></th>
<th></th>
<th><?= $this->icon('service'); ?> <?= $this->translate('Service'); ?></th>
<th><?= $this->icon('host'); ?> <?= $this->translate('Host'); ?></th>
<th class="collapse"><?= $this->translate('Output'); ?></th>
</tr>
</thead>

<tbody>
<?php foreach ($objects as $service): /** @var Service $service */ ?>
<?php
$i++;
if ($i > 5) {
$desc = $service->getHost()->getName() . ' on ' . $service->getName();
$hidden[] = $desc;
$hiddenRich[] = sprintf("<div class='color-box badge-%s'></div>%s", $service->getStateText($service->service_state) ,$desc);
continue;
}
?>

<tr class="state <?= Service::getStateText($service->service_state); ?><?= $service->service_handled ? ' handled' : '' ?>">
<td class="state"><?= Service::getStateText($service->service_state, true); ?><br /></td>
<td>
<?php if (!$service->service_handled && $service->service_state > 0): ?>
<?= $this->icon('attention-alt', $this->translate('Unhandled')) ?>
<?php endif ?>

<?php if ($service->service_acknowledged && !$service->service_in_downtime): ?>
<?= $this->icon('ok', $this->translate('Acknowledged') . (
$service->service_last_ack ? ': ' . $service->service_last_ack : ''
)) ?>
<?php endif ?>

<?php if ($service->service_is_flapping): ?>
<?= $this->icon('flapping', $this->translate('Flapping')) ?>
<?php endif ?>

<?php if (!$service->service_notifications_enabled): ?>
<?= $this->icon('bell-off-empty', $this->translate('Notifications Disabled')) ?>
<?php endif ?>

<?php if ($service->service_in_downtime): ?>
<?= $this->icon('plug', $this->translate('In Downtime')) ?>
<?php endif ?>

<?php if (isset($service->service_last_comment) && $service->service_last_comment !== null): ?>
<?= $this->icon('comment', $this->translate('Last Comment: ') . $service->service_last_comment) ?>
<?php endif ?>
</td>
<td><?= $this->escape($service->getName()); ?></td>
<td><?= $this->escape($service->getHost()->getName()); ?></b></td>
<td><p class="pluginoutput collapse"><?= $this->escape($service->service_output) ?></p></td>
</tr>
<?php endforeach ?>

<?php if (count($hidden)): ?>
<tr>
<td>
<div class="selection-info" data-title-rich="<span align='left'><?= join('<br>', $hiddenRich) ?></span>"
title="<?= join(', ', $hidden) ?>">
<?= sprintf(t('%d more ...'), count($hidden)) ?>
</div>
</td>
</tr>
<?php endif ?>

</tbody>
</table>
</p>
<?php endif ?>

0 comments on commit 860cc59

Please sign in to comment.