reference_name -> interfaceid) */ public $interfaces_cache = []; protected $groups = []; protected $templates = []; protected $hosts = []; protected $items = []; protected $valuemaps = []; protected $triggers = []; protected $graphs = []; protected $iconmaps = []; protected $images = []; protected $maps = []; protected $template_dashboards = []; protected $template_macros = []; protected $host_macros = []; protected $host_prototype_macros = []; protected $proxies = []; protected $host_prototypes = []; protected $httptests = []; protected $httpsteps = []; protected $db_groups; protected $db_templates; protected $db_hosts; protected $db_items; protected $db_valuemaps; protected $db_triggers; protected $db_graphs; protected $db_iconmaps; protected $db_images; protected $db_maps; protected $db_template_dashboards; protected $db_template_macros; protected $db_host_macros; protected $db_host_prototype_macros; protected $db_proxies; protected $db_host_prototypes; protected $db_httptests; protected $db_httpsteps; /** * Get group ID by group UUID. * * @param string $uuid * * @return string|null */ public function findGroupidByUuid(string $uuid): ?string { if ($this->db_groups === null) { $this->selectGroups(); } foreach ($this->db_groups as $groupid => $group) { if ($group['uuid'] === $uuid) { return $groupid; } } return null; } /** * Get group ID by group name. * * @param string $name * * @return string|null */ public function findGroupidByName(string $name): ?string { if ($this->db_groups === null) { $this->selectGroups(); } foreach ($this->db_groups as $groupid => $group) { if ($group['name'] === $name) { return $groupid; } } return null; } /** * Get template ID by group UUID. * * @param string $uuid * * @return string|null */ public function findTemplateidByUuid(string $uuid): ?string { if ($this->db_templates === null) { $this->selectTemplates(); } foreach ($this->db_templates as $templateid => $template) { if ($template['uuid'] === $uuid) { return $templateid; } } return null; } /** * Get template ID by template host. * * @param string $host * * @return string|null */ public function findTemplateidByHost(string $host): ?string { if ($this->db_templates === null) { $this->selectTemplates(); } foreach ($this->db_templates as $templateid => $template) { if ($template['host'] === $host) { return $templateid; } } return null; } /** * Get host ID by host. * * @param string $name * * @return string|bool */ public function findHostidByHost(string $name): ?string { if ($this->db_hosts === null) { $this->selectHosts(); } foreach ($this->db_hosts as $hostid => $host) { if ($host['host'] === $name) { return $hostid; } } return null; } /** * Get host ID or template ID by host. * * @param string $host * * @return string|null */ public function findTemplateidOrHostidByHost(string $host): ?string { $templateid = $this->findTemplateidByHost($host); if ($templateid !== null) { return $templateid; } return $this->findHostidByHost($host); } /** * Get interface ID by host ID and interface reference. * * @param string $hostid * @param string $interface_ref * * @return string|null */ public function findInterfaceidByRef(string $hostid, string $interface_ref): ?string { if (array_key_exists($hostid, $this->interfaces_cache) && array_key_exists($interface_ref, $this->interfaces_cache[$hostid])) { return $this->interfaces_cache[$hostid][$interface_ref]; } return null; } /** * Initializes references for items. */ public function initItemsReferences(): void { if ($this->db_items === null) { $this->selectItems(); } } /** * Get item ID by uuid. * * @param string $uuid * * @return string|null */ public function findItemidByUuid(string $uuid): ?string { if ($this->db_items === null) { $this->selectItems(); } foreach ($this->db_items as $itemid => $item) { if ($item['uuid'] === $uuid) { return $itemid; } } return null; } /** * Get item ID by host ID and item key_. * * @param string $hostid * @param string $key * * @return string|null */ public function findItemidByKey(string $hostid, string $key): ?string { if ($this->db_items === null) { $this->selectItems(); } foreach ($this->db_items as $itemid => $item) { if ($item['hostid'] === $hostid && $item['key_'] === $key) { return $itemid; } } return null; } /** * Get valuemap ID by valuemap name. * * @param string $hostid * @param string $name * * @return string|null */ public function findValuemapidByName(string $hostid, string $name): ?string { if ($this->db_valuemaps === null) { $this->selectValuemaps(); } foreach ($this->db_valuemaps as $valuemapid => $valuemap) { if ($valuemap['hostid'] === $hostid && $valuemap['name'] === $name) { return $valuemapid; } } return null; } /** * Get image ID by image name. * * @param string $name * * @return string|null */ public function findImageidByName(string $name): ?string { if ($this->db_images === null) { $this->selectImages(); } foreach ($this->db_images as $imageid => $image) { if ($image['name'] === $name) { return $imageid; } } return null; } /** * Get trigger by trigger ID. * * @param string $triggerid * * @return array|null */ public function findTriggerById(string $triggerid): ?array { if ($this->db_triggers === null) { $this->selectTriggers(); } if (array_key_exists($triggerid, $this->db_triggers)) { return $this->db_triggers[$triggerid]; } return null; } /** * Get trigger ID by trigger UUID. * * @param string $uuid * * @return string|null */ public function findTriggeridByUuid(string $uuid): ?string { if ($this->db_triggers === null) { $this->selectTriggers(); } foreach ($this->db_triggers as $triggerid => $trigger) { if ($trigger['uuid'] === $uuid) { return $triggerid; } } return null; } /** * Get trigger ID by trigger name and expressions. * * @param string $name * @param string $expression * @param string $recovery_expression * * @return string|null */ public function findTriggeridByName(string $name, string $expression, string $recovery_expression): ?string { if ($this->db_triggers === null) { $this->selectTriggers(); } foreach ($this->db_triggers as $triggerid => $trigger) { if ($trigger['description'] === $name && $trigger['expression'] === $expression && $trigger['recovery_expression'] === $recovery_expression) { return $triggerid; } } return null; } /** * Get graph ID by UUID. * * @param string $uuid * * @return string|null */ public function findGraphidByUuid(string $uuid): ?string { if ($this->db_graphs === null) { $this->selectGraphs(); } foreach ($this->db_graphs as $graphid => $graph) { if ($graph['uuid'] === $uuid) { return $graphid; } } return null; } /** * Get graph ID by host ID and graph name. * * @param string $hostid * @param string $name * * @return string|null */ public function findGraphidByName(string $hostid, string $name): ?string { if ($this->db_graphs === null) { $this->selectGraphs(); } foreach ($this->db_graphs as $graphid => $graph) { if ($graph['name'] === $name && in_array($hostid, $graph['hosts'])) { return $graphid; } } return null; } /** * Get iconmap ID by name. * * @param string $name * * @return string|null */ public function findIconmapidByName(string $name): ?string { if ($this->db_iconmaps === null) { $this->selectIconmaps(); } foreach ($this->db_iconmaps as $iconmapid => $iconmap) { if ($iconmap['name'] === $name) { return $iconmapid; } } return null; } /** * Get map ID by name. * * @param string $name * * @return string|null */ public function findMapidByName(string $name): ?string { if ($this->db_maps === null) { $this->selectMaps(); } foreach ($this->db_maps as $mapid => $map) { if ($map['name'] === $name) { return $mapid; } } return null; } /** * Get template dashboard ID by dashboard UUID. * * @param string $uuid * * @return string|null * * @throws APIException */ public function findTemplateDashboardidByUuid(string $uuid): ?string { if ($this->db_template_dashboards === null) { $this->selectTemplateDashboards(); } foreach ($this->db_template_dashboards as $dashboardid => $dashboard) { if ($dashboard['uuid'] === $uuid) { return $dashboardid; } } return null; } /** * Get macro ID by template ID and macro name. * * @param string $templateid * @param string $macro * * @return string|null */ public function findTemplateMacroid(string $templateid, string $macro): ?string { if ($this->db_template_macros === null) { $this->selectTemplateMacros(); } return (array_key_exists($templateid, $this->db_template_macros) && array_key_exists($macro, $this->db_template_macros[$templateid])) ? $this->db_template_macros[$templateid][$macro] : null; } /** * Get macro ID by host ID and macro name. * * @param string $hostid * @param string $macro * * @return string|null */ public function findHostMacroid(string $hostid, string $macro): ?string { if ($this->db_host_macros === null) { $this->selectHostMacros(); } return (array_key_exists($hostid, $this->db_host_macros) && array_key_exists($macro, $this->db_host_macros[$hostid])) ? $this->db_host_macros[$hostid][$macro] : null; } /** * Get macro ID by host prototype ID and macro name. * * @param string $hostid * @param string $macro * * @return string|null */ public function findHostPrototypeMacroid(string $hostid, string $macro): ?string { if ($this->db_host_prototype_macros === null) { $this->selectHostPrototypeMacros(); } return (array_key_exists($hostid, $this->db_host_prototype_macros) && array_key_exists($macro, $this->db_host_prototype_macros[$hostid])) ? $this->db_host_prototype_macros[$hostid][$macro] : null; } /** * Get proxy ID by name. * * @param string $host * * @return string|null */ public function findProxyidByHost(string $host): ?string { if ($this->db_proxies === null) { $this->selectProxies(); } foreach ($this->db_proxies as $proxyid => $proxy) { if ($proxy['host'] === $host) { return $proxyid; } } return null; } /** * Get host prototype ID by UUID. * * @param string $uuid * * @return string|null */ public function findHostPrototypeidByUuid(string $uuid): ?string { if ($this->db_host_prototypes === null) { $this->selectHostPrototypes(); } foreach ($this->db_host_prototypes as $host_prototypeid => $host_prototype) { if ($host_prototype['uuid'] === $uuid) { return $host_prototypeid; } } return null; } /** * Get host prototype ID by host. * * @param string $parent_hostid * @param string $discovery_ruleid * @param string $host * * @return string|null */ public function findHostPrototypeidByHost(string $parent_hostid, string $discovery_ruleid, string $host): ?string { if ($this->db_host_prototypes === null) { $this->selectHostPrototypes(); } foreach ($this->db_host_prototypes as $host_prototypeid => $host_prototype) { if ($host_prototype['parent_hostid'] === $parent_hostid && $host_prototype['discovery_ruleid'] === $discovery_ruleid && $host_prototype['host'] === $host) { return $host_prototypeid; } } return null; } /** * Get httptest ID by web scenario UUID. * * @param string $uuid * * @return string|null */ public function findHttpTestidByUuid(string $uuid): ?string { if ($this->db_httptests === null) { $this->selectHttpTests(); } foreach ($this->db_httptests as $httptestid => $httptest) { if ($httptest['uuid'] === $uuid) { return $httptestid; } } return null; } /** * Get httptest ID by hostid and web scenario name. * * @param string $hostid * @param string $name * * @return string|bool */ public function findHttpTestidByName(string $hostid, string $name): ?string { if ($this->db_httptests === null) { $this->selectHttpTests(); } foreach ($this->db_httptests as $httptestid => $httptest) { if ($httptest['hostid'] === $hostid && $httptest['name'] === $name) { return $httptestid; } } return null; } /** * Get httpstep ID by hostid, httptestid and web scenario step name. * * @param string $hostid * @param string $httptestid * @param string $name * * @return string|null */ public function findHttpStepidByName(string $hostid, string $httptestid, string $name): ?string { if ($this->db_httpsteps === null) { $this->selectHttpSteps(); } foreach ($this->db_httpsteps as $httpstepid => $httpstep) { if ($httpstep['hostid'] === $hostid && $httpstep['name'] === $name && $httpstep['httptestid'] === $httptestid) { return $httpstepid; } } return null; } /** * Add group names that need association with a database group ID. * * @param array $groups */ public function addGroups(array $groups): void { $this->groups = $groups; } /** * Add group name association with group ID. * * @param string $groupid * @param array $group */ public function setDbGroup(string $groupid, array $group): void { $this->db_groups[$groupid] = [ 'uuid' => $group['uuid'], 'name' => $group['name'] ]; } /** * Add templates names that need association with a database template ID. * * @param array $templates */ public function addTemplates(array $templates): void { $this->templates = $templates; } /** * Add template name association with template ID. * * @param string $templateid * @param array $template */ public function setDbTemplate(string $templateid, array $template): void { $this->db_templates[$templateid] = [ 'uuid' => $template['uuid'], 'host' => $template['host'] ]; } /** * Add hosts names that need association with a database host ID. * * @param array $hosts */ public function addHosts(array $hosts): void { $this->hosts = $hosts; } /** * Add host name association with host ID. * * @param string $hostid * @param array $host */ public function setDbHost(string $hostid, array $host): void { $this->db_hosts[$hostid] = [ 'host' => $host['host'] ]; } /** * Add item keys that need association with a database item ID. * * @param array $items */ public function addItems(array $items): void { $this->items = $items; } /** * Add item key association with item ID. * * @param string $itemid * @param array $item */ public function setDbItem(string $itemid, array $item): void { $this->db_items[$itemid] = [ 'hostid' => $item['hostid'], 'uuid' => array_key_exists('uuid', $item) ? $item['uuid'] : '', 'key_' => $item['key_'] ]; } /** * Add value map names that need association with a database value map ID. * * @param array $valuemaps */ public function addValuemaps(array $valuemaps): void { $this->valuemaps = $valuemaps; } /** * Add trigger description/expression/recovery_expression that need association with a database trigger ID. * * @param array $triggers */ public function addTriggers(array $triggers): void { $this->triggers = $triggers; } /** * Add graph names that need association with a database graph ID. * * @param array $graphs */ public function addGraphs(array $graphs): void { $this->graphs = $graphs; } /** * Add trigger name/expression association with trigger ID. * * @param string $triggerid * @param array $trigger */ public function setDbTrigger(string $triggerid, array $trigger): void { $this->db_triggers[$triggerid] = [ 'uuid' => array_key_exists('uuid', $trigger) ? $trigger['uuid'] : '', 'description' => $trigger['description'], 'expression' => $trigger['expression'], 'recovery_expression' => $trigger['recovery_expression'] ]; } /** * Add icon map names that need association with a database icon map ID. * * @param array $iconmaps */ public function addIconmaps(array $iconmaps): void { $this->iconmaps = $iconmaps; } /** * Add icon map names that need association with a database icon map ID. * * @param array $images */ public function addImages(array $images): void { $this->images = $images; } /** * Add image name association with image ID. * * @param string $imageid * @param array $image */ public function setDbImage(string $imageid, array $image): void { $this->db_images[$imageid] = [ 'name' => $image['name'] ]; } /** * Add map names that need association with a database map ID. * * @param array $maps */ public function addMaps(array $maps) { // $this->maps = array_unique(array_merge($this->maps, $maps)); $this->maps = $maps; } /** * Add map name association with map ID. * * @param string $mapid * @param array $map */ public function setDbMap(string $mapid, array $map): void { $this->db_maps[$mapid] =[ 'name' => $map['name'] ]; } /** * Add templated dashboard names that need association with a database dashboard ID. * * @param array $dashboards */ public function addTemplateDashboards(array $dashboards): void { $this->template_dashboards = $dashboards; } /** * Add user macro names that need association with a database macro ID. * * @param array $macros[