From c4f8425634b51cdb762f686e053e099edb2a40f4 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Thu, 15 Oct 2015 23:48:36 +0200 Subject: [PATCH] IcingaHost: add enumProperties, test for now --- library/Director/Db.php | 19 +++++++++++++++++++ library/Director/Objects/IcingaHost.php | 20 ++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/library/Director/Db.php b/library/Director/Db.php index 0714ebee..c81c0b9d 100644 --- a/library/Director/Db.php +++ b/library/Director/Db.php @@ -382,6 +382,25 @@ class Db extends DbConnection 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() { $db = $this->db(); diff --git a/library/Director/Objects/IcingaHost.php b/library/Director/Objects/IcingaHost.php index a8e5854b..5ef365af 100644 --- a/library/Director/Objects/IcingaHost.php +++ b/library/Director/Objects/IcingaHost.php @@ -2,6 +2,7 @@ namespace Icinga\Module\Director\Objects; +use Icinga\Data\Db\DbConnection; use Icinga\Module\Director\Web\Form\DirectorObjectForm; class IcingaHost extends IcingaObject @@ -46,6 +47,25 @@ class IcingaHost extends IcingaObject 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() { return $this->renderCommandProperty($this->check_command_id);