The next fat package: downtimes, everywhere

This commit is contained in:
Thomas Gelf 2014-03-09 21:58:01 +01:00
parent ee01b28646
commit 88859cb838
7 changed files with 80 additions and 78 deletions

View File

@ -1022,6 +1022,7 @@ class Monitoring_CommandController extends ActionController
if ($form->IsSubmittedAndValid() === true) {
$this->target->sendCommand($form->createCommand(), $this->view->objects);
Notification::success('Downtime removal has been requested');
}
}

View File

@ -194,7 +194,24 @@ class Monitoring_ListController extends Controller
'title' => 'Downtimes',
'url' => Url::fromPath('monitoring/list/downtimes')
))->activate('downtimes');
$query = DowntimeView::fromRequest($this->_request)->getQuery()->order('downtime_is_in_effect', 'DESC')->order('downtime_scheduled_start_time', 'DESC');
$this->setAutorefreshInterval(12);
$query = DowntimeView::fromRequest(
$this->_request,
array(
'id' => 'downtime_internal_id',
'objecttype' => 'downtime_objecttype',
'comment' => 'downtime_comment',
'author' => 'downtime_author',
'start' => 'downtime_start',
'end' => 'downtime_end',
'duration' => 'downtime_duration',
'is_flexible' => 'downtime_is_flexible',
'is_in_effect' => 'downtime_is_in_effect',
'entry_time' => 'downtime_entry_time',
'host' => 'downtime_host',
'service' => 'downtime_service'
)
)->getQuery()->order('downtime_is_in_effect', 'DESC')->order('downtime_scheduled_start_time', 'DESC');
$this->view->downtimes = $query->paginate();
$this->setupSortControl(array(

View File

@ -3,20 +3,24 @@ $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">
<table class="action">
<tbody>
<?php foreach ($downtimes as $downtime): ?>
<?php foreach ($this->downtimes as $downtime): ?>
<tr>
<td>
<?= $this->dateFormat()->formatDateTime((int) $downtime->downtime_start); ?> -
<?= $this->dateFormat()->formatDateTime((int) $downtime->downtime_end); ?>
<?= $this->dateFormat()->formatDateTime($downtime->start); ?> -
<?= $this->dateFormat()->formatDateTime($downtime->end); ?>
<br />
<small>Duration: <?= $this->util()->showHourMin((int) $downtime->downtime_duration); ?></small>
<small>Duration: <?= $this->util()->showHourMin($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>
<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)): ?>
@ -31,14 +35,14 @@ $helper = $this->getHelper('CommandForm');
)); ?>"><?= $downtime->host ?> </a>
<?php endif; ?>
<br />
<?= $downtime->downtime_author ?>: <?= $downtime->downtime_comment ?>
<?= $downtime->author ?>: <?= $downtime->comment ?>
<br />
<small>Entry Time: <?= ($downtime->downtime_entry_time) ? $this->dateFormat()->formatDateTime((int) $downtime->downtime_entry_time) : ''; ?>
<small>Entry Time: <?= ($downtime->entry_time) ? $this->dateFormat()->formatDateTime((int) $downtime->entry_time) : ''; ?>
</small>
<td>
<td style="width: 2em">
<?php
$data = array(
'downtimeid' => $downtime->downtime_internal_downtime_id,
'downtimeid' => $downtime->id,
'host' => $downtime->host
);
if (isset($downtime->service)) {
@ -47,7 +51,7 @@ $helper = $this->getHelper('CommandForm');
echo $helper->iconSubmitForm(
'img/icons/remove.png',
'Remove Downtime',
'btn-small',
'link-like',
'removedowntime',
$data
);
@ -57,3 +61,4 @@ $helper = $this->getHelper('CommandForm');
<?php endforeach ?>
</tbody>
</table>
</div>

View File

@ -11,16 +11,16 @@ if ($object->service_description) {
$list = array();
foreach ($object->downtimes as $downtime) {
$deleteData = $data;
$deleteData['downtimeid'] = $object->downtime_internal_downtime_id;
$deleteData['downtimeid'] = $downtime->id;
// TODO: This needs improvement
if ((int) $downtime->downtime_is_in_effect) {
$state = 'in downtime since ' . $this->timeSince($downtime->downtime_start);
if ((int) $downtime->is_in_effect) {
$state = 'in downtime since ' . $this->timeSince($downtime->start);
} else {
if ($downtime->downtime_is_fixed) {
$state = 'scheduled ' . $this->timeUnless($downtime->downtime_start);
if ($downtime->is_fixed) {
$state = 'scheduled ' . $this->timeUnless($downtime->start);
} else {
$state = 'scheduled flexible ' . $this->timeUnless($downtime->downtime_start);
$state = 'scheduled flexible ' . $this->timeUnless($downtime->start);
}
}
@ -35,9 +35,9 @@ foreach ($object->downtimes as $downtime) {
$list[] = sprintf(
"<br />%s [%s] (%s): %s\n",
$iconForm,
$this->escape($downtime->downtime_author),
$this->escape($downtime->author),
$state,
$this->escape($downtime->downtime_comment)
$this->escape($downtime->comment)
);
}

View File

@ -40,31 +40,22 @@ class DowntimeQuery extends IdoQuery
*/
protected $columnMap = array(
'downtime' => array(
'downtime_objecttype_id' => 'sdo.objecttype_id',
'downtime_author' => 'sd.author_name',
'downtime_comment' => 'sd.comment_data',
'downtime_entry_time' => 'UNIX_TIMESTAMP(sd.entry_time)',
'downtime_is_fixed' => 'sd.is_fixed',
'downtime_is_flexible' => 'CASE WHEN sd.is_fixed = 0 THEN 1 ELSE 0 END',
'downtime_triggered_by_id' => 'sd.triggered_by_id',
'downtime_scheduled_start_time' => 'UNIX_TIMESTAMP(sd.scheduled_start_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_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',
'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",
),
'hosts' => array(
'host_name' => 'ho.name1 COLLATE latin1_general_ci',
'host' => 'ho.name1 COLLATE latin1_general_ci',
),
'services' => array(
'service_host_name' => 'so.name1 COLLATE latin1_general_ci',
'service' => 'so.name2 COLLATE latin1_general_ci',
'service_name' => 'so.name2 COLLATE latin1_general_ci',
'service_description' => 'so.name2 COLLATE latin1_general_ci',
)
);
/**
@ -77,33 +68,18 @@ class DowntimeQuery extends IdoQuery
array()
);
$this->baseQuery->join(
array(
'sdo' => $this->prefix . 'objects'
),
'sd.object_id = sdo.' . $this->object_id . ' AND sdo.is_active = 1'
$this->baseQuery->joinLeft(
array('ho' => $this->prefix . 'objects'),
'sd.object_id = ho.object_id AND ho.is_active = 1 AND ho.objecttype_id = 1',
array()
);
$this->baseQuery->joinLeft(
array('so' => $this->prefix . 'objects'),
'sd.object_id = so.object_id AND so.is_active = 1 AND so.objecttype_id = 2',
array()
);
$this->joinedVirtualTables = array('downtime' => true);
}
protected function joinHosts()
{
$this->conflictsWithVirtualTable('services');
$this->baseQuery->join(
array('ho' => $this->prefix . 'objects'),
'sdo.name1 = ho.name1 AND ho.is_active = 1 AND ho.objecttype_id = 1',
array()
);
}
protected function joinServices()
{
$this->conflictsWithVirtualTable('hosts');
$this->baseQuery->joinLeft(
array('so' => $this->prefix . 'objects'),
'sdo.name1 = so.name1 AND sdo.name2 = so.name2 AND so.is_active = 1 AND sdo.is_active = 1 AND so.objecttype_id = 2',
array()
);
}
}

View File

@ -39,11 +39,7 @@ class Downtime extends DataView
public function getColumns()
{
return array(
'host',
'host_name',
'service',
'service_description',
'downtime_objecttype_id',
'downtime_objecttype',
'downtime_author',
'downtime_comment',
'downtime_entry_time',
@ -54,7 +50,9 @@ class Downtime extends DataView
'downtime_duration',
'downtime_is_in_effect',
'downtime_triggered_by_id',
'downtime_internal_downtime_id'
'downtime_internal_id',
'downtime_host',
'downtime_service',
);
}

View File

@ -66,21 +66,26 @@ abstract class AbstractObject
// WTF???
$query = Downtime::fromParams(array('backend' => null), array(
'downtime_author',
'downtime_comment',
'downtime_entry_time',
'downtime_is_fixed',
'downtime_is_flexible',
'downtime_scheduled_start_time',
'downtime_start',
'downtime_end',
'downtime_duration',
'downtime_is_in_effect',
'downtime_triggered_by_id',
'downtime_internal_downtime_id'
'id' => 'downtime_internal_id',
'objecttype' => 'downtime_objecttype',
'comment' => 'downtime_comment',
'author' => 'downtime_author',
'start' => 'downtime_start',
'end' => 'downtime_end',
'duration' => 'downtime_duration',
'is_flexible' => 'downtime_is_flexible',
'is_in_effect' => 'downtime_is_in_effect',
'entry_time' => 'downtime_entry_time',
'host' => 'downtime_host',
'service' => 'downtime_service'
))->getQuery();
$query->where('downtime_objecttype_id', $this->type);
$this->applyObjectFilter($query);
$query->where('downtime_objecttype', $this->type);
$query->where('downtime_host', $this->host_name);
if ($this->type === 'service') {
$query->where('downtime_service', $this->service_description);
}
$this->downtimes = $query->fetchAll();
return $this;