reference_name -> interfaceid) */ public $interfaces_cache = []; protected $template_groups = []; protected $host_groups = []; protected $templates = []; protected $hosts = []; protected $items = []; protected $valuemaps = []; protected $triggers = []; protected $graphs = []; protected $iconmaps = []; protected $images = []; protected $maps = []; protected $services = []; protected $slas = []; protected $users = []; protected $actions = []; protected $media_types = []; protected $template_dashboards = []; protected $template_macros = []; protected $host_macros = []; protected $host_prototype_macros = []; protected $proxies = []; protected $host_prototypes = []; protected $httptests = []; protected $httpsteps = []; protected $db_template_groups; protected $db_host_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_services; protected $db_slas; protected $db_users; protected $db_actions; protected $db_media_types; 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 template group ID by group UUID. * * @param string $uuid * * @return string|null */ public function findTemplateGroupidByUuid(string $uuid): ?string { if ($this->db_template_groups === null) { $this->selectTemplateGroups(); } foreach ($this->db_template_groups as $groupid => $group) { if ($group['uuid'] === $uuid) { return $groupid; } } return null; } /** * Get host group ID by group UUID. * * @param string $uuid * * @return string|null */ public function findHostGroupidByUuid(string $uuid): ?string { if ($this->db_host_groups === null) { $this->selectHostGroups(); } foreach ($this->db_host_groups as $groupid => $group) { if ($group['uuid'] === $uuid) { return $groupid; } } return null; } /** * Get template group ID by group name. * * @param string $name * * @return string|null */ public function findTemplateGroupidByName(string $name): ?string { if ($this->db_template_groups === null) { $this->selectTemplateGroups(); } foreach ($this->db_template_groups as $groupid => $group) { if ($group['name'] === $name) { return $groupid; } } return null; } /** * Get host group ID by group name. * * @param string $name * * @return string|null */ public function findHostGroupidByName(string $name): ?string { if ($this->db_host_groups === null) { $this->selectHostGroups(); } foreach ($this->db_host_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 * @param bool $inherited * * @return string|null */ public function findItemidByKey(string $hostid, string $key, bool $inherited = false): ?string { if ($this->db_items === null) { $this->selectItems(); } foreach ($this->db_items as $itemid => $item) { if ($item['hostid'] === $hostid && $item['key_'] === $key && ($inherited || $item['templateid'] == 0)) { 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 * @param bool $inherited * * @return string|null */ public function findTriggeridByName(string $name, string $expression, string $recovery_expression, bool $inherited = false): ?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 && ($inherited || $trigger['templateid'] == 0)) { 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 * @param bool $inherited * * @return string|null */ public function findGraphidByName(string $hostid, string $name, bool $inherited = false): ?string { if ($this->db_graphs === null) { $this->selectGraphs(); } foreach ($this->db_graphs as $graphid => $graph) { if ($graph['name'] === $name && in_array($hostid, $graph['hosts']) && ($inherited || $graph['templateid'] == 0)) { 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 service ID by name. * * @param string $name * * @return string|null */ public function findServiceidByName(string $name): ?string { if ($this->db_services === null) { $this->selectServices(); } foreach ($this->db_services as $serviceid => $service) { if ($service['name'] === $name) { return $serviceid; } } return null; } /** * Get action ID by name. * * @param string $name * * @return string|null */ public function findSlaidByName(string $name): ?string { if ($this->db_slas === null) { $this->selectSlas(); } foreach ($this->db_slas as $slaid => $sla) { if ($sla['name'] === $name) { return $slaid; } } return null; } /** * Get user ID by username. * * @param string $username * * @return string|null */ public function findUseridByUsername(string $username): ?string { if ($this->db_users === null) { $this->selectUsers(); } foreach ($this->db_users as $userid => $user) { if ($user['username'] === $username) { return $userid; } } return null; } /** * Get action ID by name. * * @param string $name * * @return string|null */ public function findActionidByName(string $name): ?string { if ($this->db_actions === null) { $this->selectActions(); } foreach ($this->db_actions as $actionid => $action) { if ($action['name'] === $name) { return $actionid; } } return null; } /** * Get media type ID by name. * * @param string $name * * @return string|null */ public function findMediaTypeidByName(string $name): ?string { if ($this->db_media_types === null) { $this->selectMediaTypes(); } foreach ($this->db_media_types as $mediatypeid => $media_type) { if ($media_type['name'] === $name) { return $mediatypeid; } } 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 template dashboard ID by dashboard name and template ID. * * @param string $name * @param int $templateid * * @return string|null */ public function findTemplateDashboardidByNameAndId(string $name, int $templateid): ?string { if ($this->db_template_dashboards === null) { $this->selectTemplateDashboards(); } foreach ($this->db_template_dashboards as $dashboardid => $dashboard) { if ($dashboard['name'] === $name && $dashboard['templateid'] == $templateid) { 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 $name * * @return string|null */ public function findProxyidByName(string $name): ?string { if ($this->db_proxies === null) { $this->selectProxies(); } foreach ($this->db_proxies as $proxyid => $proxy) { if ($proxy['name'] === $name) { 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 template group names that need association with a database group ID. * * @param array $groups */ public function addTemplateGroups(array $groups): void { $this->template_groups = $groups; } /** * Add host group names that need association with a database group ID. * * @param array $groups */ public function addHostGroups(array $groups): void { $this->host_groups = $groups; } /** * Add template group name association with group ID. * * @param string $groupid * @param array $group */ public function setDbTemplateGroup(string $groupid, array $group): void { $this->db_template_groups[$groupid] = [ 'uuid' => $group['uuid'], 'name' => $group['name'] ]; } /** * Add host group name association with group ID. * * @param string $groupid * @param array $group */ public function setDbHostGroup(string $groupid, array $group): void { $this->db_host_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_'], 'templateid' => 0 ]; } /** * 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'], 'templateid' => 0 ]; } /** * 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 = $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 service names that need association with a database service ID. * * @param array $services */ public function addServices(array $services) { $this->services = $services; } /** * Add sla names that need association with a database sla ID. * * @param array $slas */ public function addSlas(array $slas) { $this->slas = $slas; } /** * Add user usernames that need association with a database user ID. * * @param array $users */ public function addUsers(array $users) { $this->users = $users; } /** * Add action names that need association with a database action ID. * * @param array $actions */ public function addActions(array $actions) { $this->actions = $actions; } /** * Add media type names that need association with a database media type ID. * * @param array $media_types */ public function addMediaTypes(array $media_types) { $this->media_types = $media_types; } /** * 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[