} elseif ($pageFilter->groupid > 0) { $options['groupids'] = $pageFilter->groupid; } $httpTests = API::HttpTest()->get($options); $paging = getPagingLine($httpTests); $httpTests = API::HttpTest()->get(array('httptestids' => zbx_objectValues($httpTests, 'httptestid'), 'preservekeys' => true, 'output' => API_OUTPUT_EXTEND, 'selectHosts' => array('name', 'status'), 'selectSteps' => API_OUTPUT_COUNT)); foreach ($httpTests as &$httpTest) { $httpTest['host'] = reset($httpTest['hosts']); $httpTest['hostname'] = $httpTest['host']['name']; unset($httpTest['hosts']); } unset($httpTest); $httpTests = resolveHttpTestMacros($httpTests, true, false); order_result($httpTests, getPageSortField('name'), getPageSortOrder()); // fetch the latest results of the web scenario $lastHttpTestData = Manager::HttpTest()->getLastData(array_keys($httpTests)); foreach ($httpTests as $httpTest) { $lastData = isset($lastHttpTestData[$httpTest['httptestid']]) ? $lastHttpTestData[$httpTest['httptestid']] : null; // test has history data if ($lastData) { $lastcheck = zbx_date2str(_('d M Y H:i:s'), $lastData['lastcheck']); if ($lastData['lastfailedstep'] != 0) { $step_data = get_httpstep_by_no($httpTest['httptestid'], $lastData['lastfailedstep']); $status['msg'] = _s('Step "%1$s" [%2$s of %3$s] failed: %4$s', $step_data['name'], $lastData['lastfailedstep'], $httpTest['steps'], $lastData['error']); $status['style'] = 'disabled'; } else { $status['msg'] = _('OK'); $status['style'] = 'enabled'; } } else { $lastcheck = _('Never');
/** * Update web scenario. * * @param $httpTests * * @return array */ public function update($httpTests) { $httpTests = zbx_toArray($httpTests); if (!$httpTests) { self::exception(ZBX_API_ERROR_PARAMETERS, _('Empty input parameters.')); } $this->checkObjectIds($httpTests, 'httptestid', _('No "%1$s" given for web scenario.'), _('Empty web scenario ID.'), _('Incorrect web scenario ID.')); $httpTests = zbx_toHash($httpTests, 'httptestid'); $dbHttpTests = array(); $dbCursor = DBselect('SELECT ht.httptestid,ht.hostid,ht.templateid,ht.name,' . 'ht.ssl_cert_file,ht.ssl_key_file,ht.ssl_key_password,ht.verify_peer,ht.verify_host' . ' FROM httptest ht' . ' WHERE ' . dbConditionInt('ht.httptestid', array_keys($httpTests))); while ($dbHttpTest = DBfetch($dbCursor)) { $dbHttpTests[$dbHttpTest['httptestid']] = $dbHttpTest; } $dbCursor = DBselect('SELECT hs.httpstepid,hs.httptestid,hs.name' . ' FROM httpstep hs' . ' WHERE ' . dbConditionInt('hs.httptestid', array_keys($dbHttpTests))); while ($dbHttpStep = DBfetch($dbCursor)) { $dbHttpTests[$dbHttpStep['httptestid']]['steps'][$dbHttpStep['httpstepid']] = $dbHttpStep; } $httpTests = $this->validateUpdate($httpTests, $dbHttpTests); Manager::HttpTest()->persist($httpTests); return array('httptestids' => array_keys($httpTests)); }
/** * Create and return a DIV with web monitoring overview. * * @param array $filter * @param array $filter['groupids'] * @param bool $filter['maintenance'] * * @return CDiv */ function make_webmon_overview($filter) { $groups = API::HostGroup()->get(array('groupids' => $filter['groupids'], 'hostids' => isset($filter['hostids']) ? $filter['hostids'] : null, 'monitored_hosts' => true, 'with_monitored_httptests' => true, 'output' => array('groupid', 'name'), 'preservekeys' => true)); foreach ($groups as &$group) { $group['nodename'] = get_node_name_by_elid($group['groupid']); } unset($group); CArrayHelper::sort($groups, array(array('field' => 'nodename', 'order' => ZBX_SORT_UP), array('field' => 'name', 'order' => ZBX_SORT_UP))); $groupIds = array_keys($groups); $availableHosts = API::Host()->get(array('groupids' => $groupIds, 'hostids' => isset($filter['hostids']) ? $filter['hostids'] : null, 'monitored_hosts' => true, 'filter' => array('maintenance_status' => $filter['maintenance']), 'output' => array('hostid'), 'preservekeys' => true)); $availableHostIds = array_keys($availableHosts); $table = new CTableInfo(_('No web scenarios found.')); $table->setHeader(array(is_show_all_nodes() ? _('Node') : null, _('Host group'), _('Ok'), _('Failed'), _('Unknown'))); $data = array(); // fetch links between HTTP tests and host groups $result = DbFetchArray(DBselect('SELECT DISTINCT ht.httptestid,hg.groupid' . ' FROM httptest ht,hosts_groups hg' . ' WHERE ht.hostid=hg.hostid' . ' AND ' . dbConditionInt('hg.hostid', $availableHostIds) . ' AND ' . dbConditionInt('hg.groupid', $groupIds))); // fetch HTTP test execution data $httpTestData = Manager::HttpTest()->getLastData(zbx_objectValues($result, 'httptestid')); foreach ($result as $row) { if (!isset($httpTestData[$row['httptestid']])) { $data[$row['groupid']]['unknown'] = empty($data[$row['groupid']]['unknown']) ? 1 : ++$data[$row['groupid']]['unknown']; } elseif ($httpTestData[$row['httptestid']]['lastfailedstep'] != 0) { $data[$row['groupid']]['failed'] = empty($data[$row['groupid']]['failed']) ? 1 : ++$data[$row['groupid']]['failed']; } else { $data[$row['groupid']]['ok'] = empty($data[$row['groupid']]['ok']) ? 1 : ++$data[$row['groupid']]['ok']; } } foreach ($groups as $group) { if (!empty($data[$group['groupid']])) { $table->addRow(array(is_show_all_nodes() ? $group['nodename'] : null, $group['name'], new CSpan(empty($data[$group['groupid']]['ok']) ? 0 : $data[$group['groupid']]['ok'], 'off'), new CSpan(empty($data[$group['groupid']]['failed']) ? 0 : $data[$group['groupid']]['failed'], empty($data[$group['groupid']]['failed']) ? 'off' : 'on'), new CSpan(empty($data[$group['groupid']]['unknown']) ? 0 : $data[$group['groupid']]['unknown'], 'unknown'))); } } $script = new CJSScript(get_js("jQuery('#hat_webovr_footer').html('" . _s('Updated: %s', zbx_date2str(_('H:i:s'))) . "')")); return new CDiv(array($table, $script)); }
if ($page['type'] == PAGE_TYPE_JS || $page['type'] == PAGE_TYPE_HTML_BLOCK) { require_once dirname(__FILE__) . '/include/page_footer.php'; exit; } /* * Collect data */ $httpTest = API::HttpTest()->get(array('httptestids' => get_request('httptestid'), 'output' => API_OUTPUT_EXTEND, 'preservekeys' => true)); $httpTest = reset($httpTest); if (!$httpTest) { access_deny(); } $httpTest['lastfailedstep'] = 0; $httpTest['error'] = ''; // fetch http test execution data $httpTestData = Manager::HttpTest()->getLastData(array($httpTest['httptestid'])); if ($httpTestData) { $httpTestData = reset($httpTestData); } // fetch HTTP step items $query = DBselect('SELECT i.value_type,i.valuemapid,i.units,i.itemid,hi.type AS httpitem_type,hs.httpstepid' . ' FROM items i,httpstepitem hi,httpstep hs' . ' WHERE hi.itemid=i.itemid' . ' AND hi.httpstepid=hs.httpstepid' . ' AND hs.httptestid=' . zbx_dbstr($httpTest['httptestid'])); $httpStepItems = array(); $items = array(); while ($item = DBfetch($query)) { $items[] = $item; $httpStepItems[$item['httpstepid']][$item['httpitem_type']] = $item; } // fetch HTTP item history $itemHistory = Manager::History()->getLast($items); /* * Display
/** * Update web scenario. * * @param $httpTests * * @return array */ public function update($httpTests) { $httpTests = zbx_toArray($httpTests); $httpTests = zbx_toHash($httpTests, 'httptestid'); foreach ($httpTests as $hnum => $httpTest) { unset($httpTests[$hnum]['templateid']); // convert deprecated parameters $httpTests[$hnum] = $this->convertDeprecatedParam($httpTest, 'macros', 'variables'); if (isset($httpTest['steps'])) { foreach ($httpTest['steps'] as $i => $step) { $httpTests[$hnum]['steps'][$i] = $this->convertDeprecatedParam($step, 'webstepid', 'httpstepid'); } } } $dbHttpTests = array(); $dbCursor = DBselect('SELECT ht.httptestid,ht.hostid,ht.templateid,ht.name' . ' FROM httptest ht' . ' WHERE ' . dbConditionInt('ht.httptestid', array_keys($httpTests))); while ($dbHttpTest = DBfetch($dbCursor)) { $dbHttpTests[$dbHttpTest['httptestid']] = $dbHttpTest; } $dbCursor = DBselect('SELECT hs.httpstepid,hs.httptestid,hs.name' . ' FROM httpstep hs' . ' WHERE ' . dbConditionInt('hs.httptestid', array_keys($dbHttpTests))); while ($dbHttpStep = DBfetch($dbCursor)) { $dbHttpTests[$dbHttpStep['httptestid']]['steps'][$dbHttpStep['httpstepid']] = $dbHttpStep; } // add hostid if missing // add test name and steps names if it's empty or test is templated // unset steps no for templated tests foreach ($httpTests as $tnum => $httpTest) { $test =& $httpTests[$tnum]; $dbTest = $dbHttpTests[$httpTest['httptestid']]; $test['hostid'] = $dbTest['hostid']; if (!isset($test['name']) || zbx_empty($test['name']) || !empty($dbTest['templateid'])) { $test['name'] = $dbTest['name']; } if (array_key_exists('steps', $test) && is_array($test['steps'])) { foreach ($test['steps'] as $snum => $step) { if (isset($step['httpstepid']) && (!empty($dbTest['templateid']) || !array_key_exists('name', $step))) { $test['steps'][$snum]['name'] = $dbTest['steps'][$step['httpstepid']]['name']; } if (!empty($dbTest['templateid'])) { unset($test['steps'][$snum]['no']); } } } unset($test); } $this->validateUpdate($httpTests, $dbHttpTests); Manager::HttpTest()->persist($httpTests); return array('httptestids' => zbx_objectValues($httpTests, 'httptestid')); }
/** * Create and return a DIV with web monitoring overview. * * @param array $filter * @param array $filter['groupids'] * @param bool $filter['maintenance'] * * @return CDiv */ function make_webmon_overview($filter) { $groups = API::HostGroup()->get(array('groupids' => $filter['groupids'], 'hostids' => isset($filter['hostids']) ? $filter['hostids'] : null, 'monitored_hosts' => true, 'with_monitored_httptests' => true, 'output' => array('groupid', 'name'), 'preservekeys' => true)); CArrayHelper::sort($groups, array(array('field' => 'name', 'order' => ZBX_SORT_UP))); $groupIds = array_keys($groups); $availableHosts = API::Host()->get(array('groupids' => $groupIds, 'hostids' => isset($filter['hostids']) ? $filter['hostids'] : null, 'monitored_hosts' => true, 'filter' => array('maintenance_status' => $filter['maintenance']), 'output' => array('hostid'), 'preservekeys' => true)); $availableHostIds = array_keys($availableHosts); $table = new CTableInfo(_('No web scenarios found.')); $table->setHeader(array(_('Host group'), _('Ok'), _('Failed'), _('Unknown'))); $data = array(); // fetch links between HTTP tests and host groups $result = DbFetchArray(DBselect('SELECT DISTINCT ht.httptestid,hg.groupid' . ' FROM httptest ht,hosts_groups hg' . ' WHERE ht.hostid=hg.hostid' . ' AND ' . dbConditionInt('hg.hostid', $availableHostIds) . ' AND ' . dbConditionInt('hg.groupid', $groupIds) . ' AND ht.status=' . HTTPTEST_STATUS_ACTIVE)); // fetch HTTP test execution data $httpTestData = Manager::HttpTest()->getLastData(zbx_objectValues($result, 'httptestid')); foreach ($result as $row) { if (isset($httpTestData[$row['httptestid']]) && $httpTestData[$row['httptestid']]['lastfailedstep'] !== null) { if ($httpTestData[$row['httptestid']]['lastfailedstep'] != 0) { $data[$row['groupid']]['failed'] = isset($data[$row['groupid']]['failed']) ? ++$data[$row['groupid']]['failed'] : 1; } else { $data[$row['groupid']]['ok'] = isset($data[$row['groupid']]['ok']) ? ++$data[$row['groupid']]['ok'] : 1; } } else { $data[$row['groupid']]['unknown'] = isset($data[$row['groupid']]['unknown']) ? ++$data[$row['groupid']]['unknown'] : 1; } } foreach ($groups as $group) { if (!empty($data[$group['groupid']])) { $table->addRow(array(new CLink($group['name'], 'httpmon.php?groupid=' . $group['groupid'] . '&hostid=0'), new CSpan(empty($data[$group['groupid']]['ok']) ? 0 : $data[$group['groupid']]['ok'], 'off'), new CSpan(empty($data[$group['groupid']]['failed']) ? 0 : $data[$group['groupid']]['failed'], empty($data[$group['groupid']]['failed']) ? 'off' : 'on'), new CSpan(empty($data[$group['groupid']]['unknown']) ? 0 : $data[$group['groupid']]['unknown'], 'unknown'))); } } $script = new CJsScript(get_js('jQuery("#' . WIDGET_WEB_OVERVIEW . '_footer").html("' . _s('Updated: %s', zbx_date2str(TIME_FORMAT_SECONDS)) . '");')); return new CDiv(array($table, $script)); }
protected function link(array $templateIds, array $targetIds) { $hostsLinkageInserts = parent::link($templateIds, $targetIds); foreach ($hostsLinkageInserts as $hostTplIds) { Manager::Application()->link($hostTplIds['templateid'], $hostTplIds['hostid']); API::DiscoveryRule()->syncTemplates(array('hostids' => $hostTplIds['hostid'], 'templateids' => $hostTplIds['templateid'])); API::Itemprototype()->syncTemplates(array('hostids' => $hostTplIds['hostid'], 'templateids' => $hostTplIds['templateid'])); API::HostPrototype()->syncTemplates(array('hostids' => $hostTplIds['hostid'], 'templateids' => $hostTplIds['templateid'])); API::Item()->syncTemplates(array('hostids' => $hostTplIds['hostid'], 'templateids' => $hostTplIds['templateid'])); Manager::HttpTest()->link($hostTplIds['templateid'], $hostTplIds['hostid']); } // we do linkage in two separate loops because for triggers you need all items already created on host foreach ($hostsLinkageInserts as $hostTplIds) { API::Trigger()->syncTemplates(array('hostids' => $hostTplIds['hostid'], 'templateids' => $hostTplIds['templateid'])); API::TriggerPrototype()->syncTemplates(array('hostids' => $hostTplIds['hostid'], 'templateids' => $hostTplIds['templateid'])); API::GraphPrototype()->syncTemplates(array('hostids' => $hostTplIds['hostid'], 'templateids' => $hostTplIds['templateid'])); API::Graph()->syncTemplates(array('hostids' => $hostTplIds['hostid'], 'templateids' => $hostTplIds['templateid'])); } foreach ($hostsLinkageInserts as $hostTplIds) { API::Trigger()->syncTemplateDependencies(array('templateids' => $hostTplIds['templateid'], 'hostids' => $hostTplIds['hostid'])); } return $hostsLinkageInserts; }
/** * Process screen. * * @return CDiv (screen inside container) */ public function get() { $this->dataId = 'httptest_details'; $httptest = API::HttpTest()->get(['output' => ['httptestid', 'name', 'hostid'], 'selectSteps' => ['httpstepid', 'name', 'no'], 'httptestids' => $this->profileIdx2, 'preservekeys' => true]); $httptest = reset($httptest); if (!$httptest) { $messages = [['type' => 'error', 'message' => _('No permissions to referred object or it does not exist!')]]; return $this->getOutput(makeMessageBox(false, $messages, null, false, false)); } $httptest['lastfailedstep'] = 0; $httptest['error'] = ''; // fetch http test execution data $httptest_data = Manager::HttpTest()->getLastData([$httptest['httptestid']]); if ($httptest_data) { $httptest_data = reset($httptest_data); } // fetch HTTP step items $items = DBfetchArray(DBselect('SELECT i.value_type,i.valuemapid,i.units,i.itemid,hi.type,hs.httpstepid' . ' FROM items i,httpstepitem hi,httpstep hs' . ' WHERE hi.itemid=i.itemid' . ' AND hi.httpstepid=hs.httpstepid' . ' AND hs.httptestid=' . zbx_dbstr($httptest['httptestid']))); $step_items = []; foreach ($items as $item) { $step_items[$item['httpstepid']][$item['type']] = $item; } // fetch HTTP item history $item_history = Manager::History()->getLast($items); $table = (new CTableInfo())->setHeader([_('Step'), _('Speed'), _('Response time'), _('Response code'), _('Status')]); $total_time = ['value' => 0, 'value_type' => null, 'valuemapid' => null, 'units' => null]; order_result($httptest['steps'], 'no'); foreach ($httptest['steps'] as $step_data) { $items_by_type = $step_items[$step_data['httpstepid']]; $status['msg'] = _('OK'); $status['style'] = ZBX_STYLE_GREEN; $status['afterError'] = false; if (!array_key_exists('lastfailedstep', $httptest_data)) { $status['msg'] = _('Never executed'); $status['style'] = ZBX_STYLE_GREY; } elseif ($httptest_data['lastfailedstep'] != 0) { if ($httptest_data['lastfailedstep'] == $step_data['no']) { $status['msg'] = $httptest_data['error'] === null ? _('Unknown error') : _s('Error: %1$s', $httptest_data['error']); $status['style'] = ZBX_STYLE_RED; } elseif ($httptest_data['lastfailedstep'] < $step_data['no']) { $status['msg'] = _('Unknown'); $status['style'] = ZBX_STYLE_GREY; $status['afterError'] = true; } } foreach ($items_by_type as &$item) { // Calculate the total time it took to execute the scenario. // Skip steps that come after a failed step. if (!$status['afterError'] && $item['type'] == HTTPSTEP_ITEM_TYPE_TIME) { $total_time['value_type'] = $item['value_type']; $total_time['valuemapid'] = $item['valuemapid']; $total_time['units'] = $item['units']; if (array_key_exists($item['itemid'], $item_history)) { $history = $item_history[$item['itemid']][0]; $total_time['value'] += $history['value']; } } } unset($item); // step speed $speed_item = $items_by_type[HTTPSTEP_ITEM_TYPE_IN]; if (!$status['afterError'] && array_key_exists($speed_item['itemid'], $item_history) && $item_history[$speed_item['itemid']][0]['value'] > 0) { $speed = formatHistoryValue($item_history[$speed_item['itemid']][0]['value'], $speed_item); } else { $speed = UNKNOWN_VALUE; } // step response time $resptime_item = $items_by_type[HTTPSTEP_ITEM_TYPE_TIME]; if (!$status['afterError'] && array_key_exists($resptime_item['itemid'], $item_history) && $item_history[$resptime_item['itemid']][0]['value'] > 0) { $resp_time = formatHistoryValue($item_history[$resptime_item['itemid']][0]['value'], $resptime_item); } else { $resp_time = UNKNOWN_VALUE; } // step response code $resp_item = $items_by_type[HTTPSTEP_ITEM_TYPE_RSPCODE]; if (!$status['afterError'] && array_key_exists($resp_item['itemid'], $item_history) && $item_history[$resp_item['itemid']][0]['value'] > 0) { $resp = formatHistoryValue($item_history[$resp_item['itemid']][0]['value'], $resp_item); } else { $resp = UNKNOWN_VALUE; } $table->addRow([CMacrosResolverHelper::resolveHttpTestName($httptest['hostid'], $step_data['name']), $speed, $resp_time, $resp, (new CSpan($status['msg']))->addClass($status['style'])]); } if (!array_key_exists('lastfailedstep', $httptest_data)) { $status['msg'] = _('Never executed'); $status['style'] = ZBX_STYLE_GREY; } elseif ($httptest_data['lastfailedstep'] != 0) { $status['msg'] = $httptest_data['error'] === null ? _('Unknown error') : _s('Error: %1$s', $httptest_data['error']); $status['style'] = ZBX_STYLE_RED; } else { $status['msg'] = _('OK'); $status['style'] = ZBX_STYLE_GREEN; } $table->addRow([bold(_('TOTAL')), '', bold($total_time['value'] ? formatHistoryValue($total_time['value'], $total_time) : UNKNOWN_VALUE), '', (new CSpan($status['msg']))->addClass($status['style'])]); return $this->getOutput($table); }
** GNU General Public License for more details. ** ** You should have received a copy of the GNU General Public License ** along with this program; if not, write to the Free Software ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. **/ $groups = API::HostGroup()->get(['output' => ['groupid', 'name'], 'groupids' => $data['filter']['groupids'], 'hostids' => isset($data['filter']['hostids']) ? $data['filter']['hostids'] : null, 'monitored_hosts' => true, 'with_monitored_httptests' => true, 'preservekeys' => true]); CArrayHelper::sort($groups, ['name']); $groupIds = array_keys($groups); $availableHosts = API::Host()->get(['output' => ['hostid'], 'groupids' => $groupIds, 'hostids' => isset($data['filter']['hostids']) ? $data['filter']['hostids'] : null, 'filter' => ['maintenance_status' => $data['filter']['maintenance']], 'monitored_hosts' => true, 'preservekeys' => true]); $availableHostIds = array_keys($availableHosts); $table_data = []; // fetch links between HTTP tests and host groups $result = DbFetchArray(DBselect('SELECT DISTINCT ht.httptestid,hg.groupid' . ' FROM httptest ht,hosts_groups hg' . ' WHERE ht.hostid=hg.hostid' . ' AND ' . dbConditionInt('hg.hostid', $availableHostIds) . ' AND ' . dbConditionInt('hg.groupid', $groupIds) . ' AND ht.status=' . HTTPTEST_STATUS_ACTIVE)); // fetch HTTP test execution data $httpTestData = Manager::HttpTest()->getLastData(zbx_objectValues($result, 'httptestid')); foreach ($result as $row) { if (!array_key_exists($row['groupid'], $table_data)) { $table_data[$row['groupid']] = ['ok' => 0, 'failed' => 0, 'unknown' => 0]; } if (isset($httpTestData[$row['httptestid']]) && $httpTestData[$row['httptestid']]['lastfailedstep'] !== null) { $table_data[$row['groupid']][$httpTestData[$row['httptestid']]['lastfailedstep'] != 0 ? 'failed' : 'ok']++; } else { $table_data[$row['groupid']]['unknown']++; } } $table = (new CTableInfo())->setHeader([_('Host group'), _('Ok'), _('Failed'), _('Unknown')]); foreach ($groups as $group) { if (array_key_exists($group['groupid'], $table_data)) { $table->addRow([new CLink($group['name'], 'zabbix.php?action=web.view&groupid=' . $group['groupid'] . '&hostid=0'), (new CSpan($table_data[$group['groupid']]['ok']))->addClass(ZBX_STYLE_GREEN), (new CSpan($table_data[$group['groupid']]['failed']))->addClass($table_data[$group['groupid']]['failed'] == 0 ? ZBX_STYLE_GREEN : ZBX_STYLE_RED), (new CSpan($table_data[$group['groupid']]['unknown']))->addClass(ZBX_STYLE_GREY)]); }
protected function link(array $templateIds, array $targetIds) { if (!API::Host()->isWritable($targetIds)) { self::exception(ZBX_API_ERROR_PERMISSIONS, _('No permissions to referred object or it does not exist!')); } $hostsLinkageInserts = parent::link($templateIds, $targetIds); foreach ($hostsLinkageInserts as $hostTplIds) { Manager::Application()->link($hostTplIds['templateid'], $hostTplIds['hostid']); API::DiscoveryRule()->syncTemplates(array('hostids' => $hostTplIds['hostid'], 'templateids' => $hostTplIds['templateid'])); API::Itemprototype()->syncTemplates(array('hostids' => $hostTplIds['hostid'], 'templateids' => $hostTplIds['templateid'])); API::HostPrototype()->syncTemplates(array('hostids' => $hostTplIds['hostid'], 'templateids' => $hostTplIds['templateid'])); API::Item()->syncTemplates(array('hostids' => $hostTplIds['hostid'], 'templateids' => $hostTplIds['templateid'])); Manager::HttpTest()->link($hostTplIds['templateid'], $hostTplIds['hostid']); } // we do linkage in two separate loops because for triggers you need all items already created on host foreach ($hostsLinkageInserts as $hostTplIds) { API::Trigger()->syncTemplates(array('hostids' => $hostTplIds['hostid'], 'templateids' => $hostTplIds['templateid'])); API::TriggerPrototype()->syncTemplates(array('hostids' => $hostTplIds['hostid'], 'templateids' => $hostTplIds['templateid'])); API::GraphPrototype()->syncTemplates(array('hostids' => $hostTplIds['hostid'], 'templateids' => $hostTplIds['templateid'])); API::Graph()->syncTemplates(array('hostids' => $hostTplIds['hostid'], 'templateids' => $hostTplIds['templateid'])); } foreach ($hostsLinkageInserts as $hostTplIds) { API::Trigger()->syncTemplateDependencies(array('templateids' => $hostTplIds['templateid'], 'hostids' => $hostTplIds['hostid'])); } return $hostsLinkageInserts; }