2015-04-24 14:26:44 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Icinga\Module\Director\Objects;
|
|
|
|
|
2015-10-15 23:48:36 +02:00
|
|
|
use Icinga\Data\Db\DbConnection;
|
2015-07-28 17:35:54 +02:00
|
|
|
use Icinga\Module\Director\Web\Form\DirectorObjectForm;
|
|
|
|
|
2015-04-24 15:57:01 +02:00
|
|
|
class IcingaHost extends IcingaObject
|
2015-04-24 14:26:44 +02:00
|
|
|
{
|
|
|
|
protected $table = 'icinga_host';
|
|
|
|
|
|
|
|
protected $defaultProperties = array(
|
|
|
|
'id' => null,
|
|
|
|
'object_name' => null,
|
2016-02-16 12:17:50 +01:00
|
|
|
'object_type' => null,
|
|
|
|
'disabled' => 'n',
|
2015-08-29 00:05:39 +02:00
|
|
|
'display_name' => null,
|
2015-04-24 14:26:44 +02:00
|
|
|
'address' => null,
|
|
|
|
'address6' => null,
|
|
|
|
'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-17 19:27:01 +01:00
|
|
|
'has_agent' => null,
|
|
|
|
'master_should_connect' => null,
|
|
|
|
'accept_config' => null,
|
2015-04-24 14:26:44 +02:00
|
|
|
);
|
2015-06-08 14:41:40 +02:00
|
|
|
|
2015-12-03 14:20:13 +01:00
|
|
|
protected $relations = array(
|
|
|
|
'check_command' => 'IcingaCommand',
|
|
|
|
'event_command' => 'IcingaCommand',
|
|
|
|
'check_period' => 'IcingaTimePeriod',
|
|
|
|
'command_endpoint' => 'IcingaEndpoint',
|
|
|
|
'zone' => 'IcingaZone',
|
|
|
|
);
|
|
|
|
|
2015-12-17 19:22:53 +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',
|
|
|
|
'has_agent' => 'has_agent',
|
|
|
|
'master_should_connect' => 'master_should_connect',
|
2016-03-18 11:38:44 +01:00
|
|
|
'accept_config' => 'accept_config',
|
2015-12-17 19:22:53 +01:00
|
|
|
);
|
|
|
|
|
2016-02-28 14:21:00 +01:00
|
|
|
protected $intervalProperties = array(
|
|
|
|
'check_interval' => 'check_interval',
|
|
|
|
'retry_interval' => 'retry_interval',
|
|
|
|
);
|
|
|
|
|
2015-06-08 14:42:12 +02:00
|
|
|
protected $supportsCustomVars = true;
|
|
|
|
|
2015-06-16 17:51:01 +02:00
|
|
|
protected $supportsGroups = true;
|
|
|
|
|
2015-06-26 10:39:30 +02:00
|
|
|
protected $supportsImports = true;
|
|
|
|
|
2015-07-30 11:45:55 +02:00
|
|
|
protected $supportsFields = true;
|
|
|
|
|
2016-03-30 19:21:47 +02:00
|
|
|
public static function enumProperties(DbConnection $connection = null, $prefix = '')
|
2015-10-15 23:48:36 +02:00
|
|
|
{
|
2016-03-30 19:21:47 +02:00
|
|
|
$hostProperties = array($prefix . 'name' => 'name');
|
|
|
|
$realProperties = static::create()->listProperties();
|
|
|
|
sort($realProperties);
|
|
|
|
|
|
|
|
$blacklist = array(
|
|
|
|
'id',
|
|
|
|
'object_name',
|
|
|
|
'object_type',
|
|
|
|
'disabled',
|
|
|
|
'has_agent',
|
|
|
|
'master_should_connect',
|
|
|
|
'accept_config',
|
2015-11-25 12:52:57 +01:00
|
|
|
);
|
|
|
|
|
2016-03-30 19:21:47 +02:00
|
|
|
foreach ($realProperties as $prop) {
|
|
|
|
if (in_array($prop, $blacklist)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (substr($prop, -3) === '_id') {
|
|
|
|
$prop = substr($prop, 0, -3);
|
|
|
|
}
|
|
|
|
|
|
|
|
$hostProperties[$prefix . $prop] = $prop;
|
|
|
|
}
|
2016-02-27 09:45:38 +01:00
|
|
|
|
2016-03-30 19:21:47 +02:00
|
|
|
$hostVars = array();
|
2015-10-15 23:48:36 +02:00
|
|
|
if ($connection !== null) {
|
|
|
|
foreach ($connection->fetchDistinctHostVars() as $var) {
|
|
|
|
if ($var->datatype) {
|
2016-03-30 19:21:47 +02:00
|
|
|
$hostVars[$prefix . 'vars.' . $var->varname] = sprintf(
|
2016-02-27 09:45:38 +01:00
|
|
|
'%s (%s)',
|
|
|
|
$var->varname,
|
|
|
|
$var->caption
|
|
|
|
);
|
2015-10-15 23:48:36 +02:00
|
|
|
} else {
|
2016-03-30 19:21:47 +02:00
|
|
|
$hostVars[$prefix . 'vars.' . $var->varname] = $var->varname;
|
2015-10-15 23:48:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-25 12:52:57 +01:00
|
|
|
//$properties['vars.*'] = 'Other custom variable';
|
2016-03-30 19:21:47 +02:00
|
|
|
ksort($hostVars);
|
|
|
|
|
|
|
|
|
|
|
|
$props = mt('director', 'Host properties');
|
|
|
|
$vars = mt('director', 'Custom variables');
|
|
|
|
$properties = array(
|
|
|
|
$props => $hostProperties,
|
|
|
|
);
|
|
|
|
|
|
|
|
if (!empty($hostVars)) {
|
|
|
|
$properties[$vars] = $hostVars;
|
|
|
|
}
|
|
|
|
|
2015-10-15 23:48:36 +02:00
|
|
|
return $properties;
|
|
|
|
}
|
|
|
|
|
2015-11-06 09:49:05 +01:00
|
|
|
public function getCheckCommand()
|
|
|
|
{
|
|
|
|
$id = $this->getResolvedProperty('check_command_id');
|
|
|
|
return IcingaCommand::loadWithAutoIncId(
|
|
|
|
$id,
|
|
|
|
$this->getConnection()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function hasCheckCommand()
|
|
|
|
{
|
|
|
|
return $this->getResolvedProperty('check_command_id') !== null;
|
|
|
|
}
|
2015-12-17 19:27:01 +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 19:27:01 +01:00
|
|
|
protected function renderHas_Agent()
|
|
|
|
{
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
2016-02-26 11:58:37 +01:00
|
|
|
/**
|
|
|
|
* Internal property, will not be rendered
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
2015-12-17 19:27:01 +01:00
|
|
|
protected function renderMaster_should_connect()
|
|
|
|
{
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
2016-02-26 11:58:37 +01:00
|
|
|
/**
|
|
|
|
* Internal property, will not be rendered
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
2015-12-17 19:27:01 +01:00
|
|
|
protected function renderAccept_config()
|
|
|
|
{
|
2016-02-26 11:58:37 +01:00
|
|
|
// @codingStandardsIgnoreEnd
|
2015-12-17 19:27:01 +01:00
|
|
|
return '';
|
|
|
|
}
|
2015-04-24 14:26:44 +02:00
|
|
|
}
|