Cleaning up object downtimes. What a mess... :(

This commit is contained in:
Thomas Gelf 2014-03-08 18:28:19 +01:00
parent 485222492b
commit 740df4ccac
10 changed files with 124 additions and 86 deletions

View File

@ -624,6 +624,7 @@ class Monitoring_CommandController extends ActionController
if ($form->IsSubmittedAndValid() === true) {
$this->target->sendCommand($form->createCommand(), $this->view->objects);
Notification::success('Downtime scheduling requested, result should be shown soon');
}
}
@ -641,6 +642,7 @@ class Monitoring_CommandController extends ActionController
if ($form->IsSubmittedAndValid() === true) {
$this->target->sendCommand($form->createCommand(), $this->view->objects);
Notification::success('Downtime scheduling requested, result should be shown soon');
}
}
@ -659,6 +661,7 @@ class Monitoring_CommandController extends ActionController
if ($form->IsSubmittedAndValid() === true) {
$this->target->sendCommand($form->createCommand(), $this->view->objects);
Notification::success('Downtime removal requested, result should be shown soon');
}
}

View File

@ -37,6 +37,8 @@ use Icinga\Protocol\Commandpipe\Comment;
use Icinga\Util\DateTimeFactory;
use Icinga\Module\Monitoring\Backend;
use Icinga\Module\Monitoring\Command\ScheduleDowntimeCommand;
use Icinga\Module\Monitoring\Object\AbstractObject;
use Icinga\Module\Monitoring\Object\Service;
/**
* Form for scheduling downtimes
@ -89,6 +91,11 @@ class ScheduleDowntimeForm extends WithChildrenCommandForm
$cfg = $this->getConfiguration();
$preferences = $this->getUserPreferences();
$object = AbstractObject::fromRequest($this->getRequest());
$object->fetchDowntimes();
$downtimes = $object->downtimes;
/*
$downtimes = Backend::createBackend($this->getRequest()->getParam('backend'))->select()
->from(
'downtime',
@ -100,7 +107,7 @@ class ScheduleDowntimeForm extends WithChildrenCommandForm
'downtime_internal_downtime_id'
)
)->fetchAll();
*/
$options = array(
'0' => 'No Triggered Downtime'
);
@ -109,8 +116,8 @@ class ScheduleDowntimeForm extends WithChildrenCommandForm
$label = sprintf(
'ID %s: %s%s Starting @ %s',
$downtime->downtime_internal_downtime_id,
$downtime->host,
!empty($downtime->service_description) ? ' (' . $downtime->service_description . ')' : '',
$object->host_name,
$object instanceof Service ? ' (' . $object->service_description . ')' : '',
$dateFormat->formatDateTime($downtime->downtime_scheduled_start_time)
);
$options[$downtime->downtime_internal_downtime_id] = $label;

View File

@ -1,66 +1,51 @@
<div>
<div class="panel-heading">
<div class="panel-hostname">
<?php
<div class="pull-right">
<?php
$scheduleDowntimeData = array(
'host' => $this->object->host_name,
'service' => $this->object->service_description
);
$cf = $this->getHelper('CommandForm');
$scheduleDowntimeHref = $this->href('monitoring/command/scheduleDowntime', $scheduleDowntimeData);
?>
<a href="<?= $scheduleDowntimeHref; ?>" class="btn-common btn-small button" title="Schedule downtime">
<?= $this->icon('in_downtime.png') ?>
</a>
</div>
Downtimes
</div>
</div>
<hr class="separator" />
<div class="panel-body">
<table class="table table-condensed table-detail">
<tbody>
<?php if (empty($this->object->downtimes)): ?>
<tr>
<td>No Downtimes</td>
</tr>
<?php else: ?>
<?php foreach ($this->object->downtimes as $downtime): ?>
<tr>
<td>
<div class="pull-right">
<?= $this->getHelper('CommandForm')->iconSubmitForm(
'img/icons/remove.png',
'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'): ?>
In scheduled downtime since <?= $this->timeSince($downtime->downtime_start); ?>
<?php else: ?>
<?php if ($downtime->downtime_is_fixed): ?>
Downtime scheduled for <?= $downtime->downtime_start; ?>
<?php else: ?>
Waiting
<?php endif; ?>
<?php endif; ?>
$data = array('host' => $object->host_name);
if ($object->service_description) {
$data['service'] = $object->service_description;
}
<div class="small-row">
<?= $downtime->downtime_author; ?>: <?= $downtime->downtime_comment; ?>
</div>
</td>
</tr>
<?php endforeach; ?>
<?php endif; ?>
</tbody>
</table>
</div>
</div>
$list = array();
foreach ($object->downtimes as $downtime) {
$deleteData = $data;
$deleteData['downtimeid'] = $object->downtime_internal_downtime_id;
// TODO: This needs improvement
if ((int) $downtime->downtime_is_in_effect) {
$state = 'in downtime since ' . $this->timeSince($downtime->downtime_start);
} else {
if ($downtime->downtime_is_fixed) {
$state = 'scheduled ' . $this->timeUnless($downtime->downtime_start);
} else {
$state = 'scheduled flexible ' . $this->timeUnless($downtime->downtime_start);
}
}
$iconForm = $cf->iconSubmitForm(
'img/icons/remove_petrol.png',
'Remove Downtime',
'link-like',
'removedowntime',
$deleteData
);
$list[] = sprintf(
"<br />%s [%s] (%s): %s\n",
$iconForm,
$this->escape($downtime->downtime_author),
$state,
$this->escape($downtime->downtime_comment)
);
}
?>
<tr>
<th><?= $this->translate('Downtimes') ?></th>
<td>
<a href="<?= $this->href('monitoring/command/scheduleDowntime', $data) ?>"><?= $this->icon('in_downtime_petrol.png') ?> <?= $this->translate('Schedule downtime') ?></a>
<?= implode('', $list) ?>
</td>
</tr>

View File

@ -6,11 +6,9 @@
<?= $this->render('show/components/output.phtml') ?>
<?= $this->render('show/components/status.phtml') ?>
<?= $this->render('show/components/downtime.phtml') ?>
<table class="avp">
<?= $this->render('show/components/comments.phtml') ?>
<?= $this->render('show/components/downtime.phtml') ?>
<?= $this->render('show/components/flapping.phtml') ?>
<?= $this->render('show/components/perfdata.phtml') ?>
<?= $this->render('show/components/command.phtml') ?>

View File

@ -6,11 +6,9 @@
<?= $this->render('show/components/status.phtml') ?>
<?= $this->render('show/components/output.phtml') ?>
<?= $this->render('show/components/downtime.phtml') ?>
<table class="avp">
<?= $this->render('show/components/comments.phtml') ?>
<?= $this->render('show/components/downtime.phtml') ?>
<?= $this->render('show/components/flapping.phtml') ?>
<?= $this->render('show/components/perfdata.phtml') ?>
<?= $this->render('show/components/command.phtml') ?>

View File

@ -40,6 +40,7 @@ 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)',
@ -53,12 +54,16 @@ class DowntimeQuery extends IdoQuery
'downtime_triggered_by_id' => 'sd.triggered_by_id',
'downtime_internal_downtime_id' => 'sd.internal_downtime_id',
),
'objects' => array(
'host' => 'o.name1 COLLATE latin1_general_ci',
'host_name' => 'o.name1 COLLATE latin1_general_ci',
'service' => 'o.name2 COLLATE latin1_general_ci',
'service_description' => 'o.name2 COLLATE latin1_general_ci'
'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',
)
);
@ -72,17 +77,32 @@ class DowntimeQuery extends IdoQuery
array()
);
$this->joinedVirtualTables = array('downtime' => true, 'services' => true);
$this->baseQuery->join(
array(
'sdo' => $this->prefix . 'objects'
),
'sd.object_id = sdo.' . $this->object_id . ' AND sdo.is_active = 1'
);
$this->joinedVirtualTables = array('downtime' => true);
}
/**
* Join if host needed
*/
protected function joinObjects()
protected function joinHosts()
{
$this->conflictsWithVirtualTable('services');
$this->baseQuery->join(
array('o' => $this->prefix . 'objects'),
'sd.object_id = o.object_id AND o.is_active = 1 AND o.objecttype_id IN (1, 2)',
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

@ -43,6 +43,7 @@ class Downtime extends DataView
'host_name',
'service',
'service_description',
'downtime_objecttype_id',
'downtime_author',
'downtime_comment',
'downtime_entry_time',

View File

@ -44,11 +44,13 @@ abstract class AbstractObject
{
// WTF???
$query = Comment::fromParams(array('backend' => null), array(
'comment_internal_id',
'comment_timestamp',
'comment_author',
'comment_data',
'comment_type',
))->getQuery();
$query->where('comment_type', array('comment', 'ack'));
$query->where('comment_objecttype_id', $this->type);
$this->applyObjectFilter($query);
$this->comments = $query->fetchAll();
@ -73,6 +75,28 @@ abstract class AbstractObject
public function fetchDowntimes()
{
// TODO: We want to check for objecttype = 'host', not type_id = 1
// 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'
))->getQuery();
$query->where('downtime_objecttype_id', $this->type);
$this->applyObjectFilter($query);
$this->downtimes = $query->fetchAll();
return $this;
$this->downtimes = Downtime::fromRequest($this->request)->getQuery()->fetchAll();
return $this;
}

View File

@ -23,7 +23,8 @@ class Host extends AbstractObject
->fetchHostgroups()
->fetchContacts()
->fetchContactGroups()
->fetchCustomvars();
->fetchCustomvars()
->fetchDowntimes();
}
protected function getProperties()

View File

@ -24,7 +24,8 @@ class Service extends AbstractObject
->fetchServicegroups()
->fetchContacts()
->fetchContactGroups()
->fetchCustomvars();
->fetchCustomvars()
->fetchDowntimes();
}
protected function getProperties()