IcingaHost: add enumProperties, test for now

This commit is contained in:
Thomas Gelf 2015-10-15 23:48:36 +02:00
parent 988eb4bf77
commit c4f8425634
2 changed files with 39 additions and 0 deletions

View File

@ -382,6 +382,25 @@ class Db extends DbConnection
return $this->enum('icinga_' . $type, null, $filters); return $this->enum('icinga_' . $type, null, $filters);
} }
public function fetchDistinctHostVars()
{
$select = $this->db()->select()->distinct()->from(
array('hv' => 'icinga_host_var'),
array(
'varname' => 'hv.varname',
'format' => 'hv.format',
'caption' => 'df.caption',
'datatype' => 'df.datatype'
)
)->joinLeft(
array('df' => 'director_datafield'),
'df.varname = hv.varname',
array()
)->order('varname');
return $this->db()->fetchAll($select);
}
public function getUncollectedDeployments() public function getUncollectedDeployments()
{ {
$db = $this->db(); $db = $this->db();

View File

@ -2,6 +2,7 @@
namespace Icinga\Module\Director\Objects; namespace Icinga\Module\Director\Objects;
use Icinga\Data\Db\DbConnection;
use Icinga\Module\Director\Web\Form\DirectorObjectForm; use Icinga\Module\Director\Web\Form\DirectorObjectForm;
class IcingaHost extends IcingaObject class IcingaHost extends IcingaObject
@ -46,6 +47,25 @@ class IcingaHost extends IcingaObject
protected $supportsFields = true; protected $supportsFields = true;
public static function enumProperties(DbConnection $connection = null)
{
$properties = static::create()->listProperties();
$properties = array_combine($properties, $properties);
if ($connection !== null) {
foreach ($connection->fetchDistinctHostVars() as $var) {
if ($var->datatype) {
$properties['vars.' . $var->varname] = $var->caption;
} else {
$properties['vars.' . $var->varname] = 'vars.' . $var->varname;
}
}
}
$properties['vars.*'] = 'Other custom variable';
return $properties;
}
protected function renderCheck_command_id() protected function renderCheck_command_id()
{ {
return $this->renderCommandProperty($this->check_command_id); return $this->renderCommandProperty($this->check_command_id);