[icinga-checkins] icinga.org: icingaweb2-module-elasticsearch/master: ElasticsearchConfigForm: Add missing resource options

git at icinga.org git at icinga.org
Mon May 9 15:01:25 CEST 2016


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

Author: Johannes Meyer <johannes.meyer at netways.de>
Date:   Mon May  9 14:59:25 2016 +0200

ElasticsearchConfigForm: Add missing resource options

refs #11520

---

 .../forms/Config/ElasticsearchConfigForm.php       |   79 +++++++++++++-------
 1 file changed, 51 insertions(+), 28 deletions(-)

diff --git a/application/forms/Config/ElasticsearchConfigForm.php b/application/forms/Config/ElasticsearchConfigForm.php
index 6fbf365..faa50af 100644
--- a/application/forms/Config/ElasticsearchConfigForm.php
+++ b/application/forms/Config/ElasticsearchConfigForm.php
@@ -3,7 +3,7 @@
 
 namespace Icinga\Module\Elasticsearch\Forms\Config;
 
-use Icinga\Web\Notification;
+use Icinga\Application\Config;
 use Icinga\Forms\ConfigForm;
 
 class ElasticsearchConfigForm extends ConfigForm
@@ -18,44 +18,51 @@ class ElasticsearchConfigForm extends ConfigForm
     }
 
     /**
-     * @see Form::onSuccess()
-     */
-    public function onSuccess()
-    {
-        $this->config->setSection('elasticsearch', $this->getValues());
-
-        if ($this->save()) {
-            Notification::success($this->translate('New Elasticsearch configuration has successfully been stored'));
-        } else {
-            return false;
-        }
-    }
-
-    /**
-     * @see Form::onRequest()
-     */
-    public function onRequest()
-    {
-        $this->populate($this->config->getSection('elasticsearch')->toArray());
-    }
-
-    /**
-     * @see Form::createElements()
+     * {@inheritdoc}
      */
     public function createElements(array $formData)
     {
         $this->addElement(
             'text',
-            'url',
+            'elasticsearch_url',
             array(
-                'value'         => 'http://elasticsearch:9200',
+                'allowEmpty'    => true,
+                'placeholder'   => 'http://localhost:9200',
                 'label'         => $this->translate('Elasticsearch URL'),
-                'description'   => $this->translate('URL to your Elasticsearch installation.')
+                'description'   => $this->translate('URL to your Elasticsearch cluster')
             )
         );
         $this->addElement(
             'text',
-            'index_pattern',
+            'elasticsearch_username',
+            array(
+                'allowEmpty'    => true,
+                'label'         => $this->translate('Username'),
+                'description'   => $this->translate('The user name to use for authentication')
+            )
+        );
+        $this->addElement(
+            'password',
+            'elasticsearch_password',
+            array(
+                'renderPassword'    => true,
+                'allowEmpty'        => true,
+                'label'             => $this->translate('Password'),
+                'description'       => $this->translate('The password to use for authentication')
+            )
+        );
+        $this->addElement(
+            'text',
+            'elasticsearch_certificate_path',
+            array(
+                'allowEmpty'    => true,
+                'label'         => $this->translate('Certificate Path'),
+                'description'   => $this->translate('The path to the Elasticsearch\'s certificate if HTTPS is used')
+            )
+        );
+        $this->addElement(
+            'text',
+            'elasticsearch_index_pattern',
             array(
                 'value'         => 'logstash-*',
                 'label'         => $this->translate('Logstash index pattern'),
@@ -66,4 +73,20 @@ class ElasticsearchConfigForm extends ConfigForm
             )
         );
     }
+
+    /**
+     * {@inheritdoc}
+     */
+    protected function writeConfig(Config $config)
+    {
+        // TODO: Remove this once #11743 is fixed
+        $section = $config->getSection('elasticsearch');
+        foreach ($section->toArray() as $key => $value) {
+            if ($value === null) {
+                unset($section->{$key});
+            }
+        }
+
+        parent::writeConfig($config);
+    }
 }



More information about the icinga-checkins mailing list