IcingaHost: improve and extend enumProperties

This commit is contained in:
Thomas Gelf 2016-03-30 19:21:47 +02:00
parent d6be2e777c
commit 8cfdbbfb1e
1 changed files with 40 additions and 16 deletions

View File

@ -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;
} }