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

...when the deployment endpoint is not reachable
This commit is contained in:
Thomas Gelf 2016-05-03 08:27:12 +02:00
parent d84369ce77
commit fddd4488b5
2 changed files with 31 additions and 4 deletions

View File

@ -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()

View File

@ -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 &lt;itl&gt;
include &lt;plugins&gt;
include &lt;plugins-contrib&gt;
// include &lt;plugins-contrib&gt;
object FileLogger "main-log" {
severity = "information"