icingaweb2-module-director/library/Director/Objects/IcingaEndpoint.php

89 lines
2.1 KiB
PHP
Raw Normal View History

2015-06-01 17:26:09 +02:00
<?php
namespace Icinga\Module\Director\Objects;
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,
'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,
'apiuser_id' => null,
2015-06-01 17:26:09 +02:00
);
protected $relations = array(
'zone' => 'IcingaZone',
'apiuser' => 'IcingaApiUser',
);
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(
$this->getResolvedProperty('host', $this->object_name),
$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
*/
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');
}
2016-02-26 11:58:37 +01:00
/**
* Internal property, will not be rendered
*
* Avoid complaints for method names with underscore:
* @codingStandardsIgnoreStart
*
* @return string
*/
protected function renderApiuser_id()
{
2016-02-26 11:58:37 +01:00
// @codingStandardsIgnoreEnd
return '';
}
2015-06-01 17:26:09 +02:00
}