Comments are still messy, clean up and fix adding / removing them

This commit is contained in:
Thomas Gelf 2014-03-09 19:29:23 +01:00
parent bd0c36ad7a
commit 63fd074a4f
8 changed files with 76 additions and 106 deletions

View File

@ -319,16 +319,16 @@ class Monitoring_ListController extends Controller
$query = CommentView::fromRequest(
$this->_request,
array(
'comment_objecttype_id',
'comment_id',
'comment_data',
'comment_author',
'comment_timestamp',
'comment_type',
'comment_is_persistent',
'comment_expiration_timestamp',
'host_name' => 'service_host_name',
'service_name'
'id' => 'comment_internal_id',
'objecttype' => 'comment_objecttype',
'comment' => 'comment_data',
'author' => 'comment_author',
'timestamp' => 'comment_timestamp',
'type' => 'comment_type',
'persistent' => 'comment_is_persistent',
'expiration' => 'comment_expiration_timestamp',
'host',
'service'
)
)->getQuery();
@ -336,11 +336,10 @@ class Monitoring_ListController extends Controller
$this->setupSortControl(
array(
'comment_timestamp' => 'Comment Timestamp',
'host_service' => 'Host and Service',
'comment_id' => 'Comment Id',
'comment_expires' => 'Expiration Timestamp',
'comment_type' => 'Comment Type'
'timestamp' => 'Comment Timestamp',
'host' => 'Host / Service',
'type' => 'Comment Type',
'expiration' => 'Expiration',
)
);
$this->handleFormatRequest($query);

View File

@ -15,13 +15,11 @@ $cf = $this->getHelper('CommandForm');
foreach ($comments as $comment):
$objectType = (int) $comment->comment_objecttype_id === 1 ? 'host' : 'service';
?>
<tr>
<td style="width: 5em; text-align: center;">
<?php
switch ($comment->comment_type) {
switch ($comment->type) {
case 'flapping':
$icon = 'flapping';
$tooltip = 'Comment was caused by a flapping host or service.';
@ -39,28 +37,28 @@ foreach ($comments as $comment):
}
?>
<?= $this->icon($icon . '.png', $tooltip) ?><br />
<?= $this->timeSince($comment->comment_timestamp) ?>
<?= $this->timeSince($comment->timestamp) ?>
</td>
<td>
<?php if ($objectType === 'service'): ?><?= $this->icon('service.png', 'Service comment') ?> <?= $this->qlink(
$comment->service_name,
<?php if ($comment->objecttype === 'service'): ?><?= $this->icon('service.png', 'Service comment') ?> <?= $this->qlink(
$comment->service,
'monitoring/show/service',
array(
'host' => $comment->host_name,
'service' => $comment->service_name,
'host' => $comment->host,
'service' => $comment->service,
)
) ?> on<?php else: ?><?= $this->icon('host.png', 'Host comment') ?> <?php endif ?> <?= $this->qlink(
$comment->host_name,
$comment->host,
'monitoring/show/host',
array(
'host' => $comment->host_name
'host' => $comment->host
)
) ?> by <strong><?= $this->escape($comment->comment_author) ?></strong><br />
<p><?= $this->escape($comment->comment_data) ?></p>
<?php if ($comment->comment_is_persistent): ?>Comment is persistent<br /><?php endif ?>
) ?> by <strong><?= $this->escape($comment->author) ?></strong><br />
<p><?= $this->escape($comment->comment) ?></p>
<?php if ($comment->persistent): ?>Comment is persistent<br /><?php endif ?>
<b>Expires: </b> <?=
($comment->comment_expiration_timestamp) ?
$this->timeUnless($comment->comment_expiration_timestamp) :
($comment->expiration) ?
$this->timeUnless($comment->expiration) :
'Never'
?>
</td>
@ -68,12 +66,12 @@ foreach ($comments as $comment):
<?php
$data = array(
'commentid' => $comment->comment_id,
'host' => $comment->host_name
'commentid' => $comment->id,
'host' => $comment->host
);
if ($objectType === 'service') {
$data['service'] = $comment->service_name;
if ($comment->objecttype === 'service') {
$data['service'] = $comment->service;
}
echo $cf->iconSubmitForm(

View File

@ -14,11 +14,11 @@ foreach ($object->comments as $comment) {
$text = $this->tickets ? preg_replace_callback(
$this->tickets->getPattern(),
array($this->tickets, 'createLink'),
$this->escape($comment->comment_data)
) : $this->escape($comment->comment_data);
$this->escape($comment->comment)
) : $this->escape($comment->comment);
$deleteData = $data;
$deleteData['commentid'] = $object->comment_internal_id;
$deleteData['commentid'] = $comment->id;
$iconForm = $cf->iconSubmitForm(
'img/icons/remove_petrol.png',
@ -31,9 +31,9 @@ foreach ($object->comments as $comment) {
$list[] = sprintf(
"<br />%s [%s] %s (%s): %s\n",
$iconForm,
$this->escape($comment->comment_author),
$this->timeSince($comment->comment_timestamp),
$comment->comment_type,
$this->escape($comment->author),
$this->timeSince($comment->timestamp),
$comment->type,
$text
);
}

View File

@ -36,23 +36,20 @@ class CommentQuery extends IdoQuery
{
protected $columnMap = array(
'comments' => array(
'comment_objecttype_id' => 'co.objecttype_id',
'comment_id' => 'cm.internal_comment_id',
'comment_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",
'comment_internal_id' => 'cm.internal_comment_id',
'comment_data' => 'cm.comment_data',
'comment_author' => 'cm.author_name COLLATE latin1_general_ci',
'comment_timestamp' => 'UNIX_TIMESTAMP(cm.comment_time)',
'comment_type' => "CASE cm.entry_type WHEN 1 THEN 'comment' WHEN 2 THEN 'downtime' WHEN 3 THEN 'flapping' WHEN 4 THEN 'ack' END",
'comment_is_persistent' => 'cm.is_persistent',
'comment_expiration_timestamp' => 'CASE cm.expires WHEN 1 THEN UNIX_TIMESTAMP(cm.expiration_time) ELSE NULL END'
'comment_expiration_timestamp' => 'CASE cm.expires WHEN 1 THEN UNIX_TIMESTAMP(cm.expiration_time) ELSE NULL END',
),
'hosts' => array(
'host_name' => 'ho.name1 COLLATE latin1_general_ci',
'host' => 'ho.name1 COLLATE latin1_general_ci',
'host_name' => 'CASE WHEN ho.name1 IS NULL THEN so.name1 ELSE ho.name1 END COLLATE latin1_general_ci',
'host' => 'CASE WHEN ho.name1 IS NULL THEN so.name1 ELSE ho.name1 END 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',
@ -66,32 +63,35 @@ class CommentQuery extends IdoQuery
array()
);
/*
$this->baseQuery->join(
array(
'co' => $this->prefix . 'objects'
),
'cm.object_id = co.' . $this->object_id . ' AND co.is_active = 1'
);
);*/
$this->joinedVirtualTables = array('comments' => true);
$this->joinVirtualTable('hosts');
$this->joinVirtualTable('services');
}
protected function joinHosts()
{
$this->conflictsWithVirtualTable('services');
$this->baseQuery->join(
// $this->conflictsWithVirtualTable('services');
$this->baseQuery->joinLeft(
array('ho' => $this->prefix . 'objects'),
'co.name1 = ho.name1 AND ho.is_active = 1 AND ho.objecttype_id = 1',
'cm.object_id = ho.object_id AND ho.is_active = 1 AND ho.objecttype_id = 1',
array()
);
}
protected function joinServices()
{
$this->conflictsWithVirtualTable('hosts');
// $this->conflictsWithVirtualTable('hosts');
$this->baseQuery->joinLeft(
array('so' => $this->prefix . 'objects'),
'co.name1 = so.name1 AND co.name2 = so.name2 AND so.is_active = 1 AND co.is_active = 1 AND so.objecttype_id = 2',
'cm.object_id = so.object_id AND so.is_active = 1 AND so.objecttype_id = 2',
array()
);
}

View File

@ -42,8 +42,8 @@ class Comment extends DataView
public function getColumns()
{
return array(
'comment_objecttype_id',
'comment_id',
'comment_objecttype',
'comment_internal_id',
'comment_data',
'comment_author',
'comment_timestamp',
@ -51,10 +51,7 @@ class Comment extends DataView
'comment_is_persistent',
'comment_expiration_timestamp',
'host_name',
'service_host_name',
'service_name',
'host',
'service'
'service_description',
);
}
@ -67,21 +64,15 @@ class Comment extends DataView
{
return array(
'comment_timestamp' => array(
'order' => self::SORT_DESC
'order' => self::SORT_DESC
),
'host_service' => array(
'columns' => array(
'host_name' => array(
'columns' => array(
'host_name',
'service_name'
),
'order' => self::SORT_ASC
'order' => self::SORT_ASC
),
'comment_id' => array(
'order' => self::SORT_ASC
),
'comment_expires' => array(
'order' => self::SORT_DESC
)
);
}
}

View File

@ -14,11 +14,8 @@ use Icinga\Web\Request;
abstract class AbstractObject
{
const TYPE_HOST = 1;
const TYPE_SERVICE = 2;
public $type = self::TYPE_HOST;
public $prefix = 'host_';
public $type;
public $prefix;
public $comments = array();
public $downtimes = array();
@ -44,33 +41,20 @@ abstract class AbstractObject
{
// WTF???
$query = Comment::fromParams(array('backend' => null), array(
'comment_internal_id',
'comment_timestamp',
'comment_author',
'comment_data',
'comment_type',
'id' => 'comment_internal_id',
'timestamp' => 'comment_timestamp',
'author' => 'comment_author',
'comment' => 'comment_data',
'type' => 'comment_type',
))->getQuery();
$query->where('comment_type', array('comment', 'ack'));
$query->where('comment_objecttype_id', $this->type);
$this->applyObjectFilter($query);
$query->where('comment_objecttype', $this->type);
$query->where('host_name', $this->host_name);
if ($this->type === 'service') {
$query->where('service_description', $this->service_description);
}
$this->comments = $query->fetchAll();
return $this;
$this->comments = Comment::fromRequest(
$this->request,
array(
'comment_internal_id',
'comment_timestamp',
'comment_author',
'comment_data',
'comment_type',
)
)->getQuery()
//->where('comment_objecttype_id', 1)
->fetchAll();
return $this;
}
public function fetchDowntimes()
@ -124,7 +108,7 @@ abstract class AbstractObject
)
)->getQuery();
if ($this->type === self::TYPE_HOST) {
if ($this->type === 'host') {
$query->where('host_name', $this->host_name)
->where('object_type', 'host');
} else {

View File

@ -7,10 +7,9 @@ use Icinga\Data\Db\Query;
class Host extends AbstractObject
{
public $type = self::TYPE_HOST;
public $prefix = 'host_';
private $view = null;
public $typ = 'host';
public $prefix = 'host_';
private $view = null;
protected function applyObjectFilter(Query $query)
{

View File

@ -7,10 +7,9 @@ use Icinga\Data\Db\Query;
class Service extends AbstractObject
{
public $type = self::TYPE_SERVICE;
public $prefix = 'service_';
private $view = null;
public $type = 'service';
public $prefix = 'service_';
private $view = null;
protected function applyObjectFilter(Query $query)
{