2015-06-01 17:26:09 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Icinga\Module\Director\Objects;
|
|
|
|
|
2016-02-17 16:39:18 +01:00
|
|
|
use Icinga\Module\Director\Core\CoreApi;
|
|
|
|
use Icinga\Module\Director\Core\RestApiClient;
|
|
|
|
|
2015-06-01 17:26:09 +02:00
|
|
|
class IcingaEndpoint extends IcingaObject
|
|
|
|
{
|
|
|
|
protected $table = 'icinga_endpoint';
|
|
|
|
|
2015-06-29 11:11:56 +02:00
|
|
|
protected $supportsImports = true;
|
|
|
|
|
2015-06-01 17:26:09 +02:00
|
|
|
protected $defaultProperties = array(
|
|
|
|
'id' => null,
|
|
|
|
'zone_id' => null,
|
|
|
|
'object_name' => null,
|
2016-02-16 12:17:50 +01:00
|
|
|
'object_type' => null,
|
|
|
|
'disabled' => 'n',
|
2015-12-08 08:29:04 +01:00
|
|
|
'host' => null,
|
2015-06-01 17:26:09 +02:00
|
|
|
'port' => null,
|
|
|
|
'log_duration' => null,
|
2015-12-17 14:29:08 +01:00
|
|
|
'apiuser_id' => null,
|
2015-06-01 17:26:09 +02:00
|
|
|
);
|
2015-12-03 16:50:44 +01:00
|
|
|
|
|
|
|
protected $relations = array(
|
2015-12-17 14:29:08 +01:00
|
|
|
'zone' => 'IcingaZone',
|
|
|
|
'apiuser' => 'IcingaApiUser',
|
2015-12-03 16:50:44 +01:00
|
|
|
);
|
2015-12-03 17:56:27 +01:00
|
|
|
|
2016-02-17 16:39:18 +01:00
|
|
|
public function hasApiUser()
|
|
|
|
{
|
|
|
|
return $this->getResolvedProperty('apiuser_id') !== null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getApiUser()
|
|
|
|
{
|
|
|
|
return $this->getRelatedObject(
|
|
|
|
'apiuser',
|
|
|
|
$this->getResolvedProperty('apiuser_id')
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function api()
|
|
|
|
{
|
|
|
|
$client = new RestApiClient(
|
2016-03-07 02:03:34 +01:00
|
|
|
$this->getResolvedProperty('host', $this->object_name),
|
2016-02-17 16:39:18 +01:00
|
|
|
$this->getResolvedProperty('port')
|
|
|
|
);
|
|
|
|
|
|
|
|
$user = $this->getApiUser();
|
|
|
|
$client->setCredentials(
|
|
|
|
// TODO: $user->client_dn,
|
|
|
|
$user->object_name,
|
|
|
|
$user->password
|
|
|
|
);
|
|
|
|
|
|
|
|
return new CoreApi($client);
|
|
|
|
}
|
|
|
|
|
2016-02-26 11:58:37 +01:00
|
|
|
/**
|
|
|
|
* Use duration time renderer helper
|
|
|
|
*
|
|
|
|
* Avoid complaints for method names with underscore:
|
|
|
|
* @codingStandardsIgnoreStart
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
2015-12-03 17:56:27 +01:00
|
|
|
protected function renderLog_duration()
|
|
|
|
{
|
2016-02-26 11:58:37 +01:00
|
|
|
// @codingStandardsIgnoreEnd
|
2015-12-03 18:02:57 +01:00
|
|
|
return $this->renderPropertyAsSeconds('log_duration');
|
2015-12-03 17:56:27 +01:00
|
|
|
}
|
2015-12-17 14:29:08 +01:00
|
|
|
|
2016-02-26 11:58:37 +01:00
|
|
|
/**
|
|
|
|
* Internal property, will not be rendered
|
|
|
|
*
|
|
|
|
* Avoid complaints for method names with underscore:
|
|
|
|
* @codingStandardsIgnoreStart
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
2015-12-17 14:29:08 +01:00
|
|
|
protected function renderApiuser_id()
|
|
|
|
{
|
2016-02-26 11:58:37 +01:00
|
|
|
// @codingStandardsIgnoreEnd
|
2015-12-17 14:29:08 +01:00
|
|
|
return '';
|
|
|
|
}
|
2015-06-01 17:26:09 +02:00
|
|
|
}
|