$sql .= ' AND h.hostid=' . $hostid; } $sql .= ' ORDER BY h.host, i.description, i.key_, i.itemid'; $result = DBselect($sql); while ($row = DBfetch($result)) { $row['node_name'] = isset($row['node_name']) ? '(' . $row['node_name'] . ') ' : ''; $row['description'] = item_description($row); $description = new CLink($row['description'], '#', 'action'); $row['description'] = $row['node_name'] . $row['host'] . ':' . $row['description']; if (isset($_REQUEST['reference']) && $_REQUEST['reference'] == 'dashboard') { $action = get_window_opener($dstfrm, $dstfld1, $srctbl) . get_window_opener($dstfrm, $dstfld2, $row[$srcfld2]) . "window.opener.setTimeout('add2favorites();', 1000);"; } else { $action = get_window_opener($dstfrm, $dstfld1, $row[$srcfld1]) . get_window_opener($dstfrm, $dstfld2, $row[$srcfld2]); } $description->SetAction($action . ' close_window(); return false;'); $table->addRow(array($hostid > 0 ? null : $row['host'], $description, item_type2str($row['type']), item_value_type2str($row['value_type']), new CSpan(item_status2str($row['status']), item_status2style($row['status'])))); } $table->Show(); } else { if ('slides' == $srctbl) { require_once 'include/screens.inc.php'; $table = new CTableInfo(S_NO_NODES_DEFINED); $table->SetHeader(S_NAME); $result = DBselect('select slideshowid,name from slideshows where ' . DBin_node('slideshowid', $nodeid) . ' ORDER BY name'); while ($row = DBfetch($result)) { if (!slideshow_accessible($row['slideshowid'], PERM_READ_ONLY)) { continue; } $name = new CLink($row['name'], '#', 'action'); if (isset($_REQUEST['reference']) && $_REQUEST['reference'] == 'dashboard') { $action = get_window_opener($dstfrm, $dstfld1, $srcfld2) . get_window_opener($dstfrm, $dstfld2, $row[$srcfld2]) . "window.opener.setTimeout('add2favorites();', 1000);";
// create table $discoveryTable = new CTableInfo(_('No discovery rules defined.')); $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'), make_sorting_header(_('Key'), 'key_', $sortLink), make_sorting_header(_('Interval'), 'delay', $sortLink), make_sorting_header(_('Type'), 'type', $sortLink), make_sorting_header(_('Status'), 'status', $sortLink), _('Error'))); 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[] = ': '; } $discovery['name_expanded'] = itemName($discovery); $description[] = new CLink($discovery['name_expanded'], '?form=update&itemid=' . $discovery['itemid']); $status = new CLink(item_status2str($discovery['status']), '?hostid=' . $_REQUEST['hostid'] . '&g_hostdruleid=' . $discovery['itemid'] . '&go=' . ($discovery['status'] ? 'activate' : 'disable'), item_status2style($discovery['status'])); 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'); } $discoveryTable->addRow(array(new CCheckBox('g_hostdruleid[' . $discovery['itemid'] . ']', null, null, $discovery['itemid']), $description, array(new CLink(_('Item prototypes'), 'disc_prototypes.php?hostid=' . get_request('hostid') . '&parent_discoveryid=' . $discovery['itemid']), ' (' . $discovery['items'] . ')'), array(new CLink(_('Trigger prototypes'), 'trigger_prototypes.php?hostid=' . get_request('hostid') . '&parent_discoveryid=' . $discovery['itemid']), ' (' . $discovery['triggers'] . ')'), array(new CLink(_('Graph prototypes'), 'graphs.php?hostid=' . get_request('hostid') . '&parent_discoveryid=' . $discovery['itemid']), ' (' . $discovery['graphs'] . ')'), $discovery['key_'], $discovery['delay'], item_type2str($discovery['type']), $status, $error)); } // create go buttons $goComboBox = new CComboBox('go'); $goOption = new CComboItem('activate', _('Enable selected')); $goOption->setAttribute('confirm', _('Enable selected discovery rules?')); $goComboBox->addItem($goOption); $goOption = new CComboItem('disable', _('Disable selected')); $goOption->setAttribute('confirm', _('Disable selected discovery rules?'));
$itemTable->setHeader(array(new CCheckBox('all_items', null, "checkAll('" . $itemForm->getName() . "', 'all_items', 'group_itemid');"), _('Wizard'), empty($this->data['filter_hostname']) ? _('Host') : null, make_sorting_header(_('Name'), 'name'), _('Triggers'), make_sorting_header(_('Key'), 'key_'), make_sorting_header(_('Interval'), 'delay'), make_sorting_header(_('History'), 'history'), make_sorting_header(_('Trends'), 'trends'), make_sorting_header(_('Type'), 'type'), _('Applications'), make_sorting_header(_('Status'), 'status'), _('Error'))); foreach ($this->data['items'] as $item) { // description $description = array(); if (!empty($item['template_host'])) { $description[] = new CLink($item['template_host']['name'], '?hostid=' . $item['template_host']['hostid'] . '&filter_set=1', 'unknown'); $description[] = ':' . SPACE; } if (!empty($item['discoveryRule'])) { $description[] = new CLink($item['discoveryRule']['name'], 'disc_prototypes.php?parent_discoveryid=' . $item['discoveryRule']['itemid'], 'gold'); $description[] = ':' . SPACE . $item['name_expanded']; } else { $description[] = new CLink($item['name_expanded'], '?form=update&hostid=' . $item['hostid'] . '&itemid=' . $item['itemid']); } // status $status = new CCol(new CLink(item_status2str($item['status']), '?group_itemid=' . $item['itemid'] . '&hostid=' . $item['hostid'] . '&go=' . ($item['status'] ? 'activate' : 'disable'), item_status2style($item['status']))); if (zbx_empty($item['error'])) { $error = new CDiv(SPACE, 'status_icon iconok'); } else { $error = new CDiv(SPACE, 'status_icon iconerror'); $error->setHint($item['error'], '', 'on'); } $statusIcons = array($error); // discovered item lifetime indicator if ($item['flags'] == ZBX_FLAG_DISCOVERY_CREATED && $item['itemDiscovery']['ts_delete']) { $deleteError = new CDiv(SPACE, 'status_icon iconwarning'); $deleteError->setHint(_s('The item is not discovered anymore and will be deleted in %1$s (on %2$s at %3$s).', zbx_date2age($item['itemDiscovery']['ts_delete']), zbx_date2str(_('d M Y'), $item['itemDiscovery']['ts_delete']), zbx_date2str(_('H:i:s'), $item['itemDiscovery']['ts_delete']))); $statusIcons[] = $deleteError; } $triggerHintTable = new CTableInfo(); $triggerHintTable->setHeader(array(_('Severity'), _('Name'), _('Expression'), _('Status')));
$values = array(); for ($i = 1; $i <= $dstfldCount; $i++) { $dstfld = get_request('dstfld' . $i); $srcfld = get_request('srcfld' . $i); if (!empty($dstfld) && !empty($item[$srcfld])) { $values[$dstfld] = $item[$srcfld]; } } // if we need to submit parent window $js_action = 'javascript: addValues(' . zbx_jsvalue($dstfrm) . ', ' . zbx_jsvalue($values) . ', ' . ($submitParent ? 'true' : 'false') . '); return false;'; } $description->setAttribute('onclick', $js_action . ' jQuery(this).removeAttr("onclick");'); if ($multiselect) { $description = new CCol(array(new CCheckBox('items[' . zbx_jsValue($item[$srcfld1]) . ']', null, null, $item['itemid']), $description)); } $table->addRow(array($description, $item['key_'], item_type2str($item['type']), itemValueTypeString($item['value_type']), new CSpan(item_status2str($item['status']), item_status2style($item['status'])))); } if ($multiselect) { $button = new CButton('select', _('Select'), "javascript: addSelectedValues('items', " . zbx_jsvalue($reference) . ');'); $table->setFooter(new CCol($button, 'right')); insert_js('var popupReference = ' . zbx_jsvalue($items, true) . ';'); } unset($items); zbx_add_post_js('chkbxRange.pageGoName = "items";'); $form->addItem($table); $form->show(); } elseif ($srctbl == 'applications') { $table = new CTableInfo(_('No applications defined.')); $table->setHeader(array($hostid > 0 ? null : _('Host'), _('Name'))); $options = array('nodeids' => $nodeid, 'hostids' => $hostid, 'output' => API_OUTPUT_EXTEND, 'expandData' => true); if (is_null($hostid)) {
//* $sql = 'SELECT DISTINCT th.host as template_host,th.hostid as template_hostid, h.host, h.hostid, i.* ' . ' FROM ' . implode(',', $from_tables) . ' LEFT JOIN items ti ON i.templateid=ti.itemid ' . ' LEFT JOIN hosts th ON ti.hostid=th.hostid ' . ' WHERE ' . implode(' and ', $where_case) . order_by('h.host,i.description,i.key_,i.delay,i.history,i.trends,i.type,i.status', 'i.itemid'); //*/ $db_items = DBselect($sql); while ($db_item = DBfetch($db_items)) { $description = array(); $item_description = item_description($db_item); if (isset($_REQUEST['filter_description']) && !zbx_stristr($item_description, $_REQUEST['filter_description'])) { continue; } if ($db_item['templateid']) { $template_host = get_realhost_by_itemid($db_item['templateid']); array_push($description, new CLink($template_host['host'], '?' . 'hostid=' . $template_host['hostid'], 'unknown'), ':'); } array_push($description, new CLink(item_description($db_item), '?form=update&itemid=' . $db_item['itemid'] . '&hostid=' . $db_item['hostid'])); $status = new CCol(new CLink(item_status2str($db_item['status']), '?group_itemid%5B%5D=' . $db_item['itemid'] . '&go=' . ($db_item['status'] ? 'activate' : 'disable'), item_status2style($db_item['status']))); if (!zbx_empty($db_item['error'])) { $error = new CDiv(SPACE, 'error_icon'); $error->setHint($db_item['error'], '', 'on'); } else { $error = new CDiv(SPACE, 'ok_icon'); } $applications = $show_applications ? implode(', ', get_applications_by_itemid($db_item['itemid'], 'name')) : null; if (!is_null($applications) && empty($applications)) { $applications = ' - '; } $applications = new CCol($applications, 'wraptext'); $table->addRow(array(new CCheckBox('group_itemid[' . $db_item['itemid'] . ']', null, null, $db_item['itemid']), $show_host ? $db_item['host'] : null, $description, $db_item['key_'], $db_item['delay'], $db_item['history'], $db_item['trends'], item_type2str($db_item['type']), $status, $applications, $error)); $row_count++; } //----- GO ------
// create table $itemTable = new CTableInfo(_('No items prototypes defined.')); $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), make_sorting_header(_('Status'), 'status', $sortLink), _('Applications'))); 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[] = ': '; } $description[] = new CLink(itemName($item), '?form=update&itemid=' . $item['itemid'] . '&parent_discoveryid=' . $this->data['parent_discoveryid']); $status = new CLink(item_status2str($item['status']), '?group_itemid=' . $item['itemid'] . '&parent_discoveryid=' . $this->data['parent_discoveryid'] . '&go=' . ($item['status'] ? 'activate' : 'disable'), item_status2style($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 = '-'; } $itemTable->addRow(array(new CCheckBox('group_itemid[' . $item['itemid'] . ']', null, null, $item['itemid']), $description, $item['key_'], $item['delay'], $item['history'], in_array($item['value_type'], array(ITEM_VALUE_TYPE_STR, ITEM_VALUE_TYPE_LOG, ITEM_VALUE_TYPE_TEXT)) ? '' : $item['trends'], item_type2str($item['type']), $status, new CCol($applications, 'wraptext'))); } // create go buttons $goComboBox = new CComboBox('go'); $goOption = new CComboItem('activate', _('Activate selected'));
order_by('h.host,i.description,i.key_,i.delay,i.history,i.trends,i.type,i.status','i.itemid'); */ $sql = 'SELECT DISTINCT th.host as template_host,th.hostid as template_hostid, h.host, h.hostid, i.* ' . ' FROM ' . implode(',', $from_tables) . ' LEFT JOIN items ti ON i.templateid=ti.itemid ' . ' LEFT JOIN hosts th ON ti.hostid=th.hostid ' . ' WHERE ' . implode(' and ', $where_case) . order_by('h.host,i.description,i.key_,i.delay,i.history,i.trends,i.type,i.status', 'i.itemid'); $db_items = DBselect($sql); while ($db_item = DBfetch($db_items)) { $description = array(); $item_description = item_description($db_item); if (isset($_REQUEST['filter_description']) && !zbx_stristr($item_description, $_REQUEST['filter_description'])) { continue; } if ($db_item['templateid']) { $template_host = get_realhost_by_itemid($db_item['templateid']); array_push($description, new CLink($template_host['host'], '?' . 'hostid=' . $template_host['hostid'], 'unknown'), ':'); } array_push($description, new CLink(item_description($db_item), '?form=update&itemid=' . $db_item['itemid'] . '&hostid=' . $db_item['hostid'], 'action')); $status = new CCol(new CLink(item_status2str($db_item['status']), '?group_itemid%5B%5D=' . $db_item['itemid'] . '&group_task=' . ($db_item['status'] ? 'Activate+selected' : 'Disable+selected'), item_status2style($db_item['status']))); if ($db_item['error'] == '') { $error = new CCol('-', 'off'); } else { $error = new CCol($db_item['error'], 'on'); } $applications = $show_applications ? implode(', ', get_applications_by_itemid($db_item['itemid'], 'name')) : null; if (!is_null($applications) && empty($applications)) { $applications = ' - '; } $chkBox = new CCheckBox('group_itemid[' . $db_item['itemid'] . ']', null, null, $db_item['itemid']); //if($db_item['templateid'] > 0) $chkBox->setEnabled(false); $table->addRow(array($show_host ? $db_item['host'] : null, array($chkBox, $description), $db_item['key_'], $db_item['delay'], $db_item['history'], $db_item['trends'], item_type2str($db_item['type']), $status, $applications, $error)); $row_count++; } $footerButtons = array();