Comment overview: Basic implementation

refs #4714
This commit is contained in:
Marius Hein 2013-09-26 17:02:56 +02:00 committed by Eric Lippmann
parent c9e3a1ed5d
commit 1eef471bc2
7 changed files with 298 additions and 46 deletions

View File

@ -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"

View File

@ -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
*

View File

@ -0,0 +1,109 @@
<?php
$dateHelper = $this->getHelper('DateFormat');
?>
<?= $this->tabs->render($this); ?>
<?php
$viewHelper = $this->getHelper('MonitoringState');
?>
<div data-icinga-component="app/mainDetailGrid">
<?= $this->sortControl->render($this); ?>
<?= $this->paginationControl($comments, null, null, array('preserve' => $this->preserve)); ?>
<table class="table table-condensed">
<thead>
<tr>
<th colspan="2">Comment Id</th>
<th>Type</th>
<th>Host</th>
<th>Service</th>
<th>Entry Time</th>
<th>Author</th>
<th>Comment</th>
<th>Persistent</th>
<th colspan="2">Expires</th>
</tr>
</thead>
<tbody>
<?php foreach ($comments as $comment): ?>
<?php
$objectType = ($comment->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
)
);
?>
<tr <?= ($this->activeRowHref === $detailLink) ? 'class="active"' : ''; ?>>
<td>
<a class="hidden" href="<?= $detailLink; ?>"></a>
<?php if ($comment->comment_objecttype_id === '1'): ?>
{{{ICON_HOST}}}
<?php elseif ($comment->comment_objecttype_id === '2'): ?>
{{{ICON_SERVICE}}}
<?php endif; ?>
</td>
<td>
<?= $comment->comment_id; ?>
</td>
<td>
<?= $comment->comment_type; ?>
</td>
<td>
<a href="<?= $hostLink ?>">
<?= $comment->host_name; ?>
</a>
</td>
<td>
<?php if ($comment->service_name): ?>
<a href="<?= $detailLink ?>">
<?= $comment->service_name ?>
</a>
<?php else: ?>
&nbsp;
<?php endif; ?>
</td>
<td>
<?= $dateHelper->formatDateTime($comment->comment_timestamp); ?>
</td>
<td>
<?= $comment->comment_author; ?>
</td>
<td>
<?= $comment->comment_data; ?>
</td>
<td>
<?= ($comment->comment_is_persistent === '1') ? 'Yes' : 'No'; ?>
</td>
<td>
<?=
($comment->comment_expiration_timestamp) ?
$dateHelper->formatDateTime($comment->comment_expiration_timestamp) :
'&nbsp;';
?>
</td>
<td>
COMMAND!!!DELETE_COMMENT
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>

View File

@ -1,23 +1,61 @@
<?php
// {{{ICINGA_LICENSE_HEADER}}}
/**
* This file is part of Icinga 2 Web.
*
* Icinga 2 Web - Head for multiple monitoring backends.
* Copyright (C) 2013 Icinga Development Team
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
*
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* @copyright 2013 Icinga Development Team <info@icinga.org>
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
* @author Icinga Development Team <info@icinga.org>
*/
// {{{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()
);
}

View File

@ -0,0 +1,84 @@
<?php
// {{{ICINGA_LICENSE_HEADER}}}
/**
* This file is part of Icinga 2 Web.
*
* Icinga 2 Web - Head for multiple monitoring backends.
* Copyright (C) 2013 Icinga Development Team
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
*
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* @copyright 2013 Icinga Development Team <info@icinga.org>
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
* @author Icinga Development Team <info@icinga.org>
*/
// {{{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
)
);
}
}

View File

@ -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;
}

View File

@ -1,26 +0,0 @@
<?php
namespace Icinga\Module\Monitoring\View;
class CommentView extends AbstractView
{
protected $query;
protected $availableColumns = array(
'comment_data',
'comment_author',
'comment_timestamp',
'comment_type',
'host_name',
'service_host_name',
'service_description',
);
protected $specialFilters = array();
protected $sortDefaults = array(
'comment_timestamp' => array(
'default_dir' => self::SORT_DESC
)
);
}