From fa286d1fcbb64c7eb9e8995d2782e0224d2df29c Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Wed, 23 Aug 2017 23:52:00 +0200 Subject: [PATCH] IcingaTemplateRepository: list names --- .../Repository/IcingaTemplateRepository.php | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/library/Director/Repository/IcingaTemplateRepository.php b/library/Director/Repository/IcingaTemplateRepository.php index 9af713fd..f0a4cc04 100644 --- a/library/Director/Repository/IcingaTemplateRepository.php +++ b/library/Director/Repository/IcingaTemplateRepository.php @@ -71,4 +71,25 @@ class IcingaTemplateRepository public function storeChances(Db $db) { } + + public function listAllowedTemplateNames() + { + $type = $this->type; + $db = $this->connection->getDbAdapter(); + $table = 'icinga_' . $this->type; + + $query = $db->select() + ->from($table, 'object_name') + ->order('object_name'); + + if ($type !== 'command') { + $query->where('object_type = ?', 'template'); + } + + if (in_array($type, ['host', 'service'])) { + $query->where('template_choice_id IS NULL'); + } + + return $db->fetchCol($query); + } }