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() public function downtimesAction()
{ {
$query = DowntimeView::fromRequest( $query = DowntimeView::fromRequest($this->_request)->getQuery();
$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();
$this->view->downtimes = $query->paginate(); $this->view->downtimes = $query->paginate();
$this->setupSortControl(array( $this->setupSortControl(array(

View File

@ -1,135 +1,63 @@
<?php <?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'); $commandHelper = $this->getHelper('CommandForm');
?> ?>
<?= $this->tabs->render($this); ?> <div data-icinga-component="app/mainDetailGrid" data-icinga-grid-selection-type="single">
<div data-icinga-component="app/mainDetailGrid" data-icinga-grid-selection-type="none">
<div> <div>
<?= $this->sortControl->render($this); ?> <?= $this->sortControl->render($this); ?>
</div> </div>
<div> <div>
<?= $this->paginationControl( <?= $this->paginationControl($downtimes, null, null, array('preserve' => $this->preserve)); ?>
$this->downtimes,
null,
array(
'mixedPagination.phtml',
'default'
),
array('preserve' => $this->preserve)
);
?>
<table class="table table-condensed"> <table class="table table-condensed">
<thead> <tbody>
<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>
<?php foreach ($downtimes as $downtime): ?> <?php foreach ($downtimes as $downtime): ?>
<tr> <tr>
<td> <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>
<td> <td>
<div> <?php if (isset($downtime->service)): ?>
<?php if ($downtime->object_type == 'service'): ?> <a href="<?= $this->href('monitoring/show/service', array(
{{SERVICE_ICON}} 'host' => $downtime->host,
<?php endif; ?> 'service' => $downtime->service
)); ?>"><?= $downtime->service ?></a>
<?php if ($downtime->object_type == 'host'): ?> <small>on <?= $downtime->host ?></small>
{{HOST_ICON}} <?php else: ?>
<?php endif; ?> <a href="<?= $this->href('monitoring/show/host', array(
</div> 'host' => $downtime->host
</td> )); ?>"><?= $downtime->host ?></a>
<td> <?php endif; ?>
<?= $downtime->host_name ?> <br />
</td> <?= $downtime->downtime_author ?>: <?= $downtime->downtime_comment ?>
<td> <br />
<?= $downtime->service_description ?> <small>Entry Time: <?= $downtime->downtime_entry_time ?></small>
</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>
<td> <td>
<?php <?php
$data = array( $data = array(
'downtimeid' => $downtime->downtime_internal_downtime_id, 'downtimeid' => $downtime->downtime_internal_downtime_id,
'host' => $downtime->host_name 'host' => $downtime->host
); );
if (isset($downtime->service)) {
if ($downtime->object_type == 'service') { $data['service'] = $downtime->service;
$data['service'] = $downtime->service_description;
} }
echo $commandHelper->iconSubmitForm(
echo $commandHelper->simpleForm( 'icinga-icon-remove',
'removedowntime',
'Remove Downtime', 'Remove Downtime',
'btn-small',
'removedowntime',
$data $data
); );
?> ?>
</td> </td>
</tr> </tr>
<?php endforeach ?> <?php endforeach ?>
</tbody>
</table> </table>
<?= $this->paginationControl($downtimes, null, null, array('preserve' => $this->preserve)); ?>
</div> </div>
</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>
<div class="panel-heading"> <div class="panel-heading">
<div class="panel-hostname"> <div class="panel-hostname">
@ -61,30 +31,30 @@
<tr> <tr>
<td> <td>
<div class="pull-right"> <div class="pull-right">
<form action="<?= $this->href('monitoring/command/removeDowntime'); ?>" data-icinga-component="app/ajaxPostSubmitForm"> <?= $this->getHelper('CommandForm')->iconSubmitForm(
<button type="submit" class="button btn-common btn-small" name="btn_submit" value="1"> 'icinga-icon-remove',
<i class="icinga-icon-remove"></i> 'Remove Downtime',
</button> 'btn-small',
<input type="hidden" name="host" value="<?= $downtime->host_name; ?>" /> 'removedowntime',
<input type="hidden" name="service" value="<?= $downtime->service_description; ?>" /> array(
<input type="hidden" name="downtimeid" value="<?= $downtime->downtime_internal_downtime_id; ?>" /> 'downtimeid' => $downtime->downtime_internal_downtime_id,
<input type="hidden" name="CSRFToken" value="" /> 'host' => $downtime->host,
</form> 'service' => $downtime->service
)
); ?>
</div> </div>
<?php if ($downtime->downtime_is_in_effect === '1'): ?> <?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 else: ?>
<?php if ($downtime->downtime_is_fixed): ?> <?php if ($downtime->downtime_is_fixed): ?>
Scheduled for <?= $downtime->downtime_scheduled_start_time; ?> Downtime scheduled for <?= $downtime->downtime_start; ?>
<?php else: ?> <?php else: ?>
Waiting Waiting
<?php endif; ?> <?php endif; ?>
<?php endif; ?> <?php endif; ?>
Triggered by <?= $downtime->downtime_author_name; ?>
<div class="small-row"> <div class="small-row">
<?= $downtime->downtime_comment_data; ?> <?= $downtime->downtime_author; ?>: <?= $downtime->downtime_comment; ?>
</div> </div>
</td> </td>
</tr> </tr>

View File

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

View File

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

View File

@ -68,23 +68,7 @@ abstract class AbstractObject
public function fetchDowntimes() public function fetchDowntimes()
{ {
$this->downtimes = Downtime::fromRequest( $this->downtimes = Downtime::fromRequest($this->request)->getQuery()->fetchAll();
$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();
return $this; return $this;
} }