mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-27 07:44:04 +02:00
Comments are still messy, clean up and fix adding / removing them
This commit is contained in:
parent
bd0c36ad7a
commit
63fd074a4f
@ -319,16 +319,16 @@ class Monitoring_ListController extends Controller
|
|||||||
$query = CommentView::fromRequest(
|
$query = CommentView::fromRequest(
|
||||||
$this->_request,
|
$this->_request,
|
||||||
array(
|
array(
|
||||||
'comment_objecttype_id',
|
'id' => 'comment_internal_id',
|
||||||
'comment_id',
|
'objecttype' => 'comment_objecttype',
|
||||||
'comment_data',
|
'comment' => 'comment_data',
|
||||||
'comment_author',
|
'author' => 'comment_author',
|
||||||
'comment_timestamp',
|
'timestamp' => 'comment_timestamp',
|
||||||
'comment_type',
|
'type' => 'comment_type',
|
||||||
'comment_is_persistent',
|
'persistent' => 'comment_is_persistent',
|
||||||
'comment_expiration_timestamp',
|
'expiration' => 'comment_expiration_timestamp',
|
||||||
'host_name' => 'service_host_name',
|
'host',
|
||||||
'service_name'
|
'service'
|
||||||
)
|
)
|
||||||
)->getQuery();
|
)->getQuery();
|
||||||
|
|
||||||
@ -336,11 +336,10 @@ class Monitoring_ListController extends Controller
|
|||||||
|
|
||||||
$this->setupSortControl(
|
$this->setupSortControl(
|
||||||
array(
|
array(
|
||||||
'comment_timestamp' => 'Comment Timestamp',
|
'timestamp' => 'Comment Timestamp',
|
||||||
'host_service' => 'Host and Service',
|
'host' => 'Host / Service',
|
||||||
'comment_id' => 'Comment Id',
|
'type' => 'Comment Type',
|
||||||
'comment_expires' => 'Expiration Timestamp',
|
'expiration' => 'Expiration',
|
||||||
'comment_type' => 'Comment Type'
|
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
$this->handleFormatRequest($query);
|
$this->handleFormatRequest($query);
|
||||||
|
@ -15,13 +15,11 @@ $cf = $this->getHelper('CommandForm');
|
|||||||
|
|
||||||
foreach ($comments as $comment):
|
foreach ($comments as $comment):
|
||||||
|
|
||||||
$objectType = (int) $comment->comment_objecttype_id === 1 ? 'host' : 'service';
|
|
||||||
|
|
||||||
?>
|
?>
|
||||||
<tr>
|
<tr>
|
||||||
<td style="width: 5em; text-align: center;">
|
<td style="width: 5em; text-align: center;">
|
||||||
<?php
|
<?php
|
||||||
switch ($comment->comment_type) {
|
switch ($comment->type) {
|
||||||
case 'flapping':
|
case 'flapping':
|
||||||
$icon = 'flapping';
|
$icon = 'flapping';
|
||||||
$tooltip = 'Comment was caused by a flapping host or service.';
|
$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->icon($icon . '.png', $tooltip) ?><br />
|
||||||
<?= $this->timeSince($comment->comment_timestamp) ?>
|
<?= $this->timeSince($comment->timestamp) ?>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<?php if ($objectType === 'service'): ?><?= $this->icon('service.png', 'Service comment') ?> <?= $this->qlink(
|
<?php if ($comment->objecttype === 'service'): ?><?= $this->icon('service.png', 'Service comment') ?> <?= $this->qlink(
|
||||||
$comment->service_name,
|
$comment->service,
|
||||||
'monitoring/show/service',
|
'monitoring/show/service',
|
||||||
array(
|
array(
|
||||||
'host' => $comment->host_name,
|
'host' => $comment->host,
|
||||||
'service' => $comment->service_name,
|
'service' => $comment->service,
|
||||||
)
|
)
|
||||||
) ?> on<?php else: ?><?= $this->icon('host.png', 'Host comment') ?> <?php endif ?> <?= $this->qlink(
|
) ?> on<?php else: ?><?= $this->icon('host.png', 'Host comment') ?> <?php endif ?> <?= $this->qlink(
|
||||||
$comment->host_name,
|
$comment->host,
|
||||||
'monitoring/show/host',
|
'monitoring/show/host',
|
||||||
array(
|
array(
|
||||||
'host' => $comment->host_name
|
'host' => $comment->host
|
||||||
)
|
)
|
||||||
) ?> by <strong><?= $this->escape($comment->comment_author) ?></strong><br />
|
) ?> by <strong><?= $this->escape($comment->author) ?></strong><br />
|
||||||
<p><?= $this->escape($comment->comment_data) ?></p>
|
<p><?= $this->escape($comment->comment) ?></p>
|
||||||
<?php if ($comment->comment_is_persistent): ?>Comment is persistent<br /><?php endif ?>
|
<?php if ($comment->persistent): ?>Comment is persistent<br /><?php endif ?>
|
||||||
<b>Expires: </b> <?=
|
<b>Expires: </b> <?=
|
||||||
($comment->comment_expiration_timestamp) ?
|
($comment->expiration) ?
|
||||||
$this->timeUnless($comment->comment_expiration_timestamp) :
|
$this->timeUnless($comment->expiration) :
|
||||||
'Never'
|
'Never'
|
||||||
?>
|
?>
|
||||||
</td>
|
</td>
|
||||||
@ -68,12 +66,12 @@ foreach ($comments as $comment):
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
$data = array(
|
$data = array(
|
||||||
'commentid' => $comment->comment_id,
|
'commentid' => $comment->id,
|
||||||
'host' => $comment->host_name
|
'host' => $comment->host
|
||||||
);
|
);
|
||||||
|
|
||||||
if ($objectType === 'service') {
|
if ($comment->objecttype === 'service') {
|
||||||
$data['service'] = $comment->service_name;
|
$data['service'] = $comment->service;
|
||||||
}
|
}
|
||||||
|
|
||||||
echo $cf->iconSubmitForm(
|
echo $cf->iconSubmitForm(
|
||||||
|
@ -14,11 +14,11 @@ foreach ($object->comments as $comment) {
|
|||||||
$text = $this->tickets ? preg_replace_callback(
|
$text = $this->tickets ? preg_replace_callback(
|
||||||
$this->tickets->getPattern(),
|
$this->tickets->getPattern(),
|
||||||
array($this->tickets, 'createLink'),
|
array($this->tickets, 'createLink'),
|
||||||
$this->escape($comment->comment_data)
|
$this->escape($comment->comment)
|
||||||
) : $this->escape($comment->comment_data);
|
) : $this->escape($comment->comment);
|
||||||
|
|
||||||
$deleteData = $data;
|
$deleteData = $data;
|
||||||
$deleteData['commentid'] = $object->comment_internal_id;
|
$deleteData['commentid'] = $comment->id;
|
||||||
|
|
||||||
$iconForm = $cf->iconSubmitForm(
|
$iconForm = $cf->iconSubmitForm(
|
||||||
'img/icons/remove_petrol.png',
|
'img/icons/remove_petrol.png',
|
||||||
@ -31,9 +31,9 @@ foreach ($object->comments as $comment) {
|
|||||||
$list[] = sprintf(
|
$list[] = sprintf(
|
||||||
"<br />%s [%s] %s (%s): %s\n",
|
"<br />%s [%s] %s (%s): %s\n",
|
||||||
$iconForm,
|
$iconForm,
|
||||||
$this->escape($comment->comment_author),
|
$this->escape($comment->author),
|
||||||
$this->timeSince($comment->comment_timestamp),
|
$this->timeSince($comment->timestamp),
|
||||||
$comment->comment_type,
|
$comment->type,
|
||||||
$text
|
$text
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -36,23 +36,20 @@ class CommentQuery extends IdoQuery
|
|||||||
{
|
{
|
||||||
protected $columnMap = array(
|
protected $columnMap = array(
|
||||||
'comments' => array(
|
'comments' => array(
|
||||||
'comment_objecttype_id' => 'co.objecttype_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_id' => 'cm.internal_comment_id',
|
|
||||||
'comment_internal_id' => 'cm.internal_comment_id',
|
'comment_internal_id' => 'cm.internal_comment_id',
|
||||||
'comment_data' => 'cm.comment_data',
|
'comment_data' => 'cm.comment_data',
|
||||||
'comment_author' => 'cm.author_name COLLATE latin1_general_ci',
|
'comment_author' => 'cm.author_name COLLATE latin1_general_ci',
|
||||||
'comment_timestamp' => 'UNIX_TIMESTAMP(cm.comment_time)',
|
'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_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_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(
|
'hosts' => array(
|
||||||
'host_name' => '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' => 'ho.name1 COLLATE latin1_general_ci',
|
'host' => 'CASE WHEN ho.name1 IS NULL THEN so.name1 ELSE ho.name1 END COLLATE latin1_general_ci',
|
||||||
|
|
||||||
),
|
),
|
||||||
'services' => array(
|
'services' => array(
|
||||||
'service_host_name' => 'so.name1 COLLATE latin1_general_ci',
|
|
||||||
'service' => 'so.name2 COLLATE latin1_general_ci',
|
'service' => 'so.name2 COLLATE latin1_general_ci',
|
||||||
'service_name' => 'so.name2 COLLATE latin1_general_ci',
|
'service_name' => 'so.name2 COLLATE latin1_general_ci',
|
||||||
'service_description' => 'so.name2 COLLATE latin1_general_ci',
|
'service_description' => 'so.name2 COLLATE latin1_general_ci',
|
||||||
@ -66,32 +63,35 @@ class CommentQuery extends IdoQuery
|
|||||||
array()
|
array()
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/*
|
||||||
$this->baseQuery->join(
|
$this->baseQuery->join(
|
||||||
array(
|
array(
|
||||||
'co' => $this->prefix . 'objects'
|
'co' => $this->prefix . 'objects'
|
||||||
),
|
),
|
||||||
'cm.object_id = co.' . $this->object_id . ' AND co.is_active = 1'
|
'cm.object_id = co.' . $this->object_id . ' AND co.is_active = 1'
|
||||||
);
|
);*/
|
||||||
|
|
||||||
$this->joinedVirtualTables = array('comments' => true);
|
$this->joinedVirtualTables = array('comments' => true);
|
||||||
|
$this->joinVirtualTable('hosts');
|
||||||
|
$this->joinVirtualTable('services');
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function joinHosts()
|
protected function joinHosts()
|
||||||
{
|
{
|
||||||
$this->conflictsWithVirtualTable('services');
|
// $this->conflictsWithVirtualTable('services');
|
||||||
$this->baseQuery->join(
|
$this->baseQuery->joinLeft(
|
||||||
array('ho' => $this->prefix . 'objects'),
|
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()
|
array()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function joinServices()
|
protected function joinServices()
|
||||||
{
|
{
|
||||||
$this->conflictsWithVirtualTable('hosts');
|
// $this->conflictsWithVirtualTable('hosts');
|
||||||
$this->baseQuery->joinLeft(
|
$this->baseQuery->joinLeft(
|
||||||
array('so' => $this->prefix . 'objects'),
|
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()
|
array()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -42,8 +42,8 @@ class Comment extends DataView
|
|||||||
public function getColumns()
|
public function getColumns()
|
||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
'comment_objecttype_id',
|
'comment_objecttype',
|
||||||
'comment_id',
|
'comment_internal_id',
|
||||||
'comment_data',
|
'comment_data',
|
||||||
'comment_author',
|
'comment_author',
|
||||||
'comment_timestamp',
|
'comment_timestamp',
|
||||||
@ -51,10 +51,7 @@ class Comment extends DataView
|
|||||||
'comment_is_persistent',
|
'comment_is_persistent',
|
||||||
'comment_expiration_timestamp',
|
'comment_expiration_timestamp',
|
||||||
'host_name',
|
'host_name',
|
||||||
'service_host_name',
|
'service_description',
|
||||||
'service_name',
|
|
||||||
'host',
|
|
||||||
'service'
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -67,21 +64,15 @@ class Comment extends DataView
|
|||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
'comment_timestamp' => array(
|
'comment_timestamp' => array(
|
||||||
'order' => self::SORT_DESC
|
'order' => self::SORT_DESC
|
||||||
),
|
),
|
||||||
'host_service' => array(
|
'host_name' => array(
|
||||||
'columns' => array(
|
'columns' => array(
|
||||||
'host_name',
|
'host_name',
|
||||||
'service_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
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,11 +14,8 @@ use Icinga\Web\Request;
|
|||||||
|
|
||||||
abstract class AbstractObject
|
abstract class AbstractObject
|
||||||
{
|
{
|
||||||
const TYPE_HOST = 1;
|
public $type;
|
||||||
const TYPE_SERVICE = 2;
|
public $prefix;
|
||||||
|
|
||||||
public $type = self::TYPE_HOST;
|
|
||||||
public $prefix = 'host_';
|
|
||||||
|
|
||||||
public $comments = array();
|
public $comments = array();
|
||||||
public $downtimes = array();
|
public $downtimes = array();
|
||||||
@ -44,33 +41,20 @@ abstract class AbstractObject
|
|||||||
{
|
{
|
||||||
// WTF???
|
// WTF???
|
||||||
$query = Comment::fromParams(array('backend' => null), array(
|
$query = Comment::fromParams(array('backend' => null), array(
|
||||||
'comment_internal_id',
|
'id' => 'comment_internal_id',
|
||||||
'comment_timestamp',
|
'timestamp' => 'comment_timestamp',
|
||||||
'comment_author',
|
'author' => 'comment_author',
|
||||||
'comment_data',
|
'comment' => 'comment_data',
|
||||||
'comment_type',
|
'type' => 'comment_type',
|
||||||
))->getQuery();
|
))->getQuery();
|
||||||
$query->where('comment_type', array('comment', 'ack'));
|
$query->where('comment_type', array('comment', 'ack'));
|
||||||
$query->where('comment_objecttype_id', $this->type);
|
$query->where('comment_objecttype', $this->type);
|
||||||
$this->applyObjectFilter($query);
|
$query->where('host_name', $this->host_name);
|
||||||
|
if ($this->type === 'service') {
|
||||||
|
$query->where('service_description', $this->service_description);
|
||||||
|
}
|
||||||
$this->comments = $query->fetchAll();
|
$this->comments = $query->fetchAll();
|
||||||
return $this;
|
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()
|
public function fetchDowntimes()
|
||||||
@ -124,7 +108,7 @@ abstract class AbstractObject
|
|||||||
)
|
)
|
||||||
)->getQuery();
|
)->getQuery();
|
||||||
|
|
||||||
if ($this->type === self::TYPE_HOST) {
|
if ($this->type === 'host') {
|
||||||
$query->where('host_name', $this->host_name)
|
$query->where('host_name', $this->host_name)
|
||||||
->where('object_type', 'host');
|
->where('object_type', 'host');
|
||||||
} else {
|
} else {
|
||||||
|
@ -7,10 +7,9 @@ use Icinga\Data\Db\Query;
|
|||||||
|
|
||||||
class Host extends AbstractObject
|
class Host extends AbstractObject
|
||||||
{
|
{
|
||||||
|
public $typ = 'host';
|
||||||
public $type = self::TYPE_HOST;
|
public $prefix = 'host_';
|
||||||
public $prefix = 'host_';
|
private $view = null;
|
||||||
private $view = null;
|
|
||||||
|
|
||||||
protected function applyObjectFilter(Query $query)
|
protected function applyObjectFilter(Query $query)
|
||||||
{
|
{
|
||||||
|
@ -7,10 +7,9 @@ use Icinga\Data\Db\Query;
|
|||||||
|
|
||||||
class Service extends AbstractObject
|
class Service extends AbstractObject
|
||||||
{
|
{
|
||||||
|
public $type = 'service';
|
||||||
public $type = self::TYPE_SERVICE;
|
public $prefix = 'service_';
|
||||||
public $prefix = 'service_';
|
private $view = null;
|
||||||
private $view = null;
|
|
||||||
|
|
||||||
protected function applyObjectFilter(Query $query)
|
protected function applyObjectFilter(Query $query)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user