Fix object history dates make output look similar to the event history

refs #6637
This commit is contained in:
Johannes Meyer 2014-08-18 15:32:12 +02:00
parent bbddb9ed87
commit 332be22f7e

View File

@ -1,149 +1,127 @@
<?php <div class="controls">
<?= $this->render('show/components/header.phtml'); ?>
use Icinga\Module\Monitoring\Object\Service; <h1><?= $this->translate('This Object\'s Event History'); ?></h1>
<?= $this->widget('limiter', array('url' => $url, 'max' => $history->count())); ?>
if ($object instanceof Service) { <?= $this->paginationControl($history, null, null, array('preserve' => $this->preserve)); ?>
$title = $object->service_description;
$params = array(
'host' => $object->host_name,
'service' => $object->service_description
);
} else {
$title = $object->host_name;
$params = array('host' => $object->host_name);
}
// TODO: Remove this once we have better helpers
$states = array(
'service' => array(
'ok',
'warning',
'critical',
'unknown',
99 => 'pending',
),
'host' => array(
'up',
'down',
'unreachable',
99 => 'pending',
)
);
?><div class="controls">
<?= $this->render('show/components/header.phtml') ?>
<h1><?= $this->translate("This object's event history") ?></h1>
<?= $this->widget('limiter', array('url' => $this->url, 'max' => $this->history->count())) ?>
<?= $this->paginationControl($this->history, null, null, array('preserve' => $this->preserve)); ?>
</div> </div>
<div class="content"> <div class="content">
<?php if($this->history->count() === 0): ?> <?php if (empty($history)): ?>
<?= $this->translate('No History Available For This Object') ?> <?= $this->translate('No history available for this object'); ?>
</div> </div>
<?php return; endif ?> <?php return; endif ?>
<table data-base-target="_next" class="action objecthistory"> <table data-base-target="_next" class="action objecthistory">
<tbody> <tbody>
<?php foreach ($history as $event): ?>
<?php foreach ($this->history as $event): <?php
if (array_key_exists($event->state, $states[$event->object_type])) { $stateClass = 'invalid';
$state_class = $states[$event->object_type][$event->state]; $isService = isset($event->service_description);
} else { switch ($event->type) {
$state_class = 'invalid'; case 'notify':
} $icon = 'notification';
$extraTitle = false; $title = $this->translate('Notification');
switch ($event->type) { $msg = $event->output;
case 'notify': break;
$icon = 'notification'; case 'comment':
$title = $this->translate('Notification'); $icon = 'comment';
$state = $this->translate('ACK'); $title = $this->translate('Comment');
break; $msg = $event->output;
case 'comment': break;
$icon = 'comment'; case 'comment_deleted':
$title = $this->translate('Comment'); $icon = 'remove';
break; $title = $this->translate('Comment deleted');
case 'comment_deleted': $msg = $event->output;
$icon = 'remove'; break;
$title = $this->translate('Comment deleted'); case 'ack':
break; $icon = 'acknowledgement';
case 'ack': $title = $this->translate('Acknowledge');
$icon = 'acknowledgement'; $msg = $event->output;
$title = $this->translate('Acknowledge'); break;
break; case 'ack_deleted':
case 'ack_deleted': $icon = 'remove';
$icon = 'remove'; $title = $this->translate('Ack removed');
$title = $this->translate('Ack removed'); $msg = $event->output;
break; break;
case 'dt_comment': case 'dt_comment':
$icon = 'in_downtime'; $icon = 'in_downtime';
$title = $this->translate('In Downtime'); $title = $this->translate('In Downtime');
break; $msg = $event->output;
case 'dt_comment_deleted': break;
$icon = 'remove'; case 'dt_comment_deleted':
$title = $this->translate('Downtime removed'); $icon = 'remove';
break; $title = $this->translate('Downtime removed');
case 'flapping': $msg = $event->output;
$icon = 'flapping'; break;
$title = $this->translate('Flapping'); case 'flapping':
break; $icon = 'flapping';
case 'flapping_deleted': $title = $this->translate('Flapping');
$icon = 'remove'; $msg = $event->output;
$title = $this->translate('Flapping stopped'); break;
break; case 'flapping_deleted':
case 'hard_state': $icon = 'remove';
$icon = 'submit'; $title = $this->translate('Flapping stopped');
$title = strtoupper($state_class); $msg = $event->output;
break; break;
case 'soft_state': case 'hard_state':
$icon = 'softstate'; $icon = $isService ? 'service' : 'host';
$title = strtoupper($state_class); $msg = '[ ' . $event->attempt . '/' . $event->max_attempts . ' ] ' . $event->output;
$extraTitle = $this->translate('Soft State'); $stateClass = (
$state_class .= ' handled'; $isService
break; ? strtolower($this->util()->getServiceStateName($event->state))
case 'dt_start': : strtolower($this->util()->getHostStateName($event->state))
$icon = 'downtime_start'; );
$title = $this->translate('Downtime Start'); $title = strtoupper($stateClass); // TODO: Should be translatable!
break; break;
case 'dt_end': case 'soft_state':
$icon = 'downtime_end'; $icon = 'softstate';
$title = $this->translate('Downtime End'); $msg = '[ ' . $event->attempt . '/' . $event->max_attempts . ' ] ' . $event->output;
break; $stateClass = (
} $isService
? strtolower($this->util()->getServiceStateName($event->state))
: strtolower($this->util()->getHostStateName($event->state))
);
?> $title = strtoupper($stateClass); // TODO: Should be translatable!
<tr class="state <?= $state_class ?>"> break;
<td class="state"><strong><?= $this->escape($title) ?></strong><br /><?= $this->prefixedTimeSince($event->timestamp) ?><?= $extraTitle === false ? '' : '<br />' . $this->escape($extraTitle) ?></td> case 'dt_start':
<td> $icon = 'downtime_start';
<?php $title = $this->translate('Downtime Start');
$msg = $event->output;
break;
case 'dt_end':
$icon = 'downtime_end';
$title = $this->translate('Downtime End');
$msg = $event->output;
break;
}
?>
<tr class="state <?= $stateClass; ?>">
<td class="state">
<strong><?= $this->escape($title); ?></strong>
<br>
<?= date('d.m. H:i', $event->timestamp); ?>
</td>
<td><?php
$output = $this->tickets ? preg_replace_callback( $output = $this->tickets ? preg_replace_callback(
$this->tickets->getPattern(), $this->tickets->getPattern(),
array($this->tickets, 'createLink'), array($this->tickets, 'createLink'),
$this->escape($event->output) $this->escape($msg)
) : $this->escape($event->output); ) : $this->escape($msg);
echo $this->icon($icon . '.png', $title) . ' ';
if ($object instanceof Host): ?>
<?= $this->escape($event->service_description) ?>
<?php elseif ($object instanceof Service): ?>
<?php else: ?>
<?= $this->escape($event->service_description) ?> on <?= $this->escape($event->host_name) ?>
<?php endif;
if ($event->attempt !== null) {
printf('[ %d/%d ] ', $event->attempt, $event->max_attempts);
}
echo $output;
?> ?>
</td> <?php if ($isService): ?>
</tr> <?= $this->escape($event->service_description) . ' ' . $this->translate('on') . ' ' . $this->escape($event->host_name); ?>
<?php else: ?>
<?= $this->escape($event->host_name); ?>
<?php endif ?>
<br>
<div>
<?= $this->icon($icon . '.png', $title); ?> <?= empty($msg) ? '' : $msg; ?>
</div>
</td>
</tr>
<? endforeach; ?> <? endforeach; ?>
</tbody> </tbody>
</table> </table>
</div> </div>