2015-06-03 14:34:54 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Icinga\Module\Director\Objects;
|
|
|
|
|
2016-03-06 14:21:18 +01:00
|
|
|
use Icinga\Module\Director\IcingaConfig\IcingaConfigHelper as c;
|
|
|
|
|
2015-06-03 14:34:54 +02:00
|
|
|
class IcingaService extends IcingaObject
|
|
|
|
{
|
|
|
|
protected $table = 'icinga_service';
|
|
|
|
|
|
|
|
protected $defaultProperties = array(
|
|
|
|
'id' => null,
|
|
|
|
'object_name' => null,
|
2016-02-16 12:17:50 +01:00
|
|
|
'object_type' => null,
|
|
|
|
'disabled' => 'n',
|
2015-06-03 14:34:54 +02:00
|
|
|
'display_name' => null,
|
2015-12-10 12:12:58 +01:00
|
|
|
'host_id' => null,
|
2015-06-03 14:34:54 +02:00
|
|
|
'check_command_id' => null,
|
|
|
|
'max_check_attempts' => null,
|
|
|
|
'check_period_id' => null,
|
|
|
|
'check_interval' => null,
|
|
|
|
'retry_interval' => null,
|
|
|
|
'enable_notifications' => null,
|
|
|
|
'enable_active_checks' => null,
|
|
|
|
'enable_passive_checks' => null,
|
|
|
|
'enable_event_handler' => null,
|
|
|
|
'enable_flapping' => null,
|
|
|
|
'enable_perfdata' => null,
|
|
|
|
'event_command_id' => null,
|
|
|
|
'flapping_threshold' => null,
|
|
|
|
'volatile' => null,
|
|
|
|
'zone_id' => null,
|
|
|
|
'command_endpoint_id' => null,
|
|
|
|
'notes' => null,
|
|
|
|
'notes_url' => null,
|
|
|
|
'action_url' => null,
|
|
|
|
'icon_image' => null,
|
|
|
|
'icon_image_alt' => null,
|
2015-12-18 11:07:23 +01:00
|
|
|
'use_agent' => null,
|
2015-06-03 14:34:54 +02:00
|
|
|
);
|
2015-06-08 14:41:40 +02:00
|
|
|
|
2015-12-10 12:12:58 +01:00
|
|
|
protected $relations = array(
|
|
|
|
'host' => 'IcingaHost',
|
|
|
|
'check_command' => 'IcingaCommand',
|
|
|
|
'event_command' => 'IcingaCommand',
|
|
|
|
'check_period' => 'IcingaTimePeriod',
|
|
|
|
'command_endpoint' => 'IcingaEndpoint',
|
|
|
|
'zone' => 'IcingaZone',
|
|
|
|
);
|
|
|
|
|
2015-12-18 11:52:00 +01:00
|
|
|
protected $booleans = array(
|
2015-12-18 12:07:26 +01:00
|
|
|
'enable_notifications' => 'enable_notifications',
|
|
|
|
'enable_active_checks' => 'enable_active_checks',
|
|
|
|
'enable_passive_checks' => 'enable_passive_checks',
|
|
|
|
'enable_event_handler' => 'enable_event_handler',
|
|
|
|
'enable_flapping' => 'enable_flapping',
|
|
|
|
'enable_perfdata' => 'enable_perfdata',
|
|
|
|
'volatile' => 'volatile',
|
|
|
|
'use_agent' => 'use_agent',
|
2015-12-18 11:52:00 +01:00
|
|
|
);
|
|
|
|
|
2016-02-28 14:21:00 +01:00
|
|
|
protected $intervalProperties = array(
|
|
|
|
'check_interval' => 'check_interval',
|
|
|
|
'retry_interval' => 'retry_interval',
|
|
|
|
);
|
|
|
|
|
2015-06-16 17:51:01 +02:00
|
|
|
protected $supportsGroups = true;
|
|
|
|
|
2015-06-24 10:13:27 +02:00
|
|
|
protected $supportsCustomVars = true;
|
|
|
|
|
2015-07-31 17:34:12 +02:00
|
|
|
protected $supportsFields = true;
|
|
|
|
|
2015-06-26 16:20:16 +02:00
|
|
|
protected $supportsImports = true;
|
|
|
|
|
2016-02-24 21:37:48 +01:00
|
|
|
protected $supportsApplyRules = true;
|
|
|
|
|
2015-12-10 12:12:58 +01:00
|
|
|
protected $keyName = array('host_id', 'object_name');
|
|
|
|
|
2016-06-17 11:55:48 +02:00
|
|
|
protected $prioritizedProperties = array('host_id');
|
|
|
|
|
2015-11-15 16:39:20 +01:00
|
|
|
public function getCheckCommand()
|
|
|
|
{
|
|
|
|
$id = $this->getResolvedProperty('check_command_id');
|
|
|
|
return IcingaCommand::loadWithAutoIncId(
|
|
|
|
$id,
|
|
|
|
$this->getConnection()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-05-20 15:21:29 +02:00
|
|
|
public function isApplyRule()
|
|
|
|
{
|
|
|
|
if ($this->hasBeenAssignedToHostTemplate()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->hasProperty('object_type')
|
|
|
|
&& $this->object_type === 'apply';
|
|
|
|
}
|
|
|
|
|
2016-03-06 19:13:58 +01:00
|
|
|
protected function setKey($key)
|
|
|
|
{
|
|
|
|
if (is_int($key)) {
|
|
|
|
$this->id = $key;
|
|
|
|
} elseif (is_array($key)) {
|
|
|
|
foreach (array('id', 'host_id', 'object_name') as $k) {
|
|
|
|
if (array_key_exists($k, $key)) {
|
|
|
|
$this->set($k, $key[$k]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return parent::setKey($key);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2016-02-26 11:58:37 +01:00
|
|
|
/**
|
|
|
|
* Render host_id as host_name
|
|
|
|
*
|
|
|
|
* Avoid complaints for method names with underscore:
|
|
|
|
* @codingStandardsIgnoreStart
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
2015-12-10 12:12:58 +01:00
|
|
|
public function renderHost_id()
|
|
|
|
{
|
2016-02-26 11:58:37 +01:00
|
|
|
// @codingStandardsIgnoreEnd
|
2016-03-16 14:32:23 +01:00
|
|
|
|
|
|
|
if ($this->hasBeenAssignedToHostTemplate()) {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
2015-12-10 12:12:58 +01:00
|
|
|
return $this->renderRelationProperty('host', $this->host_id, 'host_name');
|
|
|
|
}
|
|
|
|
|
2016-03-06 14:21:18 +01:00
|
|
|
protected function renderAssignments()
|
|
|
|
{
|
|
|
|
if (! $this->hasBeenAssignedToHostTemplate()) {
|
|
|
|
return parent::renderAssignments();
|
|
|
|
}
|
|
|
|
|
2016-08-27 10:46:46 +02:00
|
|
|
// TODO: use assignment renderer?
|
2016-03-06 14:21:18 +01:00
|
|
|
$filter = sprintf(
|
2016-08-27 10:46:46 +02:00
|
|
|
'assign where %s in host.templates',
|
|
|
|
c::renderString($this->host)
|
2016-03-06 14:21:18 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
return "\n " . $filter . "\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function hasBeenAssignedToHostTemplate()
|
|
|
|
{
|
|
|
|
return $this->host_id && $this->getRelatedObject(
|
|
|
|
'host',
|
|
|
|
$this->host_id
|
|
|
|
)->object_type === 'template';
|
|
|
|
}
|
|
|
|
|
2015-12-18 15:52:02 +01:00
|
|
|
protected function renderCustomExtensions()
|
2015-12-18 11:55:42 +01:00
|
|
|
{
|
2016-05-10 21:13:07 +02:00
|
|
|
// A hand-crafted command endpoint overrides use_agent
|
|
|
|
if ($this->command_endpoint_id !== null) {
|
2016-02-26 11:58:37 +01:00
|
|
|
return '';
|
|
|
|
}
|
2015-12-18 11:55:42 +01:00
|
|
|
|
2016-05-10 21:13:07 +02:00
|
|
|
// In case use_agent isn't defined, do nothing
|
|
|
|
// TODO: what if we inherit use_agent and override it with 'n'?
|
|
|
|
if ($this->use_agent !== 'y') {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
2016-05-19 16:06:06 +02:00
|
|
|
return c::renderKeyValue('command_endpoint', 'host_name');
|
2015-12-18 11:55:42 +01:00
|
|
|
}
|
|
|
|
|
2016-02-26 11:58:37 +01:00
|
|
|
/**
|
|
|
|
* Do not render internal property
|
|
|
|
*
|
|
|
|
* Avoid complaints for method names with underscore:
|
|
|
|
* @codingStandardsIgnoreStart
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
2015-12-18 11:07:23 +01:00
|
|
|
public function renderUse_agent()
|
|
|
|
{
|
2016-02-26 11:58:37 +01:00
|
|
|
// @codingStandardsIgnoreEnd
|
2015-12-18 11:07:23 +01:00
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
2015-11-15 16:39:20 +01:00
|
|
|
public function hasCheckCommand()
|
|
|
|
{
|
|
|
|
return $this->getResolvedProperty('check_command_id') !== null;
|
|
|
|
}
|
2016-03-20 12:04:06 +01:00
|
|
|
|
|
|
|
public function getOnDeleteUrl()
|
|
|
|
{
|
|
|
|
if ($this->host_id) {
|
|
|
|
return 'director/host/services?name=' . rawurlencode($this->host);
|
|
|
|
} else {
|
|
|
|
return parent::getOnDeleteUrl();
|
|
|
|
}
|
|
|
|
}
|
2015-06-03 14:34:54 +02:00
|
|
|
}
|