IcingaHost: improve and extend enumProperties
This commit is contained in:
parent
d6be2e777c
commit
8cfdbbfb1e
|
@ -77,39 +77,63 @@ class IcingaHost extends IcingaObject
|
||||||
|
|
||||||
protected $supportsFields = true;
|
protected $supportsFields = true;
|
||||||
|
|
||||||
public static function enumProperties(DbConnection $connection = null)
|
public static function enumProperties(DbConnection $connection = null, $prefix = '')
|
||||||
{
|
{
|
||||||
$properties = array_merge(
|
$hostProperties = array($prefix . 'name' => 'name');
|
||||||
array('name'),
|
$realProperties = static::create()->listProperties();
|
||||||
static::create()->listProperties()
|
sort($realProperties);
|
||||||
);
|
|
||||||
$props = mt('director', 'Properties');
|
$blacklist = array(
|
||||||
$vars = mt('director', 'Custom variables');
|
'id',
|
||||||
$properties = array(
|
'object_name',
|
||||||
$props => array_combine($properties, $properties),
|
'object_type',
|
||||||
$vars => array()
|
'disabled',
|
||||||
|
'has_agent',
|
||||||
|
'master_should_connect',
|
||||||
|
'accept_config',
|
||||||
);
|
);
|
||||||
|
|
||||||
unset($properties[$props]['object_name']);
|
foreach ($realProperties as $prop) {
|
||||||
unset($properties[$props]['object_type']);
|
if (in_array($prop, $blacklist)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (substr($prop, -3) === '_id') {
|
||||||
|
$prop = substr($prop, 0, -3);
|
||||||
|
}
|
||||||
|
|
||||||
|
$hostProperties[$prefix . $prop] = $prop;
|
||||||
|
}
|
||||||
|
|
||||||
|
$hostVars = array();
|
||||||
if ($connection !== null) {
|
if ($connection !== null) {
|
||||||
foreach ($connection->fetchDistinctHostVars() as $var) {
|
foreach ($connection->fetchDistinctHostVars() as $var) {
|
||||||
if ($var->datatype) {
|
if ($var->datatype) {
|
||||||
$properties[$vars]['vars.' . $var->varname] = sprintf(
|
$hostVars[$prefix . 'vars.' . $var->varname] = sprintf(
|
||||||
'%s (%s)',
|
'%s (%s)',
|
||||||
$var->varname,
|
$var->varname,
|
||||||
$var->caption
|
$var->caption
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
$properties[$vars]['vars.' . $var->varname] = $var->varname;
|
$hostVars[$prefix . 'vars.' . $var->varname] = $var->varname;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//$properties['vars.*'] = 'Other custom variable';
|
//$properties['vars.*'] = 'Other custom variable';
|
||||||
ksort($properties[$vars]);
|
ksort($hostVars);
|
||||||
ksort($properties[$props]);
|
|
||||||
|
|
||||||
|
$props = mt('director', 'Host properties');
|
||||||
|
$vars = mt('director', 'Custom variables');
|
||||||
|
$properties = array(
|
||||||
|
$props => $hostProperties,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!empty($hostVars)) {
|
||||||
|
$properties[$vars] = $hostVars;
|
||||||
|
}
|
||||||
|
|
||||||
return $properties;
|
return $properties;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue