From 630cf488f1ba848e27ed3d9d757bf755dc9ce2ee Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Fri, 8 Apr 2016 00:24:20 +0200 Subject: [PATCH] host/ticket: add new REST API endpoint --- application/controllers/HostController.php | 15 +++++++++++++++ doc/70-REST-API.md | 21 +++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/application/controllers/HostController.php b/application/controllers/HostController.php index f4fff527..8219676f 100644 --- a/application/controllers/HostController.php +++ b/application/controllers/HostController.php @@ -2,6 +2,7 @@ namespace Icinga\Module\Director\Controllers; +use Icinga\Exception\NotFoundError; use Icinga\Module\Director\Objects\IcingaEndpoint; use Icinga\Module\Director\Objects\IcingaZone; use Icinga\Module\Director\Util; @@ -83,6 +84,20 @@ class HostController extends ObjectController $this->view->globalzone = $this->db()->getDefaultGlobalZoneName(); } + public function ticketAction() + { + if (! $this->getRequest()->isApiRequest() || ! $this->object) { + throw new NotFoundError('Not found'); + } + + $host = $this->object; + if ($host->getResolvedProperty('has_agent') !== 'y') { + throw new NotFoundError('The host "%s" is not an agent', $host->object_name); + } + + return $this->sendJson(Util::getIcingaTicket($host->object_name, $this->api()->getTicketSalt())); + } + public function renderAction() { $this->renderAgentExtras(); diff --git a/doc/70-REST-API.md b/doc/70-REST-API.md index 0f122a52..d63166d7 100644 --- a/doc/70-REST-API.md +++ b/doc/70-REST-API.md @@ -487,3 +487,24 @@ Content-Type: application/json } ``` +### Agent Tickets + +The Director is very helpful when it goes to manage your Icinga Agents. In +case you want to fetch tickets through the API, please do as follows: + + GET director/host/ticket?name=apitest + +``` +HTTP/1.1 200 OK +Date: Thu, 07 Apr 2016 22:19:24 GMT +Server: Apache +Content-Length: 43 +Content-Type: application/json +``` + +```json +"5de9883080e03278039bce57e4fbdbe8fd262c40" +``` + +Please expect an error in case the host does not exist or has not been +configured to be an Icinga Agent.