$itemsWidget->addItem(get_header_host_table('items', $this->data['hostid'], $this->data['parent_discoveryid'])); // 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 = '-';
function get_realhost_by_itemid($itemid) { $item = get_item_by_itemid($itemid); if ($item['templateid'] != 0) { return get_realhost_by_itemid($item['templateid']); // attention recursion! } return get_host_by_itemid($itemid); }
$discoveryWidget->addHeaderRowNumber(); $discoveryWidget->addItem(get_header_host_table('discoveries', $this->data['hostid'])); // create form $discoveryForm = new CForm(); $discoveryForm->setName('discovery'); $discoveryForm->addVar('hostid', $this->data['hostid']); // create table $discoveryTable = new CTableInfo(_('No discovery rules found.')); $sortLink = new CUrl(); $sortLink->setArgument('hostid', $this->data['hostid']); $sortLink = $sortLink->getUrl(); $discoveryTable->setHeader(array(new CCheckBox('all_items', null, "checkAll('" . $discoveryForm->getName() . "', 'all_items', 'g_hostdruleid');"), make_sorting_header(_('Name'), 'name', $sortLink), _('Items'), _('Triggers'), _('Graphs'), $data['host']['flags'] == ZBX_FLAG_DISCOVERY_NORMAL ? _('Hosts') : null, make_sorting_header(_('Key'), 'key_', $sortLink), make_sorting_header(_('Interval'), 'delay', $sortLink), make_sorting_header(_('Type'), 'type', $sortLink), make_sorting_header(_('Status'), 'status', $sortLink), $data['showErrorColumn'] ? _('Error') : null)); foreach ($data['discoveries'] as $discovery) { $description = array(); if ($discovery['templateid']) { $template_host = get_realhost_by_itemid($discovery['templateid']); $description[] = new CLink($template_host['name'], '?hostid=' . $template_host['hostid'], 'unknown'); $description[] = NAME_DELIMITER; } $discovery['name_expanded'] = itemName($discovery); $description[] = new CLink($discovery['name_expanded'], '?form=update&itemid=' . $discovery['itemid']); $status = new CLink(itemIndicator($discovery['status'], $discovery['state']), '?hostid=' . $_REQUEST['hostid'] . '&g_hostdruleid=' . $discovery['itemid'] . '&go=' . ($discovery['status'] ? 'activate' : 'disable'), itemIndicatorStyle($discovery['status'], $discovery['state'])); if ($data['showErrorColumn']) { $error = ''; if ($discovery['status'] == ITEM_STATUS_ACTIVE) { if (zbx_empty($discovery['error'])) { $error = new CDiv(SPACE, 'status_icon iconok'); } else { $error = new CDiv(SPACE, 'status_icon iconerror'); $error->setHint($discovery['error'], '', 'on'); }
// header $discoveryWidget->addHeader(_('Discovery rules')); $discoveryWidget->addHeaderRowNumber(); $discoveryWidget->addItem(get_header_host_table('discoveries', $this->data['hostid'])); // create form $discoveryForm = new CForm(); $discoveryForm->setName('discovery'); $discoveryForm->addVar('hostid', $this->data['hostid']); // create table $discoveryTable = new CTableInfo(_('No discovery rules found.')); $discoveryTable->setHeader(array(new CCheckBox('all_items', null, "checkAll('" . $discoveryForm->getName() . "', 'all_items', 'g_hostdruleid');"), make_sorting_header(_('Name'), 'name', $this->data['sort'], $this->data['sortorder']), _('Items'), _('Triggers'), _('Graphs'), $data['host']['flags'] == ZBX_FLAG_DISCOVERY_NORMAL ? _('Hosts') : null, make_sorting_header(_('Key'), 'key_', $this->data['sort'], $this->data['sortorder']), make_sorting_header(_('Interval'), 'delay', $this->data['sort'], $this->data['sortorder']), make_sorting_header(_('Type'), 'type', $this->data['sort'], $this->data['sortorder']), make_sorting_header(_('Status'), 'status', $this->data['sort'], $this->data['sortorder']), $data['showInfoColumn'] ? _('Info') : null)); foreach ($data['discoveries'] as $discovery) { // description $description = array(); if ($discovery['templateid']) { $dbTemplate = get_realhost_by_itemid($discovery['templateid']); $description[] = new CLink($dbTemplate['name'], '?hostid=' . $dbTemplate['hostid'], 'unknown'); $description[] = NAME_DELIMITER; } $description[] = new CLink($discovery['name_expanded'], '?form=update&itemid=' . $discovery['itemid']); // status $status = new CLink(itemIndicator($discovery['status'], $discovery['state']), '?hostid=' . $_REQUEST['hostid'] . '&g_hostdruleid=' . $discovery['itemid'] . '&action=' . ($discovery['status'] == ITEM_STATUS_DISABLED ? 'discoveryrule.massenable' : 'discoveryrule.massdisable'), itemIndicatorStyle($discovery['status'], $discovery['state'])); // info if ($data['showInfoColumn']) { if ($discovery['status'] == ITEM_STATUS_ACTIVE && !zbx_empty($discovery['error'])) { $info = new CDiv(SPACE, 'status_icon iconerror'); $info->setHint($discovery['error'], 'on'); } else { $info = ''; } } else {
$description = get_request('description', ''); $expressions = get_request('expressions', array()); $type = get_request('type', 0); $priority = get_request('priority', 0); $comments = get_request('comments', ''); $url = get_request('url', ''); $status = get_request('status', 0); } $keys = get_request('keys', array()); $frmTRLog->addRow(_('Description'), new CTextBox('description', $description, 80)); $itemName = ''; $dbItems = DBfetchArray(DBselect('SELECT itemid,hostid,name,key_,templateid' . ' FROM items' . ' WHERE itemid=' . zbx_dbstr($itemid))); $dbItems = CMacrosResolverHelper::resolveItemNames($dbItems); $dbItem = reset($dbItems); if ($dbItem['templateid']) { $template = get_realhost_by_itemid($dbItem['templateid']); $itemName = $template['host'] . NAME_DELIMITER . $dbItem['name_expanded']; } else { $itemName = $dbItem['name_expanded']; } $ctb = new CTextBox('item', $itemName, 80); $ctb->setAttribute('id', 'item'); $ctb->setAttribute('disabled', 'disabled'); $script = "javascript: return PopUp('popup.php?dstfrm=" . $frmTRLog->getName() . "&dstfld1=itemid&dstfld2=item&srctbl=items&srcfld1=itemid&srcfld2=name',800,450);"; $cbtn = new CSubmit('select_item', _('Select'), $script); $frmTRLog->addRow(_('Item'), array($ctb, $cbtn)); $frmTRLog->addVar('itemid', $itemid); $exp_select = new CComboBox('expr_type'); $exp_select->setAttribute('id', 'expr_type'); $exp_select->addItem(REGEXP_INCLUDE, _('Include')); $exp_select->addItem(REGEXP_EXCLUDE, _('Exclude'));
function get_realhost_by_itemid($itemid) { $item = get_item_by_itemid($itemid); if ($item['templateid'] != 0) { return get_realhost_by_itemid($item['templateid']); } return get_host_by_itemid($itemid); }