Merge branch 'feature/translation-plural-8092'

resolves #8092
This commit is contained in:
Eric Lippmann 2014-12-30 10:50:17 +01:00
commit 07ddc3a455
13 changed files with 66 additions and 1753 deletions

View File

@ -1,282 +0,0 @@
<?php
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}
use Icinga\Module\Monitoring\Controller;
use Icinga\Web\Widget\Chart\InlinePie;
use Icinga\Module\Monitoring\Forms\Command\MultiCommandFlagForm;
use Icinga\Web\Widget;
use Icinga\Data\Filter\Filter;
/**
* Displays aggregations collections of multiple objects.
*/
class Monitoring_MultiController extends Controller
{
public function hostAction()
{
$errors = array();
$query = $this->backend->select()->from(
'hostStatus',
array(
'host_name',
'host_in_downtime',
'host_passive_checks_enabled',
'host_obsessing',
'host_state',
'host_notifications_enabled',
'host_event_handler_enabled',
'host_flap_detection_enabled',
'host_active_checks_enabled',
// columns intended for filter-request
'host_problem',
'host_handled'
)
)->getQuery();
$this->applyQueryFilter($query);
$hosts = $query->fetchAll();
$comments = $this->backend->select()->from('comment', array(
'comment_internal_id',
'comment_host',
));
$this->applyQueryFilter($comments);
$uniqueComments = array_keys($this->getUniqueValues($comments->getQuery()->fetchAll(), 'comment_internal_id'));
// Populate view
$this->view->objects = $this->view->hosts = $hosts;
$this->view->problems = $this->getProblems($hosts);
$this->view->comments = $uniqueComments;
$this->view->hostnames = $this->getProperties($hosts, 'host_name');
$this->view->downtimes = $this->getDowntimes($hosts);
$this->view->errors = $errors;
$this->view->states = $this->countStates($hosts, 'host', 'host_name');
$this->view->pie = $this->createPie(
$this->view->states,
$this->view->getHelper('MonitoringState')->getHostStateColors(),
mt('monitoring', 'Host State')
);
// Handle configuration changes
$this->handleConfigurationForm(array(
'host_passive_checks_enabled' => $this->translate('Passive Checks'),
'host_active_checks_enabled' => $this->translate('Active Checks'),
'host_notifications_enabled' => $this->translate('Notifications'),
'host_event_handler_enabled' => $this->translate('Event Handler'),
'host_flap_detection_enabled' => $this->translate('Flap Detection'),
'host_obsessing' => $this->translate('Obsessing')
));
}
public function serviceAction()
{
$errors = array();
$query = $this->backend->select()->from('serviceStatus', array(
'host_name',
'host_state',
'service_description',
'service_handled',
'service_state',
'service_in_downtime',
'service_passive_checks_enabled',
'service_notifications_enabled',
'service_event_handler_enabled',
'service_flap_detection_enabled',
'service_active_checks_enabled',
'service_obsessing',
// also accept all filter-requests from ListView
'service_problem',
'service_severity',
'service_last_check',
'service_state_type',
'host_severity',
'host_address',
'host_last_check'
));
$this->applyQueryFilter($query);
$services = $query->getQuery()->fetchAll();
$comments = $this->backend->select()->from('comment', array(
'comment_internal_id',
'comment_host',
'comment_service'
));
$this->applyQueryFilter($comments);
$uniqueComments = array_keys($this->getUniqueValues($comments->getQuery()->fetchAll(), 'comment_internal_id'));
// populate the view
$this->view->objects = $this->view->services = $services;
$this->view->problems = $this->getProblems($services);
$this->view->comments = $uniqueComments;
$this->view->hostnames = $this->getProperties($services, 'host_name');
$this->view->servicenames = $this->getProperties($services, 'service_description');
$this->view->downtimes = $this->getDowntimes($services);
$this->view->service_states = $this->countStates($services, 'service');
$this->view->host_states = $this->countStates($services, 'host', 'host_name');
$this->view->service_pie = $this->createPie(
$this->view->service_states,
$this->view->getHelper('MonitoringState')->getServiceStateColors(),
mt('monitoring', 'Service State')
);
$this->view->host_pie = $this->createPie(
$this->view->host_states,
$this->view->getHelper('MonitoringState')->getHostStateColors(),
mt('monitoring', 'Host State')
);
$this->view->errors = $errors;
$this->handleConfigurationForm(array(
'service_passive_checks_enabled' => $this->translate('Passive Checks'),
'service_active_checks_enabled' => $this->translate('Active Checks'),
'service_notifications_enabled' => $this->translate('Notifications'),
'service_event_handler_enabled' => $this->translate('Event Handler'),
'service_flap_detection_enabled' => $this->translate('Flap Detection'),
'service_obsessing' => $this->translate('Obsessing'),
));
}
protected function applyQueryFilter($query)
{
$params = clone $this->params;
$modifyFilter = $params->shift('modifyFilter');
$filter = Filter::fromQueryString((string) $params);
if ($modifyFilter) {
$this->view->filterWidget = Widget::create('filterEditor', array(
'filter' => $filter,
'query' => $query
));
}
$this->view->filter = $filter;
$query->applyFilter($filter);
return $query;
}
/**
* Create an array with all unique values as keys.
*
* @param array $values The array containing the objects
* @param $key The key to access
*
* @return array
*/
private function getUniqueValues($values, $key)
{
$unique = array();
foreach ($values as $value) {
if (is_array($value)) {
$unique[$value[$key]] = $value[$key];
} else {
$unique[$value->$key] = $value->$key;
}
}
return $unique;
}
/**
* Get the numbers of problems of the given objects
*
* @param $objects The objects containing the problems
*
* @return int The problem count
*/
private function getProblems($objects)
{
$problems = 0;
foreach ($objects as $object) {
if (property_exists($object, 'host_unhandled_service_count')) {
$problems += $object->host_unhandled_service_count;
} else if (
property_exists($object, 'service_handled') &&
!$object->service_handled &&
$object->service_state > 0
) {
$problems++;
}
}
return $problems;
}
private function countStates($objects, $type = 'host', $unique = null)
{
$known = array();
if ($type === 'host') {
$states = array_fill_keys($this->view->getHelper('MonitoringState')->getHostStateNames(), 0);
} else {
$states = array_fill_keys($this->view->getHelper('MonitoringState')->getServiceStateNames(), 0);
}
foreach ($objects as $object) {
if (isset($unique)) {
if (array_key_exists($object->$unique, $known)) {
continue;
}
$known[$object->$unique] = true;
}
$states[$this->view->monitoringState($object, $type)]++;
}
return $states;
}
private function createPie($states, $colors, $title)
{
$chart = new InlinePie(array_values($states), $title, $colors);
$chart->setLabel(array_keys($states))->setSize(100);
$chart->setTitle($title);
return $chart;
}
private function getComments($objects)
{
$unique = array();
foreach ($objects as $object) {
$unique = array_merge($unique, $this->getUniqueValues($object->comments, 'comment_internal_id'));
}
return array_keys($unique);
}
private function getProperties($objects, $property)
{
$objectnames = array();
foreach ($objects as $object) {
$objectnames[] = $object->$property;
}
return $objectnames;
}
private function getDowntimes($objects)
{
$downtimes = array();
foreach ($objects as $object)
{
if (
(property_exists($object, 'host_in_downtime') && $object->host_in_downtime) ||
(property_exists($object, 'service_in_downtime') && $object->service_in_downtime)
) {
$downtimes[] = true;
}
}
return $downtimes;
}
/**
* Handle the form to edit configuration flags.
*
* @param $flags array The used flags.
*/
private function handleConfigurationForm(array $flags)
{
$this->view->form = $form = new MultiCommandFlagForm($flags);
$this->view->formElements = $form->buildCheckboxes();
$form->setRequest($this->_request);
if ($form->isSubmittedAndValid()) {
// TODO: Handle commands
$changed = $form->getChangedValues();
}
if ($this->_request->isPost() === false) {
$this->view->form->initFromItems($this->view->objects);
}
}
}

View File

@ -1,10 +0,0 @@
<h4><?= mt('monitoring', 'List Of Supported Commands'); ?></h4>
<ul>
<?php foreach($this->commands as $command): ?>
<li>
<a href="<?= $this->href('monitoring/command/'. $command); ?>">
<?= $this->escape($command); ?>
</a>
</li>
<?php endforeach; ?>
</ul>

View File

@ -1,25 +0,0 @@
<div class="controls">
<?= $this->tabs ?>
</div>
<div class="content">
<?php if (isset($this->objects) && !empty($this->objects) && isset($this->objects[0]->host_name)): ?>
<table class="objectlist">
<thead>
<tr>
<th><?= $this->icon('host') ?> Host</th>
<th><?= $this->icon('conf') ?> Service</th>
</tr>
</thead>
<tbody>
<?php foreach ($this->objects as $object): ?>
<tr>
<td><?= $object->host_name; ?></td>
<td><?= (isset($object->service_description) ? $object->service_description : '') ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php endif ?>
<?= $this->form ?>
</div>

View File

@ -2,11 +2,12 @@
<?= $this->tabs ?>
</div>
<div class="content">
<?php if (count($objects) === 0): ?>
<?php $hostCount = count($objects) ?>
<?php if ($hostCount === 0): ?>
<?= $this->translate('No hosts matching the filter') ?>
<?php else: ?>
<div class="hbox-item">
<b><?= sprintf($this->translate('Hosts (%u)'), array_sum(array_values($hostStates))) ?></b>
<b><?= sprintf($this->translatePlural('Host (%u)', 'Hosts (%u)', $hostCount), $hostCount) ?></b>
</div>
<div class="hbox-item">
<?= $this->hostStatesPieChart ?>
@ -18,9 +19,14 @@
</div>
<h3>
<?= sprintf($this->translate('%u Hosts'),
count($objects))
?>
<?= sprintf(
$this->translatePlural(
'%u Host',
'%u Hosts',
$hostCount
),
$hostCount
) ?>
</h3>
<div>
@ -56,13 +62,14 @@
<?php if (! empty($unhandledObjects)): ?>
<h3>
<?php $unhandledCount = count($unhandledObjects) ?>
<?= sprintf(
$this->translatePlural(
'%u Unhandled Host Problem',
'%u Unhandled Host Problems',
count($unhandledObjects)
$unhandledCount
),
count($unhandledObjects)
$unhandledCount
) ?>
</h3>
<div>
@ -83,13 +90,14 @@
<?php if (! empty($acknowledgedObjects)): ?>
<h2>
<?php $acknowledgedCount = count($acknowledgedObjects) ?>
<?= sprintf(
$this->translatePlural(
'%u Acknowledged Host Problem',
'%u Acknowledged Host Problems',
count($acknowledgedObjects)
$acknowledgedCount
),
count($acknowledgedObjects)
$acknowledgedCount
) ?>
</h2>
<div>
@ -99,20 +107,36 @@
<?php if (! empty($objectsInDowntime)): ?>
<h2>
<?php $inDowntimeCount = count($objectsInDowntime) ?>
<a href="<?= $inDowntimeLink ?>"
title="<?= $this->translate('Hosts in downtime') ?>">
<?= $this->icon('plug') ?>
<?= $this->translate(sprintf('%u hosts are in downtime', count($objectsInDowntime))) ?>
<?= sprintf(
$this->translatePlural(
'%u host is in downtime',
'%u hosts are in downtime',
$inDowntimeCount
),
$inDowntimeCount
) ?>
</a>
</h2>
<?php endif ?>
<?php if (count($objects->getComments())): ?>
<?php $havingCommentsCount = count($objects->getComments()) ?>
<?php if ($havingCommentsCount): ?>
<h2>
<a href="<?= $havingCommentsLink ?>"
title="<?= $this->translate('Comments') ?>">
<?= $this->icon('comment') ?>
<?= $this->translate(sprintf('%u comments', count($objects->getComments()))) ?>
<?= sprintf(
$this->translatePlural(
'%u comment',
'%u comments',
$havingCommentsCount
),
$havingCommentsCount
) ?>
</a>
</h2>
<?php endif ?>

View File

@ -1,25 +0,0 @@
<?php
$objectName = $this->is_service ? 'Services' : 'Hosts';
?><tr class="newsection" data-base-target="_next">
<th><a href=<?= count($comments) ?> <?= $this->translate('Comments') ?></th>
<td>
<a href="<?= $this->href('monitoring/command/removecomment', $this->target) ?>"><?=
$this->icon('cancel')
?> <?= $this->translate('Remove Comments') ?></a><br />
<a href="<?= $this->href('monitoring/command/delaynotifications', $this->target); ?>"><?=
$this->icon('bell-off-empty')
?> <?= $this->translate('Delay Notifications') ?></a><br />
<a title="<?= $this->translate('Acknowledge all problems on the selected hosts or services') ?>"
href="<?= $this->href('monitoring/command/acknowledgeproblem') ?>, $this->target); ?>">
<?= $this->icon('ok') ?> Acknowledge
</a>
</td>
<td><a href=" <?= $this->href(
'monitoring/list/comments',
array('comment_internal_id' => '(' . implode('|', $this->comments) . ')')
);
?>"> <?= count($comments) ?> comments </a>.
</td>
</tr>

View File

@ -1,19 +0,0 @@
<?php
$objectName = $this->is_service ? 'Services' : 'Hosts';
?>
<tr class="newsection">
<th><?= count($downtimes) ?> Downtimes</th>
<td>
<a href="<?=$this->href('monitoring/command/removedowntime', $this->target); ?>"><?=
$this->icon('cancel') ?>Remove Downtimes</a><br />
<a title="Schedule downtimes for all selected <?= $objectName ?>" href="<?=
$this->href('monitoring/command/scheduledowntime', $this->target) ?>"><?=
$this->icon('plug')
?> Schedule Downtimes</a>
</td>
<td>
Change <a data-base-target='_next' href="<?= $this->href('') ?>"> <?= count($downtimes) ?> downtimes</a>.
</td>
</tr>

View File

@ -1,25 +0,0 @@
<form
id="<?= $form->getId() ?>"
name="<?= $form->getName() ?>"
enctype="<?= $form->getEnctype() ?>"
action="<?= $form->getAction() ?>"
method="post"
>
<table class="avp newsection">
<?php foreach($this->form->getElements() as $name => $element):
if ($element instanceof \Icinga\Web\Form\Element\TriStateCheckbox):
$element->setDecorators(array('ViewHelper'));
?>
<tr>
<th><label for="<?= $element->getName() ?>"> <?= $element->getLabel() ?> </label></th>
<td><?= $element->render() ?></td>
</tr>
<?php else: ?>
<tr>
<th></th>
<td><?= $element->render() ?></td>
</tr>
<?php endif ?>
<?php endforeach ?>
</table>
</form>

View File

@ -1,65 +0,0 @@
<?php
$objectCount = count($objects);
$links = array();
for ($i = 0; $i < $objectCount && $i < 5; $i++) {
$object = $objects[$i];
if ($this->is_service) {
$links[] = $this->qlink(
$object->host_name . ' ' . $object->service_description,
'monitoring/show/service',
array(
'host' => $object->host_name,
'service' => $object->service_description
)
);
} else {
$links[] = $this->qlink(
$object->host_name,
'monitoring/show/host',
array(
'host' => $object->host_name
)
);
}
}
if ($this->is_service) {
$objectName = $this->translate('Services');
$link = 'monitoring/list/services';
$target = array(
'host' => $this->hostquery,
'service' => $this->servicequery
);
} else {
$objectName = $this->translate('Hosts');
$link = 'monitoring/list/hosts';
$target = array(
'host' => $this->hostquery
);
}
$more = clone $this->url;
?><tr class="newsection" data-base-target="_next">
<th><?= $this->qlink(
$this->translate('List all'),
$more->setPath($link),
null,
array('title' => $this->translate('List all selected objects'))
) ?></th>
<td colspan="3">
<?php
echo implode(', ', $links);
if ($objectCount > 5) {
echo ' ' . sprintf($this->translate('and %d more'), count($objects) - 5);
}
?>
</td>
</tr>

View File

@ -1,59 +0,0 @@
<?php
$cf = $this->getHelper('CommandForm');
$servicequery = isset($this->servicequery) ? $this->servicequery : '';
$objectName = $this->is_service ? $this->translate('Services') : $this->translate('Hosts');
$params = array(
'host' => $this->target['host'],
'service' => null,
'checktime' => time(),
'forcecheck' => '1'
);
if (array_key_exists('service', $this->target)) {
$params['service'] = $this->target['service'];
} else {
unset($params['service']);
}
?>
<tr class="newsection">
<th><?= count($objects) . ' ' . $objectName ?></th>
<td>
<a href="<?=
$this->href('monitoring/command/reschedulenextcheck', $params) ?>"><?=
$this->icon('rescheduel')
?> Recheck</a><br />
<a href="<?= $this->href('monitoring/command/reschedulenextcheck', $this->target) ?>"><?=
$this->icon('reschedule')
?> Reschedule</a><br />
</td>
<td>Perform actions on <?= count($objects) . ' ' . $objectName ?>.</td>
</tr>
<tr class="newsection">
<th><?= $this->problems ?> Problems</th>
<td>
<a title="Schedule downtimes for all selected hosts" href="<?=
$this->href('monitoring/command/scheduledowntime', $this->target) ?>"><?=
$this->icon('plug')
?> Schedule Downtimes</a>
</td>
<td><?= sprintf(
'Handle %d problems on %d %s.',
$this->problems,
count($this->objects),
$objectName
) ?></td>
</tr>
<tr>
<th><?= count($this->unhandled) ?> Unhandled</th>
<td colspan="2">
<a title="Acknowledge all problems on the selected hosts or services" href="<?=
$this->href('monitoring/command/acknowledgeproblem', $this->target) ?>"><?=
$this->icon('ok')
?> Acknowledge</a><br />
<a title="Remove all acknowledgements from all selected hosts or services" href="<?=
$this->href('monitoring/command/removeacknowledgement', $target) ?>"><?=
$this->icon('remove_petrol.png') ?> Remove Acknowledgements</a>
</td>
</tr>

View File

@ -1,62 +0,0 @@
<?php
$this->is_service = false;
$this->hostquery = implode($this->hostnames, ',');
$this->target = array('host' => $this->hostquery);
?>
<div class="controls">
<?= $this->tabs; ?>
</div>
<div class="content">
<?php if (count($objects) === 0): ?>
<?= mt('monitoring', 'No hosts matching the filter'); ?>
<?php else: ?>
<h1> Summary for <?= count($objects) ?> hosts </h1>
<?= $this->render('multi/components/objectlist.phtml'); ?>
<table class="avp">
<tr>
<th align="center">
<h3><?= array_sum(array_values($states)) ?> Hosts</h3>
</th>
<th></th>
</tr>
<tr>
<td align="center">
<?= $this->pie->render(); ?>
</td>
<td>
<?php
foreach ($states as $state => $count) {
if ($count > 0) {
echo ucfirst($state) . ': ' . $count . '<br />';
}
}
?>
</td>
<td></td>
</tr>
</table>
<h2> <?=$this->icon('host')?> Host Actions </h2>
<table class="avp newsection">
<tbody>
<?= $this->render('multi/components/summary.phtml'); ?>
<?= $this->render('multi/components/comments.phtml'); ?>
<?= $this->render('multi/components/downtimes.phtml'); ?>
</tbody>
</table>
<?= $this->render('multi/components/flags.phtml') ?>
<?php endif ?>
</div>
<a
rel="tooltip"
title="Submit passive checkresults"
href="<?= $this->href('monitoring/command/submitpassivecheckresult', $this->target); ?>"
class="button btn-cta btn-common btn-small"
>
<i class="icinga-icon-submit"></i>
</a>

View File

@ -1,61 +0,0 @@
<?php
$this->is_service = true;
$this->hostquery = implode($this->hostnames, ',');
$this->servicequery = implode($this->servicenames, ',');
$this->target = array(
'host' => $this->hostquery,
'service' => $this->servicequery
);
?>
<div class="controls">
<?= $this->tabs ?>
</div>
<div class="content">
<?php if (count($objects) === 0): ?>
<?= mt('monitoring', 'No services matching the filter'); ?>
<?php else: ?>
<h1> Summary for <?= count($objects) ?> services </h1>
<table style="width: 100%; font-size: 0.8em;">
<tr>
<th colspan="2"><?= array_sum(array_values($service_states)) ?> Services</th>
<th colspan="2"><?= array_sum(array_values($host_states)) ?> Hosts</th>
</tr>
<tr>
<td align="center"><?= $this->service_pie->render() ?></td>
<td><?php
foreach ($service_states as $state => $count) {
if ($count > 0) {
echo ucfirst($state) . ': ' . $count . '<br />';
}
}
?></td>
<td align="center"><?= $this->host_pie->render() ?></td>
<td><?php
foreach ($host_states as $state => $count) {
if ($count > 0) {
echo ucfirst($state) . ': ' . $count . '<br />';
}
}
?></td>
</tr>
</table>
<h2><?=$this->icon('conf')?> Service Actions</h2>
<table class="avp newsection">
<tbody>
<?= $this->render('multi/components/objectlist.phtml') ?>
<?= $this->render('multi/components/summary.phtml') ?>
<?= $this->render('multi/components/comments.phtml') ?>
<?= $this->render('multi/components/downtimes.phtml') ?>
</tbody>
</table>
<?= $this->render('multi/components/flags.phtml') ?>
<?php endif ?>
</div>

View File

@ -2,13 +2,14 @@
<?= $this->tabs ?>
</div>
<div class="content">
<?php if (count($objects) === 0): ?>
<?php $serviceCount = count($objects) ?>
<?php if ($serviceCount === 0): ?>
<?= $this->translate('No services matching the filter') ?>
<?php else: ?>
<div class="hbox">
<div class="hbox-item" style="width: 6em;">
<b><?= sprintf($this->translate('Services (%u)'), array_sum(array_values($serviceStates))) ?></b>
<b><?= sprintf($this->translatePlural('Service (%u)', 'Services (%u)', $serviceCount), $serviceCount) ?></b>
</div>
<div class="hbox-item">
<?= $this->serviceStatesPieChart ?>
@ -22,7 +23,8 @@
<div class="hbox">
<div class="hbox-item" style="width: 6em;">
<b><?= sprintf($this->translate('Hosts (%u)'), array_sum(array_values($hostStates))) ?></b>
<?php $hostCount = array_sum(array_values($hostStates)) ?>
<b><?= sprintf($this->translatePlural('Host (%u)', 'Hosts (%u)', $hostCount), $hostCount) ?></b>
</div>
<div class="hbox-item">
<?= $this->hostStatesPieChart ?>
@ -68,13 +70,14 @@
<?php if (! empty($unhandledObjects)): ?>
<h3>
<?php $unhandledCount = count($unhandledObjects) ?>
<?= sprintf(
$this->translatePlural(
'%u Unhandled Service Problem',
'%u Unhandled Service Problems',
count($unhandledObjects)
$unhandledCount
),
count($unhandledObjects)
$unhandledCount
) ?>
</h3>
<div>
@ -95,13 +98,14 @@
<?php if (! empty($acknowledgedObjects)): ?>
<h2>
<?php $acknowledgedCount = count($acknowledgedObjects) ?>
<?= sprintf(
$this->translatePlural(
'%u Acknowledged Service Problem',
'%u Acknowledged Service Problems',
count($acknowledgedObjects)
$acknowledgedCount
),
count($acknowledgedObjects)
$acknowledgedCount
) ?>
</h2>
<div>
@ -111,20 +115,36 @@
<?php if (! empty($objectsInDowntime)): ?>
<h2>
<?php $inDowntimeCount = count($objectsInDowntime) ?>
<a href="<?= $inDowntimeLink ?>"
title="<?= $this->translate('Services in downtime') ?>">
<?= $this->icon('plug') ?>
<?= $this->translate(sprintf('%u services are in downtime', count($objectsInDowntime))) ?>
<?= sprintf(
$this->translatePlural(
'%u service is in downtime',
'%u services are in downtime',
$inDowntimeCount
),
$inDowntimeCount
) ?>
</a>
</h2>
<?php endif ?>
<?php if (count($objects->getComments())): ?>
<?php $havingCommentsCount = count($objects->getComments()) ?>
<?php if ($havingCommentsCount): ?>
<h2>
<a href="<?= $havingCommentsLink ?>"
title="<?= $this->translate('Comments') ?>">
<?= $this->icon('comment') ?>
<?= $this->translate(sprintf('%u comments', count($objects->getComments()))) ?>
<?= sprintf(
$this->translatePlural(
'%u comment',
'%u comments',
$havingCommentsCount
),
$havingCommentsCount
) ?>
</a>
</h2>
<?php endif ?>