From 1eef471bc23b2c645cd01b2d93aab5fe25d2cf46 Mon Sep 17 00:00:00 2001 From: Marius Hein Date: Thu, 26 Sep 2013 17:02:56 +0200 Subject: [PATCH] Comment overview: Basic implementation refs #4714 --- config/modules/monitoring/menu.ini | 13 ++- .../controllers/ListController.php | 32 +++++ .../views/scripts/list/comments.phtml | 109 ++++++++++++++++++ .../Backend/Ido/Query/CommentQuery.php | 67 +++++++++-- .../library/Monitoring/DataView/Comment.php | 84 ++++++++++++++ .../Monitoring/Object/AbstractObject.php | 13 ++- .../library/Monitoring/View/CommentView.php | 26 ----- 7 files changed, 298 insertions(+), 46 deletions(-) create mode 100644 modules/monitoring/application/views/scripts/list/comments.phtml create mode 100644 modules/monitoring/library/Monitoring/DataView/Comment.php delete mode 100644 modules/monitoring/library/Monitoring/View/CommentView.php diff --git a/config/modules/monitoring/menu.ini b/config/modules/monitoring/menu.ini index ff3aed3b7..04e5e7918 100755 --- a/config/modules/monitoring/menu.ini +++ b/config/modules/monitoring/menu.ini @@ -9,12 +9,13 @@ ;Changes.route = "/monitoring/list/services?sort=service_last_state_change" ;_1 = 1 ;Spacer after this section -Hosts = "/monitoring/list/hosts" -Services = "/monitoring/list/services" -Downtimes = "/monitoring/list/downtimes" -Notifications = "/monitoring/list/notifications" -Contacts = "/monitoring/list/contacts" -Contact Groups = "/monitoring/list/contactgroups" +Hosts = "/monitoring/list/hosts" +Services = "/monitoring/list/services" +Downtimes = "/monitoring/list/downtimes" +Notifications = "/monitoring/list/notifications" +Comments = "/monitoring/list/comments" +Contacts = "/monitoring/list/contacts" +Contact Groups = "/monitoring/list/contactgroups" ;Remove component as of #4583 since it's not working ;Summaries = "/monitoring/summary/group/by/hostgroup" diff --git a/modules/monitoring/application/controllers/ListController.php b/modules/monitoring/application/controllers/ListController.php index 5a4eaadb0..1cc61a2a9 100644 --- a/modules/monitoring/application/controllers/ListController.php +++ b/modules/monitoring/application/controllers/ListController.php @@ -45,6 +45,7 @@ use Icinga\Module\Monitoring\DataView\Downtime as DowntimeView; use Icinga\Module\Monitoring\DataView\Contact as ContactView; use Icinga\Module\Monitoring\DataView\Contactgroup as ContactgroupView; use Icinga\Module\Monitoring\DataView\HostAndServiceStatus as HostAndServiceStatusView; +use Icinga\Module\Monitoring\DataView\Comment as CommentView; class Monitoring_ListController extends ActionController { @@ -306,6 +307,37 @@ class Monitoring_ListController extends ActionController $this->handleFormatRequest($query); } + public function commentsAction() + { + $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_name' + ) + )->getQuery(); + + $this->view->comments = $query->paginate(); + + $this->setupSortControl( + array( + 'comment_timestamp' => 'Comment Timestamp', + 'host_service' => 'Host and Service', + 'comment_id' => 'Comment Id', + 'comment_expires' => 'Expiration Timestamp' + ) + ); + $this->handleFormatRequest($query); + } + /** * Handle the 'format' and 'view' parameter * diff --git a/modules/monitoring/application/views/scripts/list/comments.phtml b/modules/monitoring/application/views/scripts/list/comments.phtml new file mode 100644 index 000000000..e9bec93b7 --- /dev/null +++ b/modules/monitoring/application/views/scripts/list/comments.phtml @@ -0,0 +1,109 @@ +getHelper('DateFormat'); +?> +tabs->render($this); ?> + +getHelper('MonitoringState'); +?> + +
+ sortControl->render($this); ?> + paginationControl($comments, null, null, array('preserve' => $this->preserve)); ?> + + + + + + + + + + + + + + + + + + comment_objecttype_id === '1') ? 'host' : 'service'; + $objectName = ($objectType === 'host') ? $comment->host_name : $comment->service_name; + $hrefParameters = array( + $objectType => $objectName, + 'comment_id' => $comment->comment_id + ); + if ($objectType === 'service') { + $hrefParameters['host'] = $comment->host_name; + } + + $detailLink = $this->href( + 'monitoring/show/' . $objectType, + $hrefParameters + ); + + $hostLink = $this->href( + 'monitoring/show/host', + array( + 'host' => $comment->host_name + ) + ); + ?> + activeRowHref === $detailLink) ? 'class="active"' : ''; ?>> + + + + + + + + + + + + + + +
Comment IdTypeHostServiceEntry TimeAuthorCommentPersistentExpires
+ + comment_objecttype_id === '1'): ?> + {{{ICON_HOST}}} + comment_objecttype_id === '2'): ?> + {{{ICON_SERVICE}}} + + + comment_id; ?> + + comment_type; ?> + + + host_name; ?> + + + service_name): ?> + + service_name ?> + + +   + + + formatDateTime($comment->comment_timestamp); ?> + + comment_author; ?> + + comment_data; ?> + + comment_is_persistent === '1') ? 'Yes' : 'No'; ?> + + comment_expiration_timestamp) ? + $dateHelper->formatDateTime($comment->comment_expiration_timestamp) : + ' '; + ?> + + COMMAND!!!DELETE_COMMENT +
+ +
\ No newline at end of file diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/CommentQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/CommentQuery.php index a21dbc1e9..4a3c9d9b7 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/CommentQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/CommentQuery.php @@ -1,23 +1,61 @@ + * @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2 + * @author Icinga Development Team + */ +// {{{ICINGA_LICENSE_HEADER}}} namespace Icinga\Module\Monitoring\Backend\Ido\Query; +/** + * Query map for comments + */ class CommentQuery extends AbstractQuery { protected $columnMap = array( 'comments' => array( - 'comment_data' => 'cm.comment_data', - 'comment_author' => 'cm.author_name', - //'comment_timestamp' => 'UNIX_TIMESTAMP(cm.entry_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_objecttype_id' => 'co.objecttype_id', + 'comment_id' => 'cm.internal_comment_id', + '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' ), 'hosts' => array( - 'host_name' => 'ho.name1', + '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_description' => 'so.name2 COLLATE latin1_general_ci', + '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', ) ); @@ -28,6 +66,13 @@ class CommentQuery extends AbstractQuery 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); } @@ -35,16 +80,16 @@ class CommentQuery extends AbstractQuery { $this->baseQuery->join( array('ho' => $this->prefix . 'objects'), - 'cm.object_id = ho.' . $this->object_id . ' AND ho.is_active = 1 AND ho.objecttype_id = 1', + 'co.name1 = ho.name1 AND ho.is_active = 1 AND ho.objecttype_id = 1', array() ); } protected function joinServices() { - $this->baseQuery->join( + $this->baseQuery->joinLeft( array('so' => $this->prefix . 'objects'), - 'cm.object_id = so.' . $this->object_id . ' AND so.is_active = 1 AND so.objecttype_id = 2', + 'co.name1 = so.name1 AND co.name2 = so.name2 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 new file mode 100644 index 000000000..3ef879b4a --- /dev/null +++ b/modules/monitoring/library/Monitoring/DataView/Comment.php @@ -0,0 +1,84 @@ + + * @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2 + * @author Icinga Development Team + */ +// {{{ICINGA_LICENSE_HEADER}}} + +namespace Icinga\Module\Monitoring\DataView; + +/** + * View representation for comments + */ +class Comment extends DataView +{ + /** + * Retrieve columns provided by this view + * + * @return array + */ + public function getColumns() + { + return array( + 'comment_objecttype_id', + 'comment_id', + 'comment_data', + 'comment_author', + 'comment_timestamp', + 'comment_type', + 'comment_is_persistent', + 'comment_expiration_timestamp', + 'host_name', + 'service_name' + ); + } + + /** + * Retrieve default sorting rules for particular columns. These involve sort order and potential additional to sort + * + * @return array + */ + public function getSortRules() + { + return array( + 'comment_timestamp' => array( + 'order' => self::SORT_DESC + ), + 'host_service' => array( + 'columns' => array( + 'host_name', + 'service_name' + ), + '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 408a99029..fcc512884 100644 --- a/modules/monitoring/library/Monitoring/Object/AbstractObject.php +++ b/modules/monitoring/library/Monitoring/Object/AbstractObject.php @@ -29,8 +29,15 @@ abstract class AbstractObject public function __construct(Backend $backend, $name1, $name2 = null) { $this->backend = $backend; - $this->name1 = $name1; - $this->name2 = $name2; + $this->name1 = $name1; + $this->name2 = $name2; + + if ($name1 && $name2) { + $this->type = 2; + } elseif ($name1 && !$name2) { + $this->type = 1; + } + $this->properties = (array) $this->fetchObject(); } @@ -125,7 +132,7 @@ abstract class AbstractObject 'comment_author', 'comment_data', 'comment_type', - )) + ))->where('comment_objecttype_id', $this->type) )->fetchAll(); return $this; } diff --git a/modules/monitoring/library/Monitoring/View/CommentView.php b/modules/monitoring/library/Monitoring/View/CommentView.php deleted file mode 100644 index 3a87c6a76..000000000 --- a/modules/monitoring/library/Monitoring/View/CommentView.php +++ /dev/null @@ -1,26 +0,0 @@ - array( - 'default_dir' => self::SORT_DESC - ) - ); -}