// create form $itemForm = new CForm(); $itemForm->setName('items'); $itemForm->addVar('hostid', $this->data['hostid']); $itemForm->addVar('parent_discoveryid', $this->data['parent_discoveryid']); // create table $itemTable = new CTableInfo(_('No item prototypes found.')); $sortLink = new CUrl(); $sortLink->setArgument('parent_discoveryid', $this->data['parent_discoveryid']); $sortLink = $sortLink->getUrl(); $itemTable->setHeader(array(new CCheckBox('all_items', null, "checkAll('" . $itemForm->getName() . "', 'all_items', 'group_itemid');"), make_sorting_header(_('Name'), 'name', $sortLink), make_sorting_header(_('Key'), 'key_', $sortLink), make_sorting_header(_('Interval'), 'delay', $sortLink), make_sorting_header(_('History'), 'history', $sortLink), make_sorting_header(_('Trends'), 'trends', $sortLink), make_sorting_header(_('Type'), 'type', $sortLink), _('Applications'), make_sorting_header(_('Status'), 'status', $sortLink))); foreach ($this->data['items'] as $item) { $description = array(); if (!empty($item['templateid'])) { $template_host = get_realhost_by_itemid($item['templateid']); $templateDiscoveryRuleId = get_realrule_by_itemid_and_hostid($this->data['parent_discoveryid'], $template_host['hostid']); $description[] = new CLink($template_host['name'], '?parent_discoveryid=' . $templateDiscoveryRuleId, 'unknown'); $description[] = NAME_DELIMITER; } $description[] = new CLink($item['name_expanded'], '?form=update&itemid=' . $item['itemid'] . '&parent_discoveryid=' . $this->data['parent_discoveryid']); $status = new CLink(itemIndicator($item['status']), '?group_itemid=' . $item['itemid'] . '&parent_discoveryid=' . $this->data['parent_discoveryid'] . '&go=' . ($item['status'] ? 'activate' : 'disable'), itemIndicatorStyle($item['status'])); if (!empty($item['applications'])) { order_result($item['applications'], 'name'); $applications = zbx_objectValues($item['applications'], 'name'); $applications = implode(', ', $applications); if (empty($applications)) { $applications = '-'; } } else { $applications = '-'; }
$triggerid = $trigger['triggerid']; $trigger['discoveryRuleid'] = $this->data['parent_discoveryid']; // description $description = array(); $trigger['hosts'] = zbx_toHash($trigger['hosts'], 'hostid'); $trigger['items'] = zbx_toHash($trigger['items'], 'itemid'); $trigger['functions'] = zbx_toHash($trigger['functions'], 'functionid'); if ($trigger['templateid'] > 0) { if (!isset($this->data['realHosts'][$triggerid])) { $description[] = new CSpan(empty($this->data['parent_discoveryid']) ? _('Host') : _('Template'), 'unknown'); $description[] = NAME_DELIMITER; } else { $real_hosts = $this->data['realHosts'][$triggerid]; $real_host = reset($real_hosts); if (!empty($this->data['parent_discoveryid'])) { $tpl_disc_ruleid = get_realrule_by_itemid_and_hostid($this->data['parent_discoveryid'], $real_host['hostid']); $description[] = new CLink(CHtml::encode($real_host['name']), 'trigger_prototypes.php?hostid=' . $real_host['hostid'] . '&parent_discoveryid=' . $tpl_disc_ruleid, 'unknown'); } else { $description[] = new CLink(CHtml::encode($real_host['name']), 'triggers.php?hostid=' . $real_host['hostid'], 'unknown'); } $description[] = NAME_DELIMITER; } } if (empty($this->data['parent_discoveryid'])) { if (!empty($trigger['discoveryRule'])) { $description[] = new CLink(CHtml::encode($trigger['discoveryRule']['name']), 'trigger_prototypes.php?' . 'hostid=' . $this->data['hostid'] . '&parent_discoveryid=' . $trigger['discoveryRule']['itemid'], 'parent-discovery'); $description[] = NAME_DELIMITER . $trigger['description']; } else { $description[] = new CLink(CHtml::encode($trigger['description']), 'triggers.php?form=update&hostid=' . $this->data['hostid'] . '&triggerid=' . $triggerid); } $dependencies = $trigger['dependencies'];
function get_realrule_by_itemid_and_hostid($itemid, $hostid) { $item = get_item_by_itemid($itemid); if (bccomp($hostid, $item['hostid']) == 0) { return $item['itemid']; } if ($item['templateid'] != 0) { return get_realrule_by_itemid_and_hostid($item['templateid'], $hostid); } return $item['itemid']; }
$data['hostPrototypes'] = API::HostPrototype()->get(array('discoveryids' => $data['parent_discoveryid'], 'output' => API_OUTPUT_EXTEND, 'selectTemplates' => array('templateid', 'name'), 'editable' => true, 'sortfield' => $sortField, 'limit' => $config['search_limit'] + 1)); order_result($data['hostPrototypes'], $sortField, $sortOrder); $data['paging'] = getPagingLine($data['hostPrototypes'], $sortOrder); // fetch templates linked to the prototypes $templateIds = array(); foreach ($data['hostPrototypes'] as $hostPrototype) { $templateIds = array_merge($templateIds, zbx_objectValues($hostPrototype['templates'], 'templateid')); } $templateIds = array_unique($templateIds); $linkedTemplates = API::Template()->get(array('output' => array('templateid', 'name'), 'templateids' => $templateIds, 'selectParentTemplates' => array('hostid', 'name'))); $data['linkedTemplates'] = zbx_toHash($linkedTemplates, 'templateid'); // fetch source templates and LLD rules $hostPrototypeSourceIds = getHostPrototypeSourceParentIds(zbx_objectValues($data['hostPrototypes'], 'hostid')); if ($hostPrototypeSourceIds) { $hostPrototypeSourceTemplates = DBfetchArrayAssoc(DBSelect('SELECT h.hostid,h2.name,h2.hostid AS parent_hostid' . ' FROM hosts h,host_discovery hd,items i,hosts h2' . ' WHERE h.hostid=hd.hostid' . ' AND hd.parent_itemid=i.itemid' . ' AND i.hostid=h2.hostid' . ' AND ' . dbConditionInt('h.hostid', $hostPrototypeSourceIds)), 'hostid'); foreach ($data['hostPrototypes'] as &$hostPrototype) { if ($hostPrototype['templateid']) { $sourceTemplate = $hostPrototypeSourceTemplates[$hostPrototypeSourceIds[$hostPrototype['hostid']]]; $hostPrototype['sourceTemplate'] = array('hostid' => $sourceTemplate['parent_hostid'], 'name' => $sourceTemplate['name']); $sourceDiscoveryRuleId = get_realrule_by_itemid_and_hostid($discoveryRule['itemid'], $sourceTemplate['hostid']); $hostPrototype['sourceDiscoveryRuleId'] = $sourceDiscoveryRuleId; } } unset($hostPrototype); } // render view $itemView = new CView('configuration.host.prototype.list', $data); $itemView->render(); $itemView->show(); } require_once dirname(__FILE__) . '/include/page_footer.php';