host/ticket: add new REST API endpoint

This commit is contained in:
Thomas Gelf 2016-04-08 00:24:20 +02:00
parent bd03ec62e5
commit 630cf488f1
2 changed files with 36 additions and 0 deletions

View File

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

View File

@ -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.