[icinga-checkins] icinga.org: icingaweb2-module-director/feature/job-scheduling-11627: host/ agent: show a friendly error message...

git at icinga.org git at icinga.org
Tue May 3 10:04:59 CEST 2016


Module: icingaweb2-module-director
Branch: feature/job-scheduling-11627
Commit: fddd4488b568112858ba3670aac963755503e48b
URL:    https://git.icinga.org/?p=icingaweb2-module-director.git;a=commit;h=fddd4488b568112858ba3670aac963755503e48b

Author: Thomas Gelf <thomas at gelf.net>
Date:   Tue May  3 08:27:12 2016 +0200

host/agent: show a friendly error message...

...when the deployment endpoint is not reachable

---

 application/controllers/HostController.php |   27 +++++++++++++++++++++++++--
 application/views/scripts/host/agent.phtml |    8 ++++++--
 2 files changed, 31 insertions(+), 4 deletions(-)

diff --git a/application/controllers/HostController.php b/application/controllers/HostController.php
index 8219676..c8196a2 100644
--- a/application/controllers/HostController.php
+++ b/application/controllers/HostController.php
@@ -2,6 +2,7 @@
 
 namespace Icinga\Module\Director\Controllers;
 
+use Exception;
 use Icinga\Exception\NotFoundError;
 use Icinga\Module\Director\Objects\IcingaEndpoint;
 use Icinga\Module\Director\Objects\IcingaZone;
@@ -78,7 +79,24 @@ class HostController extends ObjectController
         $this->view->title = 'Agent deployment instructions';
         // TODO: Fail when no ticket
         $this->view->certname = $this->object->object_name;
-        $this->view->ticket = Util::getIcingaTicket($this->view->certname, $this->api()->getTicketSalt());
+
+        try {
+            $this->view->ticket = Util::getIcingaTicket(
+                $this->view->certname,
+                $this->api()->getTicketSalt()
+            );
+
+        } catch (Exception $e) {
+            $this->view->ticket = 'ERROR';
+            $this->view->error = sprintf(
+                $this->translate(
+                    'A ticket for this agent could not have been requested from'
+                    . ' your deployment endpoint: %s'
+                ),
+                $e->getMessage()
+            );
+        }
+
         $this->view->master = $this->db()->getDeploymentEndpointName();
         $this->view->masterzone = $this->db()->getMasterZoneName();
         $this->view->globalzone = $this->db()->getDefaultGlobalZoneName();
@@ -95,7 +113,12 @@ class HostController extends ObjectController
             throw new NotFoundError('The host "%s" is not an agent', $host->object_name);
         }
 
-        return $this->sendJson(Util::getIcingaTicket($host->object_name, $this->api()->getTicketSalt()));
+        return $this->sendJson(
+            Util::getIcingaTicket(
+                $host->object_name,
+                $this->api()->getTicketSalt()
+            )
+        );
     }
 
     public function renderAction()
diff --git a/application/views/scripts/host/agent.phtml b/application/views/scripts/host/agent.phtml
index e799834..e6149a4 100644
--- a/application/views/scripts/host/agent.phtml
+++ b/application/views/scripts/host/agent.phtml
@@ -8,7 +8,11 @@
 $cert   = $this->escape($this->certname);
 $master = $this->escape($this->master);
 ?>
-Please check the <a href="http://docs.icinga.org/icinga2/latest/doc/module/icinga2/chapter/icinga2-client">Icinga 2 Client documentation</a> for more related information. The Director-assisted setup corresponds to configuring the <a href="http://docs.icinga.org/icinga2/latest/doc/module/icinga2/chapter/icinga2-client#icinga2-client-configuration-command-bridge">Client as Command Execution Bridge</a>.
+<p>Please check the <a href="http://docs.icinga.org/icinga2/latest/doc/module/icinga2/chapter/icinga2-client">Icinga 2 Client documentation</a> for more related information. The Director-assisted setup corresponds to configuring the <a href="http://docs.icinga.org/icinga2/latest/doc/module/icinga2/chapter/icinga2-client#icinga2-client-configuration-command-bridge">Client as Command Execution Bridge</a>.</p>
+
+<?php if ($this->error): ?>
+<p class="error"><?= $this->escape($this->error) ?></p>
+<?php endif ?>
 
 <h2>When using the node wizard</h2>
 <p>Ticket : <code><?= $this->escape($ticket) ?></code></p>
@@ -49,7 +53,7 @@ icinga2 pki request --host <?= $master ?> \
 include "constants.conf"
 include <itl>
 include <plugins>
-include <plugins-contrib>
+// include <plugins-contrib>
 
 object FileLogger "main-log" {
   severity = "information"



More information about the icinga-checkins mailing list