From f66ab8dae2f3d0418759f81a3a64dc9517a62449 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 14 Apr 2024 15:17:31 +0200 Subject: Adding upstream version 1.10.2. Signed-off-by: Daniel Baumann --- .../Director/Resolver/OverriddenVarsResolver.php | 74 ++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 library/Director/Resolver/OverriddenVarsResolver.php (limited to 'library/Director/Resolver/OverriddenVarsResolver.php') diff --git a/library/Director/Resolver/OverriddenVarsResolver.php b/library/Director/Resolver/OverriddenVarsResolver.php new file mode 100644 index 0000000..4541244 --- /dev/null +++ b/library/Director/Resolver/OverriddenVarsResolver.php @@ -0,0 +1,74 @@ +overrideVarName = $connection->settings()->get('override_services_varname'); + $this->db = $connection->getDbAdapter(); + } + + public function fetchForHost(IcingaHost $host) + { + $overrides = []; + $parents = $host->listFlatResolvedImportNames(); + if (empty($parents)) { + return $overrides; + } + $query = $this->db->select() + ->from(['hv' => 'icinga_host_var'], [ + 'host_name' => 'h.object_name', + 'varvalue' => 'hv.varvalue', + ]) + ->join( + ['h' => 'icinga_host'], + 'h.id = hv.host_id', + [] + ) + ->where('hv.varname = ?', $this->overrideVarName) + ->where('h.object_name IN (?)', $parents); + + foreach ($this->db->fetchAll($query) as $row) { + if ($row->varvalue === null) { + continue; + } + foreach (Json::decode($row->varvalue) as $serviceName => $vars) { + $overrides[$serviceName][$row->host_name] = $vars; + } + } + + return $overrides; + } + + public function fetchForServiceName(IcingaHost $host, $serviceName) + { + $overrides = $this->fetchForHost($host); + if (isset($overrides[$serviceName])) { + return $overrides[$serviceName]; + } + + return []; + } + + public function fetchVarForServiceName(IcingaHost $host, $serviceName, $varName) + { + $overrides = $this->fetchForHost($host); + if (isset($overrides[$serviceName][$varName])) { + return $overrides[$serviceName][$varName]; + } + + return null; + } +} -- cgit v1.2.3