List service event history when showing a service

refs #4663
This commit is contained in:
Eric Lippmann 2013-09-27 12:38:14 +02:00
parent 61bfcd495b
commit 18bd1c3221
6 changed files with 97 additions and 4 deletions

View File

@ -86,6 +86,7 @@ class Monitoring_ShowController extends ActionController
public function serviceAction()
{
$this->view->object->prefetch();
$this->view->object->eventHistory = $this->view->object->eventHistory->limit(10)->fetchAll();
$this->view->preserve = array();
}

View File

@ -268,7 +268,7 @@ class Zend_View_Helper_MonitoringProperties extends Zend_View_Helper_Abstract
return $out;
}
public function getNotificationType(AbstractObject $notification)
public function getNotificationType($notification)
{
$reason = intval($notification->notification_reason);
if (!isset(self::$notificationReasons[$reason])) {

View File

@ -0,0 +1,89 @@
<?php if (!empty($object->eventHistory)): ?>
<div class="panel panel-default">
<div class="panel-heading">
<span>History</span>
</div>
<div class="panel-body">
<table class="table table-condensed">
<tbody>
<?php foreach ($object->eventHistory as $event): ?>
<tr>
<td><?= date('d.m. H:i', $event->timestamp); ?></td>
<td>
<?php if (!$object instanceof Icinga\Module\Monitoring\Object\Service): ?>
<a href="<?= $this->href('monitoring/show/service', array(
'host' => $object->host_name,
'service' => $event->service_description
)); ?>">
<?= $event->service_description ?>
</a>
<?php else: ?>
<a href="<?= $this->href('monitoring/show/host', array(
'host' => $object->host_name
)); ?>">
<?= $event->host_name ?>
</a>
<?php endif; ?>
</td>
<td>
<?php
switch ($event->type) {
case 'notify':
$icon = '{{NOTIFICATION_ICON}}';
$title = 'Notification';
$msg = $event->output;
break;
case 'comment':
$icon = '{{COMMENT_ICON}}';
$title = 'Comment';
$msg = $event->output;
break;
case 'ack':
$icon = '{{ACKNOWLEDGEMENT_ICON}}';
$title = 'Acknowledgement';
$msg = '';
break;
case 'dt_comment':
$icon = '{{IN_DOWNTIME_ICON}}';
$title = 'In Downtime';
$msg = $event->output;
break;
case 'flapping':
$icon = '{{FLAPPING_ICON}}';
$title = 'Flapping';
$msg = '';
break;
case 'hard_state':
$icon = '{{HARDSTATE_ICON}}';
$title = 'Hard State';
$msg = '[' . $event->attempt . '/' . $event->max_attempts . ']';
break;
case 'soft_state':
$icon = '{{SOFTSTATE_ICON}}';
$title = 'Soft State';
$msg = '[' . $event->attempt . '/' . $event->max_attempts . ']';
break;
case 'dt_start':
$icon = '{{DOWNTIME_START_ICON}}';
$title = 'Downtime Start';
$msg = $event->output;
break;
case 'dt_end':
$icon = '{{DOWNTIME_END_ICON}}';
$title = 'Downtime End';
$msg = $event->output;
break;
}
?>
<a href="#" title="<?= $title ?>"><i><?= $icon ?></i></a>
<?php if (!empty($msg)) { echo $msg; } ?>
</td>
</tr>
<? endforeach; ?>
</tbody>
</table>
</div>
</div>
<?php endif; ?>

View File

@ -31,6 +31,8 @@ class EventHistoryQuery extends AbstractQuery
'output' => 'eh.output', // we do not want long_output
//'problems' => 'CASE WHEN eh.state = 0 OR eh.state IS NULL THEN 0 ELSE 1 END',
'type' => 'eh.type',
'service_host_name' => 'eho.name1 COLLATE latin1_general_ci',
'service_description' => 'eho.name2 COLLATE latin1_general_ci'
),
'hostgroups' => array(
'hostgroup' => 'hgo.name1 COLLATE latin1_general_ci',
@ -74,7 +76,7 @@ class EventHistoryQuery extends AbstractQuery
}
if ($end) {
foreach ($this->subQueries as $query) {
$query->where('raw_timestamp', '<' . $start);
$query->where('raw_timestamp', '<' . $end);
}
}
$sub = $this->db->select()->union($this->subQueries, Zend_Db_Select::SQL_UNION_ALL);

View File

@ -143,7 +143,7 @@ abstract class AbstractObject
return $this;
}
protected function fetchEventHisoty()
protected function fetchEventHistory()
{
$this->foreign['eventHistory'] = $this->applyObjectFilter(
$this->backend->select()->from('eventHistory', array(
@ -158,6 +158,7 @@ abstract class AbstractObject
'type'
))
);
// echo $this->foreign['eventHistory']->dump();die;
return $this;
}
}

View File

@ -32,7 +32,7 @@ class Service extends AbstractObject
->fetchContactgroups()
->fetchCustomvars()
->fetchComments()
->fetchEventHisoty();
->fetchEventHistory();
}
protected function fetchObject()