[icinga-checkins] icinga.org: icingaweb2-module-elasticsearch/master: Place search in its own controller

git at icinga.org git at icinga.org
Thu Jun 30 17:08:11 CEST 2016


Module: icingaweb2-module-elasticsearch
Branch: master
Commit: 3d47308a028a2c47d21e4fd65e17ec69f2118555
URL:    https://git.icinga.org/?p=icingaweb2-module-elasticsearch.git;a=commit;h=3d47308a028a2c47d21e4fd65e17ec69f2118555

Author: Markus Frosch <lazyfrosch at icinga.org>
Date:   Thu Jun 30 15:32:23 2016 +0200

Place search in its own controller

---

 application/controllers/EventController.php        |   76 --------------------
 application/controllers/SearchController.php       |   57 +++++++++++++++
 application/views/scripts/events/show.phtml        |    2 +
 .../{event/search.phtml => search/index.phtml}     |    2 +-
 configuration.php                                  |    5 +-
 library/Elasticsearch/Controller.php               |    5 ++
 6 files changed, 68 insertions(+), 79 deletions(-)

diff --git a/application/controllers/EventController.php b/application/controllers/EventController.php
deleted file mode 100644
index db4f1ed..0000000
--- a/application/controllers/EventController.php
+++ /dev/null
@@ -1,76 +0,0 @@
-<?php
-/* Elasticsearch Module | (c) 2016 Icinga Development Team | GPLv2+ */
-
-namespace Icinga\Module\Elasticsearch\Controllers;
-
-use Icinga\Exception\IcingaException;
-use Icinga\Exception\NotImplementedError;
-
-use Icinga\Module\Elasticsearch\Controller;
-
-use Icinga\Module\Elasticsearch\EventBackend;
-use Icinga\Module\Elasticsearch\Event;
-
-use Icinga\Module\Monitoring\Backend;
-//use Icinga\Module\Monitoring\Object\Host;
-//use Icinga\Module\Monitoring\Object\Service;
-
-class EventController extends Controller
-{
-    public function indexAction()
-    {
-        $this->redirectNow('elasticsearch/event/search');
-    }
-
-    public function searchAction()
-    {
-        $this->assertPermission('module/elasticsearch/search');
-
-        $repository = EventBackend::fromConfig();
-
-        if ($type = $this->getParam('type')) {
-            $repository->setBaseTable($type);
-        }
-
-        $query = $repository->select();
-
-        $sort_columns = array();
-        foreach ($query->getColumns() as $value) {
-            $sort_columns[$value] = $value;
-        }
-        $this->setupFilterControl($query, null, null, array('fields', 'refresh'));
-        $this->setupLimitControl(100);
-        $this->setupSortControl($sort_columns, $query, array('@timestamp' => 'desc'));
-        $this->setupPaginationControl($query, 100);
-        $this->setupFieldSelectorControl($query);
-        $this->setupAutoRefresherControl();
-
-        $this->getTabs()->add('search', array(
-            'title' => $this->translate('Events'),
-            'url'   => $this->view->url()
-        ))->activate(('search'));;
-
-        /* TODO: adapt to FilterEditor
-        $this->view->show_ack = $this->_getParam('show_ack', 0);
-
-        $this->view->warning = $this->_getParam('warning');
-        if ($this->view->warning) {
-            $search->setIcingaWarningQuery($this->view->warning);
-        }
-        $this->view->critical = $this->_getParam('critical');
-        if ($this->view->critical) {
-            $search->setIcingaCriticalQuery($this->view->critical);
-        }
-        */
-
-        // TODO: reimplement
-        //if (! $this->view->show_ack)
-        //    $search->setWithoutAck(true);
-
-        $this->view->events = $query->fetchAll();
-
-        // TODO: reimplement
-        //$this->view->warnings = $search->getIcingaWarningCount();
-        //$this->view->criticals = $search->getIcingaCriticalCount();
-    }
-}
diff --git a/application/controllers/SearchController.php b/application/controllers/SearchController.php
new file mode 100644
index 0000000..e67aec6
--- /dev/null
+++ b/application/controllers/SearchController.php
@@ -0,0 +1,57 @@
+<?php
+/* Elasticsearch Module | (c) 2016 Icinga Development Team | GPLv2+ */
+
+namespace Icinga\Module\Elasticsearch\Controllers;
+
+use Icinga\Exception\IcingaException;
+use Icinga\Module\Elasticsearch\Controller;
+use Icinga\Module\Elasticsearch\Event;
+use Icinga\Module\Elasticsearch\EventBackend;
+
+class SearchController extends Controller
+{
+    public function indexAction()
+    {
+        $this->assertPermission('module/elasticsearch/search');
+        
+        $this->createTabs('search', 'search');
+
+        $repository = EventBackend::fromConfig();
+
+        $query = $repository->select();
+
+        $sort_columns = array();
+        foreach ($query->getColumns() as $value) {
+            $sort_columns[$value] = $value;
+        }
+        $this->setupFilterControl($query, null, null, array('fields', 'refresh'));
+        $this->setupLimitControl(100);
+        $this->setupSortControl($sort_columns, $query, array('@timestamp' => 'desc'));
+        $this->setupPaginationControl($query, 100);
+        $this->setupFieldSelectorControl($query);
+        $this->setupAutoRefresherControl();
+
+        $this->view->eventUrl = $this->view->url('elasticsearch/search/show');
+
+        $this->view->events = $query;
+    }
+
+    public function showAction()
+    {
+        $this->assertPermission('module/elasticsearch/search');
+ 
+        $this->createTabs('event', 'show');
+
+        $id = $this->getParam('id');
+        if ($id === null) {
+            throw new IcingaException('You need to specify the event id!');
+        }
+
+        $repository = EventBackend::fromConfig();
+        $query = $repository->select();
+
+        $this->view->event = Event::fromRepository($query, $id);
+        
+        $this->render('events/show', null, true);
+    }
+}
diff --git a/application/views/scripts/events/show.phtml b/application/views/scripts/events/show.phtml
index 7ce9dcc..619513a 100644
--- a/application/views/scripts/events/show.phtml
+++ b/application/views/scripts/events/show.phtml
@@ -12,10 +12,12 @@
     ?>
 
         <table class="event_detail">
+            <?php if ($this->eventType !== null): ?>
             <tr>
                 <th><?= $this->translate('Event type') ?></th>
                 <td><?= $this->qlink($this->eventType->getLabel(), 'elasticsearch/events', array('type' => $this->eventType->getName())) ?></td>
             </tr>
+            <?php endif; ?>
             <tr>
                 <th><?= $this->translate('Elasticsearch index') ?></th>
                 <td><?= $this->escape($this->event->getIndex()) ?></td>
diff --git a/application/views/scripts/event/search.phtml b/application/views/scripts/search/index.phtml
similarity index 91%
rename from application/views/scripts/event/search.phtml
rename to application/views/scripts/search/index.phtml
index e6782c4..592b13f 100644
--- a/application/views/scripts/event/search.phtml
+++ b/application/views/scripts/search/index.phtml
@@ -15,7 +15,7 @@
     <?php if (property_exists($this, 'error')): ?>
         <h3><?= $this->error?></h3>
     <?php elseif (empty($this->events)): ?>
-        <p>No results found!</p>
+        <p><?= $this->translate('No events found!') ?></p>
     <?php else: ?>
         <?php $this->fields = $this->fieldSelector->getFields(); ?>
         <?= $this->render('event/partial/eventTable.phtml') ?>
diff --git a/configuration.php b/configuration.php
index 9a60a9f..1d22a5b 100644
--- a/configuration.php
+++ b/configuration.php
@@ -6,11 +6,12 @@ use Icinga\Application\Modules\Module;
 $this->providePermission('module/elasticsearch/search', $this->translate('Allow unrestricted access to query data in Elasticsearch'));
 
 $section = $this->menuSection('Elasticsearch')
-    ->setIcon('doc-text');
+    ->setIcon('doc-text')
+    ->setUrl('elasticsearch');
 
 $section->add(t('Event search'))
         ->setIcon('search')
-        ->setUrl('elasticsearch/event/search');
+        ->setUrl('elasticsearch/search');
 
 $this->provideConfigTab('elasticsearch', array(
     'title' => $this->translate('Configure Elasticsearch settings'),
diff --git a/library/Elasticsearch/Controller.php b/library/Elasticsearch/Controller.php
index e4a6dc0..f546e79 100644
--- a/library/Elasticsearch/Controller.php
+++ b/library/Elasticsearch/Controller.php
@@ -35,6 +35,11 @@ class Controller extends IcingaWebController
                     $active = 'overview';
                 }
                 break;
+            case 'search':
+                $tabs->add('search', array(
+                    'title' => $this->translate('Event search'),
+                ));
+                break;
             case 'events':
                 if ($active === 'create') {
                     $tabs->add('create', array(



More information about the icinga-checkins mailing list