Let downtime view look more list-like and fix downtime end calculation

refs #6637
This commit is contained in:
Johannes Meyer 2014-08-19 17:03:35 +02:00
parent 332be22f7e
commit 3573908071
4 changed files with 135 additions and 67 deletions

View File

@ -222,6 +222,7 @@ class Monitoring_ListController extends Controller
'author' => 'downtime_author',
'start' => 'downtime_start',
'scheduled_start' => 'downtime_scheduled_start',
'scheduled_end' => 'downtime_scheduled_end',
'end' => 'downtime_end',
'duration' => 'downtime_duration',
'is_flexible' => 'downtime_is_flexible',
@ -229,7 +230,9 @@ class Monitoring_ListController extends Controller
'is_in_effect' => 'downtime_is_in_effect',
'entry_time' => 'downtime_entry_time',
'host' => 'downtime_host',
'service' => 'downtime_service'
'service' => 'downtime_service',
'host_state' => 'downtime_host_state',
'service_state' => 'downtime_service_state'
))->order('downtime_is_in_effect', 'DESC')
->order('downtime_scheduled_start', 'DESC');

View File

@ -1,70 +1,121 @@
<?php
$helper = $this->getHelper('CommandForm');
?>
<div class="controls">
<?= $this->tabs ?>
<div style="margin: 1em">
<?= $this->sortControl->render($this); ?>
</div>
<?= $this->paginationControl($downtimes, null, null, array('preserve' => $this->preserve)); ?>
</div>
<div class="content downtimes">
<table data-base-target="_next" class="action">
<tbody>
<?php
if (count($downtimes) === 0) {
echo t('No downtimes matching the filter');
}
foreach ($this->downtimes as $downtime): ?>
<tr>
<td>
<?= $this->dateFormat()->formatDateTime($downtime->start); ?> -
<?= $this->dateFormat()->formatDateTime($downtime->end); ?>
<br />
<small>Duration: <?= $this->util()->showHourMin($downtime->duration); ?></small>
<br />
<small>The <?php if($downtime->is_flexible): ?>flexible<?php else: ?>fixed<?php endif; ?> downtime is <?php if(!$downtime->is_in_effect): ?>not <?php endif; ?>in effect</small>
</td>
<td>
<?php if (isset($downtime->service)): ?>
<a href="<?= $this->href('monitoring/show/service', array(
'host' => (string) $downtime->host,
'service' => (string) $downtime->service
)); ?>"><?= $downtime->service ?></a>
<small>on <?= $downtime->host ?></small>
<?php else: ?>
<a href="<?= $this->href('monitoring/show/host', array(
'host' => (string) $downtime->host
)); ?>"><?= $downtime->host ?> </a>
<?php endif; ?>
<br />
<?= $downtime->author ?>: <?= $downtime->comment ?>
<br />
<small>Entry Time: <?= ($downtime->entry_time) ? $this->dateFormat()->formatDateTime((int) $downtime->entry_time) : ''; ?>
</small>
<td style="width: 2em">
<?php
$data = array(
'downtimeid' => $downtime->id,
'host' => $downtime->host
);
if (isset($downtime->service)) {
$data['service'] = $downtime->service;
}
// echo $helper->iconSubmitForm(
// 'img/icons/remove.png',
echo $helper->labelSubmitForm(
'X',
'Remove Downtime',
'link-like',
'removedowntime',
$data
);
?>
</td>
</tr>
<?php endforeach ?>
</tbody>
</table>
<?php if (false === $this->compact): ?>
<div class="controls">
<?= $this->tabs->render($this); ?>
<div style="margin: 1em" class="dontprint">
<?= $this->translate('Sort by'); ?> <?= $this->sortControl->render($this); ?>
</div>
<?= $this->widget('limiter', array('url' => $this->url, 'max' => $downtimes->count())); ?>
<?= $this->paginationControl($downtimes, null, null, array('preserve' => $this->preserve)); ?>
</div>
<?php endif ?>
<div class="content">
<?php if (empty($downtimes)): ?>
<?= $this->translate('No downtimes matching the filter'); ?>
</div>
<?php return; endif ?>
<table data-base-target="_next" class="action">
<tbody>
<?php foreach ($downtimes as $downtime): ?>
<?php
if (isset($downtime->service)) {
$stateName = strtolower($this->util()->getServiceStateName($downtime->service_state));
} else {
$stateName = strtolower($this->util()->getHostStateName($downtime->host_state));
}
?>
<tr class="state <?= $stateName; ?><?= $downtime->is_in_effect ? ' handled' : ''; ?>">
<td class="state">
<strong><?= $downtime->is_in_effect ? $this->translate('Expires') : $this->translate('Starts'); ?></strong>
<br>
<?= $this->prefixedTimeUntil($downtime->is_in_effect ? $downtime->end : $downtime->start); ?>
</td>
<td>
<?php if (isset($downtime->service)): ?>
<a href="<?= $this->href('monitoring/show/service', array(
'host' => $downtime->host,
'service' => $downtime->service
)); ?>">
<?= $downtime->service; ?>
</a>
<small>
<?= $this->translate('on'); ?> <?= $downtime->host; ?>
</small>
<?php else: ?>
<a href="<?= $this->href('monitoring/show/host', array(
'host' => $downtime->host
)); ?>">
<?= $downtime->host; ?>
</a>
<?php endif ?>
<br>
<?= $this->icon('comment.png'); ?> [<?= $downtime->author; ?>] <?= $downtime->comment; ?>
<br>
<small>
<?php if ($downtime->is_flexible): ?>
<?php if ($downtime->is_in_effect): ?>
<?= sprintf(
$this->translate('This flexible downtime was started on %s at %s and lasts for %s until %s at %s.'),
date('d.m.y', $downtime->start),
date('H:i', $downtime->start),
$this->format()->duration($downtime->duration),
date('d.m.y', $downtime->end),
date('H:i', $downtime->end)
); ?>
<?php else: ?>
<?= sprintf(
$this->translate('This flexible downtime has been scheduled to start between %s - %s and to last for %s.'),
date('d.m.y H:i', $downtime->scheduled_start),
date('d.m.y H:i', $downtime->scheduled_end),
$this->format()->duration($downtime->duration)
); ?>
<?php endif ?>
<?php else: ?>
<?php if ($downtime->is_in_effect): ?>
<?= sprintf(
$this->translate('This fixed downtime was started on %s at %s and expires on %s at %s.'),
date('d.m.y', $downtime->start),
date('H:i', $downtime->start),
date('d.m.y', $downtime->end),
date('H:i', $downtime->end)
); ?>
<?php else: ?>
<?= sprintf(
$this->translate('This fixed downtime has been scheduled to start on %s at %s and to end on %s at %s.'),
date('d.m.y', $downtime->scheduled_start),
date('H:i', $downtime->scheduled_start),
date('d.m.y', $downtime->scheduled_end),
date('H:i', $downtime->scheduled_end)
); ?>
<?php endif ?>
<?php endif ?>
</small>
</td>
<?php
$data = array(
'downtimeid' => $downtime->id,
'host' => $downtime->host
);
if (isset($downtime->service)) {
$data['service'] = $downtime->service;
}
?>
<td style="width: 2em">
<?= $helper->labelSubmitForm(
'X',
'Remove Downtime',
'link-like',
'removedowntime',
$data
); ?>
</td>
</tr>
<?php endforeach ?>
</tbody>
</table>
</div>

View File

@ -24,13 +24,15 @@ class DowntimeQuery extends IdoQuery
'downtime_scheduled_start' => 'UNIX_TIMESTAMP(sd.scheduled_start_time)',
'downtime_scheduled_end' => 'UNIX_TIMESTAMP(sd.scheduled_end_time)',
'downtime_start' => "UNIX_TIMESTAMP(CASE WHEN sd.trigger_time != '0000-00-00 00:00:00' then sd.trigger_time ELSE sd.scheduled_start_time END)",
'downtime_end' => 'UNIX_TIMESTAMP(sd.scheduled_end_time)',
'downtime_end' => 'CASE WHEN sd.is_fixed THEN UNIX_TIMESTAMP(sd.scheduled_end_time) ELSE UNIX_TIMESTAMP(sd.trigger_time) + sd.duration END',
'downtime_duration' => 'sd.duration',
'downtime_is_in_effect' => 'sd.is_in_effect',
'downtime_internal_id' => 'sd.internal_downtime_id',
'downtime_host' => 'CASE WHEN ho.name1 IS NULL THEN so.name1 ELSE ho.name1 END COLLATE latin1_general_ci',
'downtime_service' => 'so.name2 COLLATE latin1_general_ci',
'downtime_objecttype' => "CASE WHEN ho.object_id IS NOT NULL THEN 'host' ELSE CASE WHEN so.object_id IS NOT NULL THEN 'service' ELSE NULL END END",
'downtime_host_state' => 'CASE WHEN hs.has_been_checked = 0 OR hs.has_been_checked IS NULL THEN 99 ELSE hs.current_state END',
'downtime_service_state' => 'CASE WHEN ss.has_been_checked = 0 OR ss.has_been_checked IS NULL THEN 99 ELSE ss.current_state END'
),
);
@ -53,6 +55,16 @@ class DowntimeQuery extends IdoQuery
'sd.object_id = so.object_id AND so.is_active = 1 AND so.objecttype_id = 2',
array()
);
$this->select->joinLeft(
array('hs' => $this->prefix . 'hoststatus'),
'ho.object_id = hs.host_object_id',
array()
);
$this->select->joinLeft(
array('ss' => $this->prefix . 'servicestatus'),
'so.object_id = ss.service_object_id',
array()
);
$this->joinedVirtualTables = array('downtime' => true);
}
}

View File

@ -30,6 +30,8 @@ class Downtime extends DataView
'downtime_internal_id',
'downtime_host',
'downtime_service',
'downtime_host_state',
'downtiem_service_state'
);
}