From 73eced1b119bda7950e41e9c7965c0259057c116 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Mon, 7 Mar 2016 01:10:56 +0100 Subject: [PATCH] KickstartForm: catch errors gracefully... ...and provide better documentation --- application/forms/KickstartForm.php | 41 ++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 7 deletions(-) diff --git a/application/forms/KickstartForm.php b/application/forms/KickstartForm.php index 20bc8688..d411fc32 100644 --- a/application/forms/KickstartForm.php +++ b/application/forms/KickstartForm.php @@ -2,6 +2,7 @@ namespace Icinga\Module\Director\Forms; +use Exception; use Icinga\Module\Director\KickstartHelper; use Icinga\Module\Director\Web\Form\QuickForm; @@ -20,38 +21,64 @@ class KickstartForm extends QuickForm $this->addElement('text', 'endpoint', array( 'label' => $this->translate('Endpoint Name'), + 'description' => $this->translate( + 'This is the name of the Endpoint object (and certificate name) you' + . ' created for your ApiListener object. In case you are unsure what' + . ' this means please make sure to read the documentation first' + ), 'required' => true, )); $this->addElement('text', 'host', array( 'label' => $this->translate('Icinga Host'), - 'description' => $this->translate('IP address / hostname of remote node'), - 'required' => true, + 'description' => $this->translate( + 'IP address / hostname of your Icinga node. Please note that this' + . ' information will only be used for the very first connection to' + . ' your Icinga instance. The Director then relies on a correctly' + . ' configured Endpoint object. Correctly configures means that either' + . ' it\'s name is resolvable or that it\'s host property contains' + . ' either an IP address or a resolvable host name. Your Director must' + . ' be able to reach this endpoint' + ), + 'required' => false, )); $this->addElement('text', 'port', array( 'label' => $this->translate('Port'), 'value' => '5665', - 'description' => $this->translate('The port your '), - 'required' => true, + 'description' => $this->translate( + 'The port you are going to use. The default port 5665 will be used' + . ' if none is set' + ), + 'required' => false, )); $this->addElement('text', 'username', array( 'label' => $this->translate('API user'), + 'description' => $this->translate( + 'Your Icinga 2 API username' + ), 'required' => true, )); $this->addElement('password', 'password', array( 'label' => $this->translate('Password'), + 'description' => $this->translate( + 'The corresponding password' + ), 'required' => true, )); } public function onSuccess() { - $kickstart = new KickstartHelper($this->db); - $kickstart->setConfig($this->getValues())->run(); - parent::onSuccess(); + try { + $kickstart = new KickstartHelper($this->db); + $kickstart->setConfig($this->getValues())->run(); + parent::onSuccess(); + } catch (Exception $e) { + $this->getElement('endpoint')->addError($e->getMessage()); + } } public function setDb($db)