Monitoring/Downtimes: Wrap information in a two column view

This commit is contained in:
Eric Lippmann 2013-10-19 17:24:28 +02:00
parent d9afd06701
commit 652df9fd66
6 changed files with 73 additions and 221 deletions

View File

@ -175,25 +175,7 @@ class Monitoring_ListController extends MonitoringController
*/
public function downtimesAction()
{
$query = DowntimeView::fromRequest(
$this->_request,
array(
'host_name',
'object_type',
'service_description',
'downtime_entry_time',
'downtime_internal_downtime_id',
'downtime_author_name',
'downtime_comment_data',
'downtime_duration',
'downtime_scheduled_start_time',
'downtime_scheduled_end_time',
'downtime_is_fixed',
'downtime_is_in_effect',
'downtime_triggered_by_id',
'downtime_trigger_time'
)
)->getQuery();
$query = DowntimeView::fromRequest($this->_request)->getQuery();
$this->view->downtimes = $query->paginate();
$this->setupSortControl(array(

View File

@ -1,135 +1,63 @@
<?php
/**
* Create a DateTime from a string and use the util helper to
* format it
*
* @param $self Reference to the current view that contains the helper.
* @param $dateString The String that will be converted.
* @return String The formatted string.
*/
function formatDateString($self,$dateString){
$d = new DateTime($dateString);
return $self->util()->showTime($d->getTimestamp());
}
$commandHelper = $this->getHelper('CommandForm');
?>
<?= $this->tabs->render($this); ?>
<div data-icinga-component="app/mainDetailGrid" data-icinga-grid-selection-type="none">
<div data-icinga-component="app/mainDetailGrid" data-icinga-grid-selection-type="single">
<div>
<?= $this->sortControl->render($this); ?>
</div>
<div>
<?= $this->paginationControl(
$this->downtimes,
null,
array(
'mixedPagination.phtml',
'default'
),
array('preserve' => $this->preserve)
);
?>
<?= $this->paginationControl($downtimes, null, null, array('preserve' => $this->preserve)); ?>
<table class="table table-condensed">
<thead>
<tr>
<th>Is In Effect</th>
<th>Object</th>
<th>Host Name</th>
<th>Service Name</th>
<th>Entry Time</th>
<th>Author</th>
<th>Comment</th>
<th>Start Time</th>
<th>End Time</th>
<th>Type</th>
<th>Trigger Time</th>
<th>Downtime ID</th>
<th>Trigger ID</th>
<th>Duration</th>
<th>&nbsp;</th>
</tr>
</thead>
<tbody>
<?php foreach ($downtimes as $downtime): ?>
<tr>
<td>
<?= ($downtime->downtime_is_in_effect == 0 ? 'False' : '<b>True</b>'); ?>
<?= $this->dateFormat()->formatDateTime((int) $downtime->downtime_start); ?> -
<?= $this->dateFormat()->formatDateTime((int) $downtime->downtime_end); ?>
<br />
<small>Duration: <?= $this->util()->showHourMin((int) $downtime->downtime_duration); ?></small>
<br />
<small>The <?php if($downtime->downtime_is_flexible): ?>flexible<?php else: ?>fixed<?php endif; ?> downtime is <?php if(!$downtime->downtime_is_in_effect): ?>not <?php endif; ?>in effect</small>
</td>
<td>
<div>
<?php if ($downtime->object_type == 'service'): ?>
{{SERVICE_ICON}}
<?php endif; ?>
<?php if ($downtime->object_type == 'host'): ?>
{{HOST_ICON}}
<?php endif; ?>
</div>
</td>
<td>
<?= $downtime->host_name ?>
</td>
<td>
<?= $downtime->service_description ?>
</td>
<td>
<?= formatDateString($this,$downtime->downtime_entry_time); ?>
</td>
<td>
<?= $downtime->downtime_author_name ?>
</td>
<td>
<?= $downtime->downtime_comment_data ?>
</td>
<td>
<?= formatDateString($this,$downtime->downtime_scheduled_start_time); ?>
</td>
<td>
<?= formatDateString($this,$downtime->downtime_scheduled_end_time); ?>
</td>
<td>
<?= $downtime->downtime_is_fixed == 1 ? 'Fixed' : 'Not Fixed' ?>
</td>
<td>
<?php
$date = formatDateString($this,$downtime->downtime_trigger_time);
echo $date != 'undef' ? $date : 'N/A';
?>
</td>
<td>
<?= $downtime->downtime_internal_downtime_id ?>
</td>
<td>
<?= $downtime->downtime_triggered_by_id == 0 ?
'N/A' : $downtime->downtime_triggered_by_id ?>
</td>
<td>
<?= $this->util()->showHourMin(intval($downtime->downtime_duration)); ?>
</td>
<?php if (isset($downtime->service)): ?>
<a href="<?= $this->href('monitoring/show/service', array(
'host' => $downtime->host,
'service' => $downtime->service
)); ?>"><?= $downtime->service ?></a>
<small>on <?= $downtime->host ?></small>
<?php else: ?>
<a href="<?= $this->href('monitoring/show/host', array(
'host' => $downtime->host
)); ?>"><?= $downtime->host ?></a>
<?php endif; ?>
<br />
<?= $downtime->downtime_author ?>: <?= $downtime->downtime_comment ?>
<br />
<small>Entry Time: <?= $downtime->downtime_entry_time ?></small>
<td>
<?php
$data = array(
'downtimeid' => $downtime->downtime_internal_downtime_id,
'host' => $downtime->host_name
'downtimeid' => $downtime->downtime_internal_downtime_id,
'host' => $downtime->host
);
if ($downtime->object_type == 'service') {
$data['service'] = $downtime->service_description;
if (isset($downtime->service)) {
$data['service'] = $downtime->service;
}
echo $commandHelper->simpleForm(
'removedowntime',
echo $commandHelper->iconSubmitForm(
'icinga-icon-remove',
'Remove Downtime',
'btn-small',
'removedowntime',
$data
);
?>
</td>
</tr>
<?php endforeach ?>
</tbody>
</table>
<?= $this->paginationControl($downtimes, null, null, array('preserve' => $this->preserve)); ?>
</div>
</div>

View File

@ -1,33 +1,3 @@
<?php if (!empty($this->downtimes)): ?>
<?php
$list = array();
foreach ($this->downtimes as $downtime) {
$row = array();
if ($downtime->downtime_is_in_effect === '1') {
$row[] = 'Running<br />since '. $this->timeSince($downtime->downtime_actual_start_time);
} else {
if ($downtime->downtime_is_fixed) {
$row[] = 'Scheduled<br />for '. $downtime->downtime_scheduled_start_time;
} else {
$row[] = 'Waiting';
}
}
$row[] = sprintf(
'Triggered by %s: <em>%s</em>',
$downtime->downtime_author_name,
$downtime->downtime_comment_data
);
$row[] = '<button type="button" data-target="command" class="btn btn-warning"'
. ' data-command-id="29" data-command-info="'. $downtime->downtime_internal_downtime_id. '"'
. '>{{REMOVE_ICON}} Remove'
. '</button>';
$list[] = '<td>'. implode('</td><td>', $row). '</td>';
}
?>
<?php endif; ?>
<div>
<div class="panel-heading">
<div class="panel-hostname">
@ -61,30 +31,30 @@
<tr>
<td>
<div class="pull-right">
<form action="<?= $this->href('monitoring/command/removeDowntime'); ?>" data-icinga-component="app/ajaxPostSubmitForm">
<button type="submit" class="button btn-common btn-small" name="btn_submit" value="1">
<i class="icinga-icon-remove"></i>
</button>
<input type="hidden" name="host" value="<?= $downtime->host_name; ?>" />
<input type="hidden" name="service" value="<?= $downtime->service_description; ?>" />
<input type="hidden" name="downtimeid" value="<?= $downtime->downtime_internal_downtime_id; ?>" />
<input type="hidden" name="CSRFToken" value="" />
</form>
<?= $this->getHelper('CommandForm')->iconSubmitForm(
'icinga-icon-remove',
'Remove Downtime',
'btn-small',
'removedowntime',
array(
'downtimeid' => $downtime->downtime_internal_downtime_id,
'host' => $downtime->host,
'service' => $downtime->service
)
); ?>
</div>
<?php if ($downtime->downtime_is_in_effect === '1'): ?>
Running since <?= $this->timeSince($downtime->downtime_actual_start_time); ?>
In scheduled downtime since <?= $this->timeSince($downtime->downtime_start); ?>
<?php else: ?>
<?php if ($downtime->downtime_is_fixed): ?>
Scheduled for <?= $downtime->downtime_scheduled_start_time; ?>
Downtime scheduled for <?= $downtime->downtime_start; ?>
<?php else: ?>
Waiting
<?php endif; ?>
<?php endif; ?>
Triggered by <?= $downtime->downtime_author_name; ?>
<div class="small-row">
<?= $downtime->downtime_comment_data; ?>
<?= $downtime->downtime_author; ?>: <?= $downtime->downtime_comment; ?>
</div>
</td>
</tr>

View File

@ -36,27 +36,21 @@ class DowntimeQuery extends IdoQuery
*/
protected $columnMap = array(
'downtime' => array(
'downtime_type' => 'sd.downtime_type',
'downtime_author_name' => 'sd.author_name',
'downtime_comment_data' => 'sd.comment_data',
'downtime_entry_time' => 'sd.entry_time',
'downtime_is_fixed' => 'sd.is_fixed',
'downtime_duration' => 'sd.duration',
'downtime_scheduled_start_time' => 'sd.scheduled_start_time',
'downtime_scheduled_end_time' => 'sd.scheduled_end_time',
'downtime_was_started' => 'sd.was_started',
'downtime_actual_start_time' => 'sd.actual_start_time',
'downtime_actual_start_time_usec' => 'sd.actual_start_time_usec',
'downtime_is_in_effect' => 'sd.is_in_effect',
'downtime_trigger_time' => 'sd.trigger_time',
'downtime_triggered_by_id' => 'sd.triggered_by_id',
'downtime_internal_downtime_id' => 'sd.internal_downtime_id'
'downtime_author' => 'sd.author_name',
'downtime_comment' => 'sd.comment_data',
'downtime_entry_time' => 'sd.entry_time',
'downtime_is_fixed' => 'sd.is_fixed',
'downtime_is_flexible' => 'CASE WHEN sd.is_fixed = 0 THEN 1 ELSE 0 END',
'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_duration' => 'sd.duration',
'downtime_is_in_effect' => 'sd.is_in_effect',
'downtime_triggered_by_id' => 'sd.triggered_by_id',
'downtime_internal_downtime_id' => 'sd.internal_downtime_id',
),
'objects' => array(
'host_name' => 'o.name1 COLLATE latin1_general_ci',
'service_host_name' => 'o.name1 COLLATE latin1_general_ci',
'service_description' => 'o.name2 COLLATE latin1_general_ci',
'object_type' => "CASE o.objecttype_id WHEN 1 THEN 'host' ELSE 'service' END",
'host' => 'o.name1 COLLATE latin1_general_ci',
'service' => 'o.name2 COLLATE latin1_general_ci'
)
);

View File

@ -14,23 +14,17 @@ class Downtime extends DataView
public function getColumns()
{
return array(
'host_name',
'object_type',
'service_host_name',
'service_description',
'downtime_type',
'downtime_author_name',
'downtime_comment_data',
'downtime_is_fixed',
'downtime_duration',
'host',
'service',
'downtime_author',
'downtime_comment',
'downtime_entry_time',
'downtime_scheduled_start_time',
'downtime_scheduled_end_time',
'downtime_was_started',
'downtime_actual_start_time',
'downtime_actual_start_time_usec',
'downtime_is_fixed',
'downtime_is_flexible',
'downtime_start',
'downtime_end',
'downtime_duration',
'downtime_is_in_effect',
'downtime_trigger_time',
'downtime_triggered_by_id',
'downtime_internal_downtime_id'
);
@ -42,7 +36,7 @@ class Downtime extends DataView
'downtime_is_in_effect' => array(
'order' => self::SORT_DESC
),
'downtime_actual_start_time' => array(
'downtime_start' => array(
'order' => self::SORT_DESC
)
);

View File

@ -68,23 +68,7 @@ abstract class AbstractObject
public function fetchDowntimes()
{
$this->downtimes = Downtime::fromRequest(
$this->request,
array(
'downtime_type',
'downtime_author_name',
'downtime_comment_data',
'downtime_is_fixed',
'downtime_duration',
'downtime_entry_time',
'downtime_scheduled_start_time',
'downtime_scheduled_end_time',
'downtime_was_started',
'downtime_actual_start_time',
'downtime_is_in_effect',
'downtime_triggered_by_id',
)
)->getQuery()->fetchAll();
$this->downtimes = Downtime::fromRequest($this->request)->getQuery()->fetchAll();
return $this;
}