From 63fd074a4f27be575dfc83d6baf38318afc3b4b6 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Sun, 9 Mar 2014 19:29:23 +0100 Subject: [PATCH] Comments are still messy, clean up and fix adding / removing them --- .../controllers/ListController.php | 29 +++++++------ .../views/scripts/list/comments.phtml | 36 ++++++++-------- .../scripts/show/components/comments.phtml | 12 +++--- .../Backend/Ido/Query/CommentQuery.php | 26 ++++++------ .../library/Monitoring/DataView/Comment.php | 23 ++++------ .../Monitoring/Object/AbstractObject.php | 42 ++++++------------- .../library/Monitoring/Object/Host.php | 7 ++-- .../library/Monitoring/Object/Service.php | 7 ++-- 8 files changed, 76 insertions(+), 106 deletions(-) diff --git a/modules/monitoring/application/controllers/ListController.php b/modules/monitoring/application/controllers/ListController.php index 14b2d1cda..5104bcc4a 100644 --- a/modules/monitoring/application/controllers/ListController.php +++ b/modules/monitoring/application/controllers/ListController.php @@ -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); diff --git a/modules/monitoring/application/views/scripts/list/comments.phtml b/modules/monitoring/application/views/scripts/list/comments.phtml index 6bf109cab..70120def4 100644 --- a/modules/monitoring/application/views/scripts/list/comments.phtml +++ b/modules/monitoring/application/views/scripts/list/comments.phtml @@ -15,13 +15,11 @@ $cf = $this->getHelper('CommandForm'); foreach ($comments as $comment): - $objectType = (int) $comment->comment_objecttype_id === 1 ? 'host' : 'service'; - ?> 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): } ?> icon($icon . '.png', $tooltip) ?>
- timeSince($comment->comment_timestamp) ?> + timeSince($comment->timestamp) ?> - icon('service.png', 'Service comment') ?> qlink( - $comment->service_name, + objecttype === 'service'): ?>icon('service.png', 'Service comment') ?> qlink( + $comment->service, 'monitoring/show/service', array( - 'host' => $comment->host_name, - 'service' => $comment->service_name, + 'host' => $comment->host, + 'service' => $comment->service, ) ) ?> onicon('host.png', 'Host comment') ?> qlink( - $comment->host_name, + $comment->host, 'monitoring/show/host', array( - 'host' => $comment->host_name + 'host' => $comment->host ) - ) ?> by escape($comment->comment_author) ?>
-

escape($comment->comment_data) ?>

- comment_is_persistent): ?>Comment is persistent
+ ) ?> by escape($comment->author) ?>
+

escape($comment->comment) ?>

+ persistent): ?>Comment is persistent
Expires: comment_expiration_timestamp) ? - $this->timeUnless($comment->comment_expiration_timestamp) : + ($comment->expiration) ? + $this->timeUnless($comment->expiration) : 'Never' ?> @@ -68,12 +66,12 @@ foreach ($comments as $comment): $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( diff --git a/modules/monitoring/application/views/scripts/show/components/comments.phtml b/modules/monitoring/application/views/scripts/show/components/comments.phtml index 22cf962ce..454361691 100644 --- a/modules/monitoring/application/views/scripts/show/components/comments.phtml +++ b/modules/monitoring/application/views/scripts/show/components/comments.phtml @@ -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( "
%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 ); } diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/CommentQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/CommentQuery.php index 64077f9d4..b2d477741 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/CommentQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/CommentQuery.php @@ -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() ); } diff --git a/modules/monitoring/library/Monitoring/DataView/Comment.php b/modules/monitoring/library/Monitoring/DataView/Comment.php index cb20d2222..330f8525f 100644 --- a/modules/monitoring/library/Monitoring/DataView/Comment.php +++ b/modules/monitoring/library/Monitoring/DataView/Comment.php @@ -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 - ) ); } } diff --git a/modules/monitoring/library/Monitoring/Object/AbstractObject.php b/modules/monitoring/library/Monitoring/Object/AbstractObject.php index f48f1cb12..36c10c77b 100644 --- a/modules/monitoring/library/Monitoring/Object/AbstractObject.php +++ b/modules/monitoring/library/Monitoring/Object/AbstractObject.php @@ -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 { diff --git a/modules/monitoring/library/Monitoring/Object/Host.php b/modules/monitoring/library/Monitoring/Object/Host.php index ed1372fa7..422e9707e 100644 --- a/modules/monitoring/library/Monitoring/Object/Host.php +++ b/modules/monitoring/library/Monitoring/Object/Host.php @@ -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) { diff --git a/modules/monitoring/library/Monitoring/Object/Service.php b/modules/monitoring/library/Monitoring/Object/Service.php index f072c62a9..2a661f7b7 100644 --- a/modules/monitoring/library/Monitoring/Object/Service.php +++ b/modules/monitoring/library/Monitoring/Object/Service.php @@ -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) {