// item key $itemKey = $item['type'] == ITEM_TYPE_HTTPTEST || $item['flags'] == ZBX_FLAG_DISCOVERY_CREATED ? new CSpan($item['key_expanded'], 'enabled') : new CLink($item['key_expanded'], 'items.php?form=update&itemid=' . $item['itemid'], 'enabled'); // info if ($item['status'] == ITEM_STATUS_ACTIVE && $item['error'] !== '') { $info = new CDiv(null, 'status_icon iconerror'); $info->setHint($item['error'], 'on'); } else { $info = ''; } // trend value if ($item['value_type'] == ITEM_VALUE_TYPE_FLOAT || $item['value_type'] == ITEM_VALUE_TYPE_UINT64) { $trendValue = $config['hk_trends_global'] ? $config['hk_trends'] : $item['trends']; } else { $trendValue = UNKNOWN_VALUE; } $row = new CRow(array('', $checkbox, $hostColumn, new CCol(new CDiv(array($item['name_expanded'], BR(), $itemKey), $stateCss . ' item')), new CCol(new CSpan($item['type'] == ITEM_TYPE_SNMPTRAP || $item['type'] == ITEM_TYPE_TRAPPER ? UNKNOWN_VALUE : $item['delay'], $stateCss)), new CCol(new CSpan($config['hk_history_global'] ? $config['hk_history'] : $item['history'], $stateCss)), new CCol(new CSpan($trendValue, $stateCss)), new CCol(new CSpan(item_type2str($item['type']), $stateCss)), new CCol(new CSpan($lastClock, $stateCss)), new CCol(new CSpan($lastValue, $stateCss)), new CCol(new CSpan($change, $stateCss)), new CCol($actions, $stateCss), $info)); } else { $row = new CRow(array('', $checkbox, $hostColumn, new CCol(new CSpan($item['name_expanded'], $stateCss . ' item')), new CCol(new CSpan($lastClock, $stateCss)), new CCol(new CSpan($lastValue, $stateCss)), new CCol(new CSpan($change, $stateCss)), new CCol($actions, $stateCss))); } $hosts[$item['hostid']]['item_cnt']++; $tab_rows[$item['hostid']][] = $row; } foreach ($hosts as $hostId => $dbHost) { $host = $hosts[$dbHost['hostid']]; if (!isset($tab_rows[$hostId])) { continue; } $appRows = $tab_rows[$hostId]; $openState = CProfile::get('web.latest.toggle_other', null, $host['hostid']); $toggle = new CDiv(null, 'app-list-toggle icon-plus-9x9'); if ($openState) {
$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'); } } } // host prototype link $hostPrototypeLink = null; if ($data['host']['flags'] == ZBX_FLAG_DISCOVERY_NORMAL) { $hostPrototypeLink = array(new CLink(_('Host prototypes'), 'host_prototypes.php?parent_discoveryid=' . $discovery['itemid']), ' (' . $discovery['hostPrototypes'] . ')'); } $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'] . ')'), $hostPrototypeLink, $discovery['key_'], $discovery['delay'], item_type2str($discovery['type']), $status, $data['showErrorColumn'] ? $error : null)); } // 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?')); $goComboBox->addItem($goOption); $goOption = new CComboItem('delete', _('Delete selected')); $goOption->setAttribute('confirm', _('Delete selected discovery rules?')); $goComboBox->addItem($goOption); $goButton = new CSubmit('goButton', _('Go') . ' (0)'); $goButton->setAttribute('id', 'goButton'); zbx_add_post_js('chkbxRange.pageGoName = "g_hostdruleid";');
foreach ($item['triggers'] as $trigger) { foreach ($trigger['functions'] as $function) { if (!str_in_array($function['function'], array('regexp', 'iregexp'))) { continue 2; } } $triggers[] = array('id' => $trigger['triggerid'], 'name' => $trigger['description']); } $menuIcon = new CIcon(_('Menu'), 'iconmenu_b'); $menuIcon->setMenuPopup(CMenuPopupHelper::getTriggerLog($item['itemid'], $item['name'], $triggers)); } else { $menuIcon = SPACE; } $checkBox = new CCheckBox('group_itemid[' . $item['itemid'] . ']', null, null, $item['itemid']); $checkBox->setEnabled(empty($item['discoveryRule'])); $itemTable->addRow(array($checkBox, $menuIcon, empty($this->data['filter_hostid']) ? $item['host'] : null, $description, $triggerInfo, CHtml::encode($item['key_']), $item['type'] == ITEM_TYPE_TRAPPER || $item['type'] == ITEM_TYPE_SNMPTRAP ? '' : $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']), new CCol(CHtml::encode($item['applications_list']), 'wraptext'), $status, $infoIcons)); } // create go buttons $goComboBox = new CComboBox('action'); $goOption = new CComboItem('item.massenable', _('Enable selected')); $goOption->setAttribute('confirm', _('Enable selected items?')); $goComboBox->addItem($goOption); $goOption = new CComboItem('item.massdisable', _('Disable selected')); $goOption->setAttribute('confirm', _('Disable selected items?')); $goComboBox->addItem($goOption); $goOption = new CComboItem('item.massupdateform', _('Mass update')); $goComboBox->addItem($goOption); $goOption = new CComboItem('item.masscopyto', _('Copy selected to ...')); $goComboBox->addItem($goOption); $goOption = new CComboItem('item.massclearhistory', _('Clear history for selected')); $goOption->setAttribute('confirm', _('Delete history of selected items?'));
if ($now - $row["nextcheck"] <= 300) { $sec_300[$row["type"]]++; } else { if ($now - $row["nextcheck"] <= 600) { $sec_600[$row["type"]]++; } else { $sec_rest[$row["type"]]++; } } } } } } $table->setHeader(array(S_ITEMS, S_5_SECONDS, S_10_SECONDS, S_30_SECONDS, S_1_MINUTE, S_5_MINUTES, S_MORE_THAN_10_MINUTES)); foreach ($item_types as $type) { $elements = array(item_type2str($type), new CCol($sec_10[$type], $sec_10[$type] ? "unknown_trigger" : "normal"), new CCol($sec_30[$type], $sec_30[$type] ? "information" : "normal"), new CCol($sec_60[$type], $sec_60[$type] ? "warning" : "normal"), new CCol($sec_300[$type], $sec_300[$type] ? "average" : "normal"), new CCol($sec_600[$type], $sec_600[$type] ? "high" : "normal"), new CCol($sec_rest[$type], $sec_rest[$type] ? "disaster" : "normal")); $table->addRow($elements); } } else { if ($_REQUEST["show"] == 1) { $db_proxies = DBselect('select hostid from hosts where status=' . HOST_STATUS_PROXY); while (null != ($db_proxy = DBfetch($db_proxies))) { $sec_10[$db_proxy['hostid']] = 0; $sec_30[$db_proxy['hostid']] = 0; $sec_60[$db_proxy['hostid']] = 0; $sec_300[$db_proxy['hostid']] = 0; $sec_600[$db_proxy['hostid']] = 0; $sec_rest[$db_proxy['hostid']] = 0; } $sec_10[0] = 0; $sec_30[0] = 0;
continue 2; } } $triggers .= ',["' . $trigger['description'] . '",' . zbx_jsvalue("javascript: openWinCentered('tr_logform.php?sform=1&itemid=" . $item['itemid'] . "&triggerid=" . $trigger['triggerid'] . "','TriggerLog',760,540," . "'titlebar=no, resizable=yes, scrollbars=yes');") . ']'; $triggers_flag = true; } if ($triggers_flag) { $triggers = rtrim($triggers, ',') . ')'; } else { $triggers = 'Array()'; } $menuicon = new CIcon(S_MENU, 'iconmenu_b', 'call_triggerlog_menu(event, ' . zbx_jsvalue($item['itemid']) . ',' . zbx_jsvalue($item['description_expanded']) . ',' . $triggers . ');'); } else { $menuicon = SPACE; } $table->addRow(array(new CCheckBox('group_itemid[' . $item['itemid'] . ']', null, null, $item['itemid']), $menuicon, $host, $description, $trigger_info, $item['key_'], $item['type'] == ITEM_TYPE_TRAPPER ? '' : $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'), $error)); } // GO{ $goBox = new CComboBox('go'); $goOption = new CComboItem('activate', S_ACTIVATE_SELECTED); $goOption->setAttribute('confirm', S_ENABLE_SELECTED_ITEMS_Q); $goBox->addItem($goOption); $goOption = new CComboItem('disable', S_DISABLE_SELECTED); $goOption->setAttribute('confirm', S_DISABLE_SELECTED_ITEMS_Q); $goBox->addItem($goOption); $goOption = new CComboItem('massupdate', S_MASS_UPDATE); //$goOption->setAttribute('confirm',S_MASS_UPDATE_SELECTED_ITEMS_Q); $goBox->addItem($goOption); $goOption = new CComboItem('copy_to', S_COPY_SELECTED_TO); //$goOption->setAttribute('confirm',S_COPY_SELECTED_ITEMS_Q); $goBox->addItem($goOption);
// create form list $itemFormList = new CFormList('itemFormList'); if (!empty($this->data['templates'])) { if ($this->data['is_discovery_rule']) { $itemFormList->addRow(_('Parent discovery rules'), $this->data['templates']); } else { $itemFormList->addRow(_('Parent items'), $this->data['templates']); } } $nameTextBox = new CTextBox('name', $this->data['name'], ZBX_TEXTBOX_STANDARD_SIZE, $this->data['limited']); $nameTextBox->attr('autofocus', 'autofocus'); $itemFormList->addRow(_('Name'), $nameTextBox); // append type to form list if ($this->data['limited']) { $itemForm->addVar('type', $this->data['type']); $itemFormList->addRow(_('Type'), new CTextBox('typename', item_type2str($this->data['type']), ZBX_TEXTBOX_STANDARD_SIZE, 'yes')); } else { $typeComboBox = new CComboBox('type', $this->data['type']); $typeComboBox->addItems($this->data['types']); $itemFormList->addRow(_('Type'), $typeComboBox); } // append key to form list $itemFormList->addRow(_('Key'), array(new CTextBox('key', $this->data['key'], ZBX_TEXTBOX_STANDARD_SIZE, $this->data['limited']), !$this->data['limited'] && !$this->data['is_discovery_rule'] ? new CButton('keyButton', _('Select'), 'return PopUp("popup.php?srctbl=help_items&srcfld1=key' . '&dstfrm=' . $itemForm->getName() . '&dstfld1=key&itemtype="+jQuery("#type option:selected").val());', 'formlist') : null)); // append interfaces to form list if (!empty($this->data['interfaces'])) { $interfacesComboBox = new CComboBox('interfaceid', $this->data['interfaceid']); // set up interface groups $interfaceGroups = array(); foreach (zbx_objectValues($this->data['interfaces'], 'type') as $interfaceType) { $interfaceGroups[$interfaceType] = new COptGroup(interfaceType2str($interfaceType)); }
} $widget = (new CWidget())->setTitle(_('Queue of items to be updated'))->setControls((new CForm('get'))->cleanItems()->addItem((new CList())->addItem((new CComboBox('config', $config, 'submit();'))->addItem(QUEUE_OVERVIEW, _('Overview'))->addItem(QUEUE_OVERVIEW_BY_PROXY, _('Overview by proxy'))->addItem(QUEUE_DETAILS, _('Details'))))); $table = new CTableInfo(); $severityConfig = select_config(); // overview if ($config == QUEUE_OVERVIEW) { $itemTypes = [ITEM_TYPE_ZABBIX, ITEM_TYPE_ZABBIX_ACTIVE, ITEM_TYPE_SIMPLE, ITEM_TYPE_SNMPV1, ITEM_TYPE_SNMPV2C, ITEM_TYPE_SNMPV3, ITEM_TYPE_INTERNAL, ITEM_TYPE_AGGREGATE, ITEM_TYPE_EXTERNAL, ITEM_TYPE_DB_MONITOR, ITEM_TYPE_IPMI, ITEM_TYPE_SSH, ITEM_TYPE_TELNET, ITEM_TYPE_JMX, ITEM_TYPE_CALCULATED]; $table->setHeader([_('Items'), _('5 seconds'), _('10 seconds'), _('30 seconds'), _('1 minute'), _('5 minutes'), _('More than 10 minutes')]); $queueData = zbx_toHash($queueData, 'itemtype'); foreach ($itemTypes as $type) { if (isset($queueData[$type])) { $itemTypeData = $queueData[$type]; } else { $itemTypeData = ['delay5' => 0, 'delay10' => 0, 'delay30' => 0, 'delay60' => 0, 'delay300' => 0, 'delay600' => 0]; } $table->addRow([item_type2str($type), getSeverityCell(TRIGGER_SEVERITY_NOT_CLASSIFIED, $severityConfig, $itemTypeData['delay5'], !$itemTypeData['delay5']), getSeverityCell(TRIGGER_SEVERITY_INFORMATION, $severityConfig, $itemTypeData['delay10'], !$itemTypeData['delay10']), getSeverityCell(TRIGGER_SEVERITY_WARNING, $severityConfig, $itemTypeData['delay30'], !$itemTypeData['delay30']), getSeverityCell(TRIGGER_SEVERITY_AVERAGE, $severityConfig, $itemTypeData['delay60'], !$itemTypeData['delay60']), getSeverityCell(TRIGGER_SEVERITY_HIGH, $severityConfig, $itemTypeData['delay300'], !$itemTypeData['delay300']), getSeverityCell(TRIGGER_SEVERITY_DISASTER, $severityConfig, $itemTypeData['delay600'], !$itemTypeData['delay600'])]); } } elseif ($config == QUEUE_OVERVIEW_BY_PROXY) { $proxies = API::proxy()->get(['output' => ['hostid', 'host'], 'preservekeys' => true]); order_result($proxies, 'host'); $proxies[0] = ['host' => _('Server')]; $table->setHeader([_('Proxy'), _('5 seconds'), _('10 seconds'), _('30 seconds'), _('1 minute'), _('5 minutes'), _('More than 10 minutes')]); $queueData = zbx_toHash($queueData, 'proxyid'); foreach ($proxies as $proxyId => $proxy) { if (isset($queueData[$proxyId])) { $proxyData = $queueData[$proxyId]; } else { $proxyData = ['delay5' => 0, 'delay10' => 0, 'delay30' => 0, 'delay60' => 0, 'delay300' => 0, 'delay600' => 0]; } $table->addRow([$proxy['host'], getSeverityCell(TRIGGER_SEVERITY_NOT_CLASSIFIED, $severityConfig, $proxyData['delay5'], !$proxyData['delay5']), getSeverityCell(TRIGGER_SEVERITY_INFORMATION, $severityConfig, $proxyData['delay10'], !$proxyData['delay10']), getSeverityCell(TRIGGER_SEVERITY_WARNING, $severityConfig, $proxyData['delay30'], !$proxyData['delay30']), getSeverityCell(TRIGGER_SEVERITY_AVERAGE, $severityConfig, $proxyData['delay60'], !$proxyData['delay60']), getSeverityCell(TRIGGER_SEVERITY_HIGH, $severityConfig, $proxyData['delay300'], !$proxyData['delay300']), getSeverityCell(TRIGGER_SEVERITY_DISASTER, $severityConfig, $proxyData['delay600'], !$proxyData['delay600'])]); }
/** * Get data for item edit page. * * @param array $item item, item prototype or LLD rule to take the data from * @param bool $options['is_discovery_rule'] * * @return array */ function getItemFormData(array $item = [], array $options = []) { $data = ['form' => getRequest('form'), 'form_refresh' => getRequest('form_refresh'), 'is_discovery_rule' => !empty($options['is_discovery_rule']), 'parent_discoveryid' => getRequest('parent_discoveryid', !empty($options['is_discovery_rule']) ? getRequest('itemid') : null), 'itemid' => getRequest('itemid'), 'limited' => false, 'interfaceid' => getRequest('interfaceid', 0), 'name' => getRequest('name', ''), 'description' => getRequest('description', ''), 'key' => getRequest('key', ''), 'hostname' => getRequest('hostname'), 'delay' => getRequest('delay', ZBX_ITEM_DELAY_DEFAULT), 'history' => getRequest('history', 90), 'status' => getRequest('status', isset($_REQUEST['form_refresh']) ? 1 : 0), 'type' => getRequest('type', 0), 'snmp_community' => getRequest('snmp_community', 'public'), 'snmp_oid' => getRequest('snmp_oid', 'interfaces.ifTable.ifEntry.ifInOctets.1'), 'port' => getRequest('port', ''), 'value_type' => getRequest('value_type', ITEM_VALUE_TYPE_UINT64), 'data_type' => getRequest('data_type', ITEM_DATA_TYPE_DECIMAL), 'trapper_hosts' => getRequest('trapper_hosts', ''), 'units' => getRequest('units', ''), 'valuemapid' => getRequest('valuemapid', 0), 'params' => getRequest('params', ''), 'multiplier' => getRequest('multiplier', 0), 'delta' => getRequest('delta', 0), 'trends' => getRequest('trends', DAY_IN_YEAR), 'new_application' => getRequest('new_application', ''), 'applications' => getRequest('applications', []), 'delay_flex' => getRequest('delay_flex', []), 'snmpv3_contextname' => getRequest('snmpv3_contextname', ''), 'snmpv3_securityname' => getRequest('snmpv3_securityname', ''), 'snmpv3_securitylevel' => getRequest('snmpv3_securitylevel', 0), 'snmpv3_authprotocol' => getRequest('snmpv3_authprotocol', ITEM_AUTHPROTOCOL_MD5), 'snmpv3_authpassphrase' => getRequest('snmpv3_authpassphrase', ''), 'snmpv3_privprotocol' => getRequest('snmpv3_privprotocol', ITEM_PRIVPROTOCOL_DES), 'snmpv3_privpassphrase' => getRequest('snmpv3_privpassphrase', ''), 'ipmi_sensor' => getRequest('ipmi_sensor', ''), 'authtype' => getRequest('authtype', 0), 'username' => getRequest('username', ''), 'password' => getRequest('password', ''), 'publickey' => getRequest('publickey', ''), 'privatekey' => getRequest('privatekey', ''), 'formula' => getRequest('formula', 1), 'logtimefmt' => getRequest('logtimefmt', ''), 'add_groupid' => getRequest('add_groupid', getRequest('groupid', 0)), 'valuemaps' => null, 'possibleHostInventories' => null, 'alreadyPopulated' => null, 'initial_item_type' => null, 'templates' => []]; // hostid if (!empty($data['parent_discoveryid'])) { $discoveryRule = API::DiscoveryRule()->get(['itemids' => $data['parent_discoveryid'], 'output' => API_OUTPUT_EXTEND, 'editable' => true]); $discoveryRule = reset($discoveryRule); $data['hostid'] = $discoveryRule['hostid']; $data['new_application_prototype'] = getRequest('new_application_prototype', ''); $data['application_prototypes'] = getRequest('application_prototypes', array()); } else { $data['hostid'] = getRequest('hostid', 0); } // types, http items only for internal processes $data['types'] = item_type2str(); unset($data['types'][ITEM_TYPE_HTTPTEST]); if (!empty($options['is_discovery_rule'])) { unset($data['types'][ITEM_TYPE_AGGREGATE], $data['types'][ITEM_TYPE_CALCULATED], $data['types'][ITEM_TYPE_SNMPTRAP]); } // item if ($item) { $data['item'] = $item; $data['hostid'] = !empty($data['hostid']) ? $data['hostid'] : $data['item']['hostid']; $data['limited'] = $data['item']['templateid'] != 0; // get templates $itemid = $item['itemid']; do { $params = ['itemids' => $itemid, 'output' => ['itemid', 'templateid'], 'selectHosts' => ['name']]; if ($data['is_discovery_rule']) { $item = API::DiscoveryRule()->get($params); } else { $params['selectDiscoveryRule'] = ['itemid']; $params['filter'] = ['flags' => null]; $item = API::Item()->get($params); } $item = reset($item); if (!empty($item)) { $host = reset($item['hosts']); if (!empty($item['hosts'])) { $host['name'] = CHtml::encode($host['name']); if (bccomp($data['itemid'], $itemid) == 0) { } elseif ($data['is_discovery_rule']) { $data['templates'][] = new CLink($host['name'], 'host_discovery.php?form=update&itemid=' . $item['itemid']); $data['templates'][] = SPACE . '⇒' . SPACE; } elseif ($item['discoveryRule']) { $data['templates'][] = new CLink($host['name'], 'disc_prototypes.php?form=update' . '&itemid=' . $item['itemid'] . '&parent_discoveryid=' . $item['discoveryRule']['itemid']); $data['templates'][] = SPACE . '⇒' . SPACE; } else { $data['templates'][] = new CLink($host['name'], 'items.php?form=update&itemid=' . $item['itemid']); $data['templates'][] = SPACE . '⇒' . SPACE; } } $itemid = $item['templateid']; } else { break; } } while ($itemid != 0); $data['templates'] = array_reverse($data['templates']); array_shift($data['templates']); } // caption if (!empty($data['is_discovery_rule'])) { $data['caption'] = _('Discovery rule'); } else { $data['caption'] = !empty($data['parent_discoveryid']) ? _('Item prototype') : _('Item'); } // hostname if (empty($data['is_discovery_rule']) && empty($data['hostname'])) { if (!empty($data['hostid'])) { $hostInfo = API::Host()->get(['hostids' => $data['hostid'], 'output' => ['name'], 'templated_hosts' => true]); $hostInfo = reset($hostInfo); $data['hostname'] = $hostInfo['name']; } else { $data['hostname'] = _('not selected'); } } // fill data from item if (!hasRequest('form_refresh') && ($item || $data['limited'])) { $data['name'] = $data['item']['name']; $data['description'] = $data['item']['description']; $data['key'] = $data['item']['key_']; $data['interfaceid'] = $data['item']['interfaceid']; $data['type'] = $data['item']['type']; $data['snmp_community'] = $data['item']['snmp_community']; $data['snmp_oid'] = $data['item']['snmp_oid']; $data['port'] = $data['item']['port']; $data['value_type'] = $data['item']['value_type']; $data['data_type'] = $data['item']['data_type']; $data['trapper_hosts'] = $data['item']['trapper_hosts']; $data['units'] = $data['item']['units']; $data['valuemapid'] = $data['item']['valuemapid']; $data['multiplier'] = $data['item']['multiplier']; $data['hostid'] = $data['item']['hostid']; $data['params'] = $data['item']['params']; $data['snmpv3_contextname'] = $data['item']['snmpv3_contextname']; $data['snmpv3_securityname'] = $data['item']['snmpv3_securityname']; $data['snmpv3_securitylevel'] = $data['item']['snmpv3_securitylevel']; $data['snmpv3_authprotocol'] = $data['item']['snmpv3_authprotocol']; $data['snmpv3_authpassphrase'] = $data['item']['snmpv3_authpassphrase']; $data['snmpv3_privprotocol'] = $data['item']['snmpv3_privprotocol']; $data['snmpv3_privpassphrase'] = $data['item']['snmpv3_privpassphrase']; $data['ipmi_sensor'] = $data['item']['ipmi_sensor']; $data['authtype'] = $data['item']['authtype']; $data['username'] = $data['item']['username']; $data['password'] = $data['item']['password']; $data['publickey'] = $data['item']['publickey']; $data['privatekey'] = $data['item']['privatekey']; $data['logtimefmt'] = $data['item']['logtimefmt']; $data['new_application'] = getRequest('new_application', ''); if ($data['parent_discoveryid'] != 0) { $data['new_application_prototype'] = getRequest('new_application_prototype', ''); } if (!$data['is_discovery_rule']) { $data['formula'] = $data['item']['formula']; } if (!$data['limited'] || !isset($_REQUEST['form_refresh'])) { $data['delay'] = $data['item']['delay']; if (($data['type'] == ITEM_TYPE_TRAPPER || $data['type'] == ITEM_TYPE_SNMPTRAP) && $data['delay'] == 0) { $data['delay'] = ZBX_ITEM_DELAY_DEFAULT; } $data['history'] = $data['item']['history']; $data['status'] = $data['item']['status']; $data['delta'] = $data['item']['delta']; $data['trends'] = $data['item']['trends']; $parser = new CItemDelayFlexParser($data['item']['delay_flex']); if ($parser->isValid()) { foreach ($parser->getIntervals() as $interval) { if ($interval['type'] == ITEM_DELAY_FLEX_TYPE_FLEXIBLE) { $interval_parts = explode('/', $interval['interval']); $data['delay_flex'][] = ['delay' => $interval_parts[0], 'period' => $interval_parts[1], 'type' => ITEM_DELAY_FLEX_TYPE_FLEXIBLE]; } else { $data['delay_flex'][] = ['schedule' => $interval['interval'], 'type' => ITEM_DELAY_FLEX_TYPE_SCHEDULING]; } } } $data['applications'] = array_unique(zbx_array_merge($data['applications'], get_applications_by_itemid($data['itemid']))); if ($data['parent_discoveryid'] != 0) { /* * Get a list of application prototypes assigned to item prototype. Don't select distinct names, * since database can be accidentally created case insensitive. */ $application_prototypes = DBfetchArray(DBselect('SELECT ap.name' . ' FROM application_prototype ap,item_application_prototype iap' . ' WHERE ap.application_prototypeid=iap.application_prototypeid' . ' AND ap.itemid=' . zbx_dbstr($data['parent_discoveryid']) . ' AND iap.itemid=' . zbx_dbstr($data['itemid']))); // Merge form submitted data with data existing in DB to find diff and correctly display ListBox. $data['application_prototypes'] = array_unique(zbx_array_merge($data['application_prototypes'], zbx_objectValues($application_prototypes, 'name'))); } } } if (!$data['delay_flex']) { $data['delay_flex'][] = ['delay' => '', 'period' => '', 'type' => ITEM_DELAY_FLEX_TYPE_FLEXIBLE]; } // applications if (count($data['applications']) == 0) { array_push($data['applications'], 0); } $data['db_applications'] = DBfetchArray(DBselect('SELECT DISTINCT a.applicationid,a.name' . ' FROM applications a' . ' WHERE a.hostid=' . zbx_dbstr($data['hostid']) . ($data['parent_discoveryid'] ? ' AND a.flags=' . ZBX_FLAG_DISCOVERY_NORMAL : ''))); order_result($data['db_applications'], 'name'); if ($data['parent_discoveryid'] != 0) { // Make the application prototype list no appearing empty, but filling it with "-None-" as first element. if (count($data['application_prototypes']) == 0) { $data['application_prototypes'][] = 0; } // Get a list of application prototypes by discovery rule. $data['db_application_prototypes'] = DBfetchArray(DBselect('SELECT ap.application_prototypeid,ap.name' . ' FROM application_prototype ap' . ' WHERE ap.itemid=' . zbx_dbstr($data['parent_discoveryid']))); order_result($data['db_application_prototypes'], 'name'); } // interfaces $data['interfaces'] = API::HostInterface()->get(['hostids' => $data['hostid'], 'output' => API_OUTPUT_EXTEND]); // valuemapid if ($data['limited']) { if ($data['valuemapid'] != 0) { $valuemaps = API::ValueMap()->get(['output' => ['name'], 'valuemapids' => [$data['valuemapid']]]); if ($valuemaps) { $data['valuemaps'] = $valuemaps[0]['name']; } } } else { $data['valuemaps'] = API::ValueMap()->get(['output' => ['valemapid', 'name']]); CArrayHelper::sort($data['valuemaps'], ['name']); } // possible host inventories if (empty($data['parent_discoveryid'])) { $data['possibleHostInventories'] = getHostInventories(); // get already populated fields by other items $data['alreadyPopulated'] = API::item()->get(['output' => ['inventory_link'], 'filter' => ['hostid' => $data['hostid']], 'nopermissions' => true]); $data['alreadyPopulated'] = zbx_toHash($data['alreadyPopulated'], 'inventory_link'); } // unset snmpv3 fields if ($data['type'] != ITEM_TYPE_SNMPV3) { $data['snmpv3_contextname'] = ''; $data['snmpv3_securityname'] = ''; $data['snmpv3_securitylevel'] = ITEM_SNMPV3_SECURITYLEVEL_NOAUTHNOPRIV; $data['snmpv3_authprotocol'] = ITEM_AUTHPROTOCOL_MD5; $data['snmpv3_authpassphrase'] = ''; $data['snmpv3_privprotocol'] = ITEM_PRIVPROTOCOL_DES; $data['snmpv3_privpassphrase'] = ''; } // unset ssh auth fields if ($data['type'] != ITEM_TYPE_SSH) { $data['authtype'] = ITEM_AUTHTYPE_PASSWORD; $data['publickey'] = ''; $data['privatekey'] = ''; } return $data; }
if ($multiselect) { $js_action = 'javascript: addValue(' . zbx_jsvalue($reference) . ', ' . zbx_jsvalue($item['itemid']) . ');'; } else { $values = array(); for ($i = 1; $i <= $dstfldCount; $i++) { $dstfld = getRequest('dstfld' . $i); $srcfld = getRequest('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");'); $table->addRow(array($hostid > 0 ? null : $item['hostname'], $multiselect ? new CCheckBox('items[' . zbx_jsValue($item[$srcfld1]) . ']', null, null, $item['itemid']) : null, $description, $item['key_'], item_type2str($item['type']), itemValueTypeString($item['value_type']), new CSpan(itemIndicator($item['status'], $item['state']), itemIndicatorStyle($item['status'], $item['state'])))); // made to save memory usage if ($multiselect) { $jsItems[$item['itemid']] = array('itemid' => $item['itemid'], 'name' => $item['name'], 'key_' => $item['key_'], 'flags' => $item['flags'], 'type' => $item['type'], 'value_type' => $item['value_type'], 'host' => $item['hostname']); } } 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($jsItems, true) . ';'); } $form->addItem($table); $form->show(); } elseif ($srctbl == 'applications') { $form = new CForm(); $form->setName('applicationform');
function insert_mass_update_item_form() { global $USER_DETAILS; $frmItem = new CFormTable(S_ITEM, null, 'post'); $frmItem->setHelp('web.items.item.php'); $frmItem->setTitle(S_MASS_UPDATE); $frmItem->addVar('massupdate', 1); $frmItem->addVar('group_itemid', get_request('group_itemid', array())); $frmItem->addVar('config', get_request('config', 0)); $delay = get_request('delay', 30); $history = get_request('history', 90); $status = get_request('status', 0); $type = get_request('type', 0); $snmp_community = get_request('snmp_community', 'public'); $snmp_port = get_request('snmp_port', 161); $value_type = get_request('value_type', ITEM_VALUE_TYPE_UINT64); $data_type = get_request('data_type', ITEM_DATA_TYPE_DECIMAL); $trapper_hosts = get_request('trapper_hosts', ''); $units = get_request('units', ''); $authtype = get_request('authtype', ''); $username = get_request('username', ''); $password = get_request('password', ''); $publickey = get_request('publickey', ''); $privatekey = get_request('privatekey', ''); $valuemapid = get_request('valuemapid', 0); $delta = get_request('delta', 0); $trends = get_request('trends', 365); $applications = get_request('applications', array()); $delay_flex = get_request('delay_flex', array()); $snmpv3_securityname = get_request('snmpv3_securityname', ''); $snmpv3_securitylevel = get_request('snmpv3_securitylevel', 0); $snmpv3_authpassphrase = get_request('snmpv3_authpassphrase', ''); $snmpv3_privpassphrase = get_request('snmpv3_privpassphrase', ''); $formula = get_request('formula', '1'); $logtimefmt = get_request('logtimefmt', ''); $delay_flex_el = array(); $i = 0; foreach ($delay_flex as $val) { if (!isset($val['delay']) && !isset($val['period'])) { continue; } array_push($delay_flex_el, array(new CCheckBox('rem_delay_flex[]', 'no', null, $i), $val['delay'], SPACE . S_SEC_AT . SPACE, $val['period']), BR()); $frmItem->addVar("delay_flex[" . $i . "][delay]", $val['delay']); $frmItem->addVar("delay_flex[" . $i . "][period]", $val['period']); $i++; if ($i >= 7) { break; } /* limit count of intervals * 7 intervals by 30 symbols = 210 characters * db storage field is 256 */ } if (count($delay_flex_el) == 0) { array_push($delay_flex_el, S_NO_FLEXIBLE_INTERVALS); } else { array_push($delay_flex_el, new CButton('del_delay_flex', S_DELETE_SELECTED)); } if (count($applications) == 0) { array_push($applications, 0); } $itemTypes = item_type2str(); // http items only for internal processes unset($itemTypes[ITEM_TYPE_HTTPTEST]); $cmbType = new CComboBox('type', $type); $cmbType->addItems($itemTypes); $frmItem->addRow(array(new CVisibilityBox('type_visible', get_request('type_visible'), 'type', S_ORIGINAL), S_TYPE), $cmbType); $frmItem->addRow(array(new CVisibilityBox('community_visible', get_request('community_visible'), 'snmp_community', S_ORIGINAL), S_SNMP_COMMUNITY), new CTextBox('snmp_community', $snmp_community, 16)); $frmItem->addRow(array(new CVisibilityBox('securityname_visible', get_request('securityname_visible'), 'snmpv3_securityname', S_ORIGINAL), S_SNMPV3_SECURITY_NAME), new CTextBox('snmpv3_securityname', $snmpv3_securityname, 64)); $cmbSecLevel = new CComboBox('snmpv3_securitylevel', $snmpv3_securitylevel); $cmbSecLevel->addItem(ITEM_SNMPV3_SECURITYLEVEL_NOAUTHNOPRIV, "noAuthNoPriv"); $cmbSecLevel->addItem(ITEM_SNMPV3_SECURITYLEVEL_AUTHNOPRIV, "authNoPriv"); $cmbSecLevel->addItem(ITEM_SNMPV3_SECURITYLEVEL_AUTHPRIV, "authPriv"); $frmItem->addRow(array(new CVisibilityBox('securitylevel_visible', get_request('securitylevel_visible'), 'snmpv3_securitylevel', S_ORIGINAL), S_SNMPV3_SECURITY_LEVEL), $cmbSecLevel); $frmItem->addRow(array(new CVisibilityBox('authpassphrase_visible', get_request('authpassphrase_visible'), 'snmpv3_authpassphrase', S_ORIGINAL), S_SNMPV3_AUTH_PASSPHRASE), new CTextBox('snmpv3_authpassphrase', $snmpv3_authpassphrase, 64)); $frmItem->addRow(array(new CVisibilityBox('privpassphras_visible', get_request('privpassphras_visible'), 'snmpv3_privpassphrase', S_ORIGINAL), S_SNMPV3_PRIV_PASSPHRASE), new CTextBox('snmpv3_privpassphrase', $snmpv3_privpassphrase, 64)); $frmItem->addRow(array(new CVisibilityBox('port_visible', get_request('port_visible'), 'snmp_port', S_ORIGINAL), S_SNMP_PORT), new CNumericBox('snmp_port', $snmp_port, 5)); $cmbValType = new CComboBox('value_type', $value_type); $cmbValType->addItem(ITEM_VALUE_TYPE_UINT64, S_NUMERIC_UNSIGNED); $cmbValType->addItem(ITEM_VALUE_TYPE_FLOAT, S_NUMERIC_FLOAT); $cmbValType->addItem(ITEM_VALUE_TYPE_STR, S_CHARACTER); $cmbValType->addItem(ITEM_VALUE_TYPE_LOG, S_LOG); $cmbValType->addItem(ITEM_VALUE_TYPE_TEXT, S_TEXT); $frmItem->addRow(array(new CVisibilityBox('value_type_visible', get_request('value_type_visible'), 'value_type', S_ORIGINAL), S_TYPE_OF_INFORMATION), $cmbValType); $cmbDataType = new CComboBox('data_type', $data_type); $cmbDataType->addItem(ITEM_DATA_TYPE_DECIMAL, item_data_type2str(ITEM_DATA_TYPE_DECIMAL)); $cmbDataType->addItem(ITEM_DATA_TYPE_OCTAL, item_data_type2str(ITEM_DATA_TYPE_OCTAL)); $cmbDataType->addItem(ITEM_DATA_TYPE_HEXADECIMAL, item_data_type2str(ITEM_DATA_TYPE_HEXADECIMAL)); $frmItem->addRow(array(new CVisibilityBox('data_type_visible', get_request('data_type_visible'), 'data_type', S_ORIGINAL), S_DATA_TYPE), $cmbDataType); $frmItem->addRow(array(new CVisibilityBox('units_visible', get_request('units_visible'), 'units', S_ORIGINAL), S_UNITS), new CTextBox('units', $units, 40)); $cmbAuthType = new CComboBox('authtype', $authtype); $cmbAuthType->addItem(ITEM_AUTHTYPE_PASSWORD, S_PASSWORD); $cmbAuthType->addItem(ITEM_AUTHTYPE_PUBLICKEY, S_PUBLIC_KEY); $frmItem->addRow(array(new CVisibilityBox('authtype_visible', get_request('authtype_visible'), 'authtype', S_ORIGINAL), S_AUTHENTICATION_METHOD), $cmbAuthType); $frmItem->addRow(array(new CVisibilityBox('username_visible', get_request('username_visible'), 'username', S_ORIGINAL), S_USER_NAME), new CTextBox('username', $username, 40)); $frmItem->addRow(array(new CVisibilityBox('publickey_visible', get_request('publickey_visible'), 'publickey', S_ORIGINAL), S_PUBLIC_KEY_FILE), new CTextBox('publickey', $publickey, 40)); $frmItem->addRow(array(new CVisibilityBox('privatekey_visible', get_request('privatekey_visible'), 'privatekey', S_ORIGINAL), S_PRIVATE_KEY_FILE), new CTextBox('privatekey', $privatekey, 40)); $frmItem->addRow(array(new CVisibilityBox('password_visible', get_request('password_visible'), 'password', S_ORIGINAL), S_PASSWORD), new CTextBox('password', $password, 40)); $frmItem->addRow(array(new CVisibilityBox('formula_visible', get_request('formula_visible'), 'formula', S_ORIGINAL), S_CUSTOM_MULTIPLIER . ' (0 - ' . S_DISABLED . ')'), new CTextBox('formula', $formula, 40)); $frmItem->addRow(array(new CVisibilityBox('delay_visible', get_request('delay_visible'), 'delay', S_ORIGINAL), S_UPDATE_INTERVAL_IN_SEC), new CNumericBox('delay', $delay, 5)); $delay_flex_el = new CSpan($delay_flex_el); $delay_flex_el->setAttribute('id', 'delay_flex_list'); $frmItem->addRow(array(new CVisibilityBox('delay_flex_visible', get_request('delay_flex_visible'), array('delay_flex_list', 'new_delay_flex_el'), S_ORIGINAL), S_FLEXIBLE_INTERVALS), $delay_flex_el); $new_delay_flex_el = new CSpan(array(S_DELAY, SPACE, new CNumericBox("new_delay_flex[delay]", "50", 5), S_PERIOD, SPACE, new CTextBox("new_delay_flex[period]", "1-7,00:00-23:59", 27), BR(), new CButton("add_delay_flex", S_ADD))); $new_delay_flex_el->setAttribute('id', 'new_delay_flex_el'); $frmItem->addRow(S_NEW_FLEXIBLE_INTERVAL, $new_delay_flex_el, 'new'); $frmItem->addRow(array(new CVisibilityBox('history_visible', get_request('history_visible'), 'history', S_ORIGINAL), S_KEEP_HISTORY_IN_DAYS), new CNumericBox('history', $history, 8)); $frmItem->addRow(array(new CVisibilityBox('trends_visible', get_request('trends_visible'), 'trends', S_ORIGINAL), S_KEEP_TRENDS_IN_DAYS), new CNumericBox('trends', $trends, 8)); $cmbStatus = new CComboBox('status', $status); foreach (array(ITEM_STATUS_ACTIVE, ITEM_STATUS_DISABLED, ITEM_STATUS_NOTSUPPORTED) as $st) { $cmbStatus->addItem($st, item_status2str($st)); } $frmItem->addRow(array(new CVisibilityBox('status_visible', get_request('status_visible'), 'status', S_ORIGINAL), S_STATUS), $cmbStatus); $frmItem->addRow(array(new CVisibilityBox('logtimefmt_visible', get_request('logtimefmt_visible'), 'logtimefmt', S_ORIGINAL), S_LOG_TIME_FORMAT), new CTextBox("logtimefmt", $logtimefmt, 16)); $cmbDelta = new CComboBox('delta', $delta); $cmbDelta->addItem(0, S_AS_IS); $cmbDelta->addItem(1, S_DELTA_SPEED_PER_SECOND); $cmbDelta->addItem(2, S_DELTA_SIMPLE_CHANGE); $frmItem->addRow(array(new CVisibilityBox('delta_visible', get_request('delta_visible'), 'delta', S_ORIGINAL), S_STORE_VALUE), $cmbDelta); $cmbMap = new CComboBox('valuemapid', $valuemapid); $cmbMap->addItem(0, S_AS_IS); $db_valuemaps = DBselect('SELECT * FROM valuemaps WHERE ' . DBin_node('valuemapid')); while ($db_valuemap = DBfetch($db_valuemaps)) { $cmbMap->addItem($db_valuemap["valuemapid"], get_node_name_by_elid($db_valuemap["valuemapid"], null, ': ') . $db_valuemap["name"]); } $link = new CLink(S_SHOW_VALUE_MAPPINGS, 'config.php?config=6'); $link->setAttribute('target', '_blank'); $frmItem->addRow(array(new CVisibilityBox('valuemapid_visible', get_request('valuemapid_visible'), 'valuemapid', S_ORIGINAL), S_SHOW_VALUE), array($cmbMap, SPACE, $link)); $frmItem->addRow(array(new CVisibilityBox('trapper_hosts_visible', get_request('trapper_hosts_visible'), 'trapper_hosts', S_ORIGINAL), S_ALLOWED_HOSTS), new CTextBox('trapper_hosts', $trapper_hosts, 40)); $cmbApps = new CListBox('applications[]', $applications, 6); $cmbApps->addItem(0, '-' . S_NONE . '-'); if (isset($_REQUEST['hostid'])) { $sql = 'SELECT applicationid,name ' . ' FROM applications ' . ' WHERE hostid=' . $_REQUEST['hostid'] . ' ORDER BY name'; $db_applications = DBselect($sql); while ($db_app = DBfetch($db_applications)) { $cmbApps->addItem($db_app["applicationid"], $db_app["name"]); } } $frmItem->addRow(array(new CVisibilityBox('applications_visible', get_request('applications_visible'), 'applications[]', S_ORIGINAL), S_APPLICATIONS), $cmbApps); $frmItem->addItemToBottomRow(array(new CButton("update", S_UPDATE), SPACE, new CButtonCancel(url_param('groupid') . url_param("hostid") . url_param("config")))); return $frmItem; }
if ($discovery['templateid']) { $dbTemplate = get_realhost_by_itemid($discovery['templateid']); $description[] = (new CLink($dbTemplate['name'], '?hostid=' . $dbTemplate['hostid']))->addClass(ZBX_STYLE_LINK_ALT)->addClass(ZBX_STYLE_GREY); $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')))->addClass(ZBX_STYLE_LINK_ACTION)->addClass(itemIndicatorStyle($discovery['status'], $discovery['state']))->addSID(); // info if ($data['showInfoColumn']) { if ($discovery['status'] == ITEM_STATUS_ACTIVE && !zbx_empty($discovery['error'])) { $info = makeErrorIcon($discovery['error']); } else { $info = ''; } } else { $info = null; } // host prototype link $hostPrototypeLink = null; if ($data['host']['flags'] == ZBX_FLAG_DISCOVERY_NORMAL) { $hostPrototypeLink = [new CLink(_('Host prototypes'), 'host_prototypes.php?parent_discoveryid=' . $discovery['itemid']), CViewHelper::showNum($discovery['hostPrototypes'])]; } $discoveryTable->addRow([new CCheckBox('g_hostdruleid[' . $discovery['itemid'] . ']', $discovery['itemid']), $description, [new CLink(_('Item prototypes'), 'disc_prototypes.php?parent_discoveryid=' . $discovery['itemid']), CViewHelper::showNum($discovery['items'])], [new CLink(_('Trigger prototypes'), 'trigger_prototypes.php?parent_discoveryid=' . $discovery['itemid']), CViewHelper::showNum($discovery['triggers'])], [new CLink(_('Graph prototypes'), 'graphs.php?parent_discoveryid=' . $discovery['itemid']), CViewHelper::showNum($discovery['graphs'])], $hostPrototypeLink, $discovery['key_'], $discovery['delay'] === '' ? '' : convertUnitsS($discovery['delay']), item_type2str($discovery['type']), $status, $info]); } zbx_add_post_js('cookie.prefix = "' . $this->data['hostid'] . '";'); // append table to form $discoveryForm->addItem([$discoveryTable, $this->data['paging'], new CActionButtonList('action', 'g_hostdruleid', ['discoveryrule.massenable' => ['name' => _('Enable'), 'confirm' => _('Enable selected discovery rules?')], 'discoveryrule.massdisable' => ['name' => _('Disable'), 'confirm' => _('Disable selected discovery rules?')], 'discoveryrule.massdelete' => ['name' => _('Delete'), 'confirm' => _('Delete selected discovery rules?')]], $this->data['hostid'])]); // append form to widget $widget->addItem($discoveryForm); return $widget;
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 ------ $goBox = new CComboBox('go'); $goBox->addItem('activate', S_ACTIVATE_SELECTED); $goBox->addItem('disable', S_DISABLE_SELECTED); $goBox->addItem('massupdate', S_MASS_UPDATE); $goBox->addItem('copy_to', S_COPY_SELECTED_TO); $goBox->addItem('clean_history', S_CLEAN_HISTORY_SELECTED_ITEMS); $goBox->addItem('delete', S_DELETE_SELECTED); // goButton name is necessary!!! $goButton = new CButton('goButton', S_GO . ' (0)'); $goButton->setAttribute('id', 'goButton'); zbx_add_post_js('chkbxRange.pageGoName = "group_itemid";'); $table->setFooter(new CCol(array($goBox, $goButton)));
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(); array_push($footerButtons, new CButtonQMessage('group_task', S_ACTIVATE_SELECTED, S_ACTIVATE_SELECTED_ITEMS_Q)); array_push($footerButtons, SPACE); array_push($footerButtons, new CButtonQMessage('group_task', S_DISABLE_SELECTED, S_DISABLE_SELECTED_ITEMS_Q)); array_push($footerButtons, SPACE); array_push($footerButtons, new CButtonQMessage('group_task', S_CLEAN_HISTORY_SELECTED_ITEMS, S_HISTORY_CLEANING_CAN_TAKE_A_LONG_TIME_CONTINUE_Q)); array_push($footerButtons, SPACE); array_push($footerButtons, new CButtonQMessage('group_task', S_DELETE_SELECTED, S_DELETE_SELECTED_ITEMS_Q)); array_push($footerButtons, SPACE); array_push($footerButtons, new CButton('form_copy_to', S_COPY_SELECTED_TO)); array_push($footerButtons, SPACE); array_push($footerButtons, new CButton('form_mass_update', S_MASS_UPDATE)); $table->setFooter(new CCol($footerButtons));
$statusIcons = array(); if ($item['status'] == ITEM_STATUS_ACTIVE) { 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[] = $error; } if ($item['value_type'] == ITEM_VALUE_TYPE_FLOAT || $item['value_type'] == ITEM_VALUE_TYPE_UINT64) { $trendValue = $config['hk_trends_global'] ? $config['hk_trends'] : $item['trends']; } else { $trendValue = UNKNOWN_VALUE; } $row = new CRow(array(SPACE, is_show_all_nodes() ? $host['item_cnt'] ? SPACE : get_node_name_by_elid($item['itemid']) : null, $hostColumn, new CCol(new CDiv(array($item['name_expanded'], BR(), $itemKey), $stateCss . ' item')), new CCol(new CSpan($item['type'] == ITEM_TYPE_SNMPTRAP || $item['type'] == ITEM_TYPE_TRAPPER ? UNKNOWN_VALUE : $item['delay'], $stateCss)), new CCol(new CSpan($config['hk_history_global'] ? $config['hk_history'] : $item['history'], $stateCss)), new CCol(new CSpan($trendValue, $stateCss)), new CCol(new CSpan(item_type2str($item['type']), $stateCss)), new CCol(new CSpan($lastClock, $stateCss)), new CCol(new CSpan($lastValue, $stateCss)), new CCol(new CSpan($change, $stateCss)), $actions, $statusIcons)); } else { $row = new CRow(array(SPACE, is_show_all_nodes() ? $host['item_cnt'] ? SPACE : get_node_name_by_elid($item['itemid']) : null, $hostColumn, new CCol(new CSpan($item['name_expanded'], $stateCss . ' item')), new CCol(new CSpan($lastClock, $stateCss)), new CCol(new CSpan($lastValue, $stateCss)), new CCol(new CSpan($change, $stateCss)), $actions)); } $hosts[$item['hostid']]['item_cnt']++; $tab_rows[$item['hostid']][] = $row; } foreach ($hosts as $hostId => $dbHost) { $host = $hosts[$dbHost['hostid']]; if (!isset($tab_rows[$hostId])) { continue; } $appRows = $tab_rows[$hostId]; $openState = CProfile::get('web.latest.toggle_other', null, $host['hostid']); $toggle = new CDiv(SPACE, 'app-list-toggle icon-plus-9x9'); if ($openState) {
$usedInterfacesTypes[$item['type']] = itemTypeInterface($item['type']); } $initialItemType = min(array_keys($usedInterfacesTypes)); $data['type'] = get_request('type') !== null ? $data['type'] : $initialItemType; $data['initial_item_type'] = $initialItemType; $data['multiple_interface_types'] = count(array_unique($usedInterfacesTypes)) > 1; } // application if (count($data['applications']) == 0) { array_push($data['applications'], 0); } if (!empty($data['hostid'])) { $data['db_applications'] = DBfetchArray(DBselect('SELECT a.applicationid,a.name' . ' FROM applications a' . ' WHERE a.hostid=' . $data['hostid'] . ' ORDER BY a.name')); } // item types $data['itemTypes'] = item_type2str(); unset($data['itemTypes'][ITEM_TYPE_HTTPTEST]); // valuemap $data['valuemaps'] = DBfetchArray(DBselect('SELECT v.valuemapid,v.name FROM valuemaps v WHERE ' . DBin_node('v.valuemapid'))); order_result($data['valuemaps'], 'name'); // render view $itemView = new CView('configuration.item.massupdate', $data); $itemView->render(); $itemView->show(); } elseif ($_REQUEST['go'] == 'copy_to' && isset($_REQUEST['group_itemid'])) { $data = array('group_itemid' => get_request('group_itemid', array()), 'hostid' => get_request('hostid', 0), 'copy_type' => get_request('copy_type', 0), 'copy_groupid' => get_request('copy_groupid', 0), 'copy_targetid' => get_request('copy_targetid', array())); if (!is_array($data['group_itemid']) || is_array($data['group_itemid']) && count($data['group_itemid']) < 1) { error(_('Incorrect list of items.')); } else { // group $data['groups'] = API::HostGroup()->get(array('output' => API_OUTPUT_EXTEND));
$sec_300[$row['type']]++; } else { if ($diff <= 600) { $sec_600[$row['type']]++; } else { $sec_rest[$row['type']]++; } } } } } } } $table->setHeader(array(_('Items'), _('5 seconds'), _('10 seconds'), _('30 seconds'), _('1 minute'), _('5 minutes'), _('More than 10 minutes'))); foreach ($item_types as $type) { $table->addRow(array(item_type2str($type), getSeverityCell(TRIGGER_SEVERITY_NOT_CLASSIFIED, $sec_10[$type], !$sec_10[$type]), getSeverityCell(TRIGGER_SEVERITY_INFORMATION, $sec_30[$type], !$sec_30[$type]), getSeverityCell(TRIGGER_SEVERITY_WARNING, $sec_60[$type], !$sec_60[$type]), getSeverityCell(TRIGGER_SEVERITY_AVERAGE, $sec_300[$type], !$sec_300[$type]), getSeverityCell(TRIGGER_SEVERITY_HIGH, $sec_600[$type], !$sec_600[$type]), getSeverityCell(TRIGGER_SEVERITY_DISASTER, $sec_rest[$type], !$sec_rest[$type]))); } } else { if ($_REQUEST['config'] == 1) { $proxies = API::proxy()->get(array('output' => array('hostid', 'host'), 'preservekeys' => true)); order_result($proxies, 'host'); $proxies[0] = array('host' => _('Server')); foreach ($proxies as $proxyid => $proxy) { $sec_10[$proxyid] = 0; $sec_30[$proxyid] = 0; $sec_60[$proxyid] = 0; $sec_300[$proxyid] = 0; $sec_600[$proxyid] = 0; $sec_rest[$proxyid] = 0; } while ($row = DBfetch($result)) {
if (!empty($this->data['parent_discoveryid'])) { $itemForm->addVar('parent_discoveryid', $this->data['parent_discoveryid']); } if (!empty($this->data['itemid'])) { $itemForm->addVar('itemid', $this->data['itemid']); } // create form list $itemFormList = new CFormList('itemFormList'); if (!empty($this->data['templates'])) { $itemFormList->addRow(_('Parent discovery rules'), $this->data['templates']); } $itemFormList->addRow(_('Name'), (new CTextBox('name', $this->data['name'], $this->data['limited']))->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH)->setAttribute('autofocus', 'autofocus')); // append type to form list if ($this->data['limited']) { $itemForm->addVar('type', $this->data['type']); $itemFormList->addRow(_('Type'), (new CTextBox('typename', item_type2str($this->data['type']), true))->setWidth(ZBX_TEXTAREA_SMALL_WIDTH)); } else { $typeComboBox = (new CComboBox('type', $this->data['type']))->addItems($this->data['types']); $itemFormList->addRow(_('Type'), $typeComboBox); } // append key to form list $itemFormList->addRow(_('Key'), [(new CTextBox('key', $this->data['key'], $this->data['limited']))->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH)]); // append interfaces to form list if (!empty($this->data['interfaces'])) { $interfacesComboBox = new CComboBox('interfaceid', $this->data['interfaceid']); // set up interface groups $interfaceGroups = []; foreach (zbx_objectValues($this->data['interfaces'], 'type') as $interfaceType) { $interfaceGroups[$interfaceType] = new COptGroup(interfaceType2str($interfaceType)); } // add interfaces to groups
$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);";
/** * Get data for item edit page. * * @param array $item item, item prototype or LLD rule to take the data from * @param bool $options['is_discovery_rule'] * * @return array */ function getItemFormData(array $item = array(), array $options = array()) { $data = array('form' => getRequest('form'), 'form_refresh' => getRequest('form_refresh'), 'is_discovery_rule' => !empty($options['is_discovery_rule']), 'parent_discoveryid' => getRequest('parent_discoveryid', !empty($options['is_discovery_rule']) ? getRequest('itemid') : null), 'itemid' => getRequest('itemid'), 'limited' => false, 'interfaceid' => getRequest('interfaceid', 0), 'name' => getRequest('name', ''), 'description' => getRequest('description', ''), 'key' => getRequest('key', ''), 'hostname' => getRequest('hostname'), 'delay' => getRequest('delay', ZBX_ITEM_DELAY_DEFAULT), 'history' => getRequest('history', 90), 'status' => getRequest('status', isset($_REQUEST['form_refresh']) ? 1 : 0), 'type' => getRequest('type', 0), 'snmp_community' => getRequest('snmp_community', 'public'), 'snmp_oid' => getRequest('snmp_oid', 'interfaces.ifTable.ifEntry.ifInOctets.1'), 'port' => getRequest('port', ''), 'value_type' => getRequest('value_type', ITEM_VALUE_TYPE_UINT64), 'data_type' => getRequest('data_type', ITEM_DATA_TYPE_DECIMAL), 'trapper_hosts' => getRequest('trapper_hosts', ''), 'units' => getRequest('units', ''), 'valuemapid' => getRequest('valuemapid', 0), 'params' => getRequest('params', ''), 'multiplier' => getRequest('multiplier', 0), 'delta' => getRequest('delta', 0), 'trends' => getRequest('trends', DAY_IN_YEAR), 'new_application' => getRequest('new_application', ''), 'applications' => getRequest('applications', array()), 'delay_flex' => getRequest('delay_flex', array()), 'new_delay_flex' => getRequest('new_delay_flex', array('delay' => 50, 'period' => ZBX_DEFAULT_INTERVAL)), 'snmpv3_contextname' => getRequest('snmpv3_contextname', ''), 'snmpv3_securityname' => getRequest('snmpv3_securityname', ''), 'snmpv3_securitylevel' => getRequest('snmpv3_securitylevel', 0), 'snmpv3_authprotocol' => getRequest('snmpv3_authprotocol', ITEM_AUTHPROTOCOL_MD5), 'snmpv3_authpassphrase' => getRequest('snmpv3_authpassphrase', ''), 'snmpv3_privprotocol' => getRequest('snmpv3_privprotocol', ITEM_PRIVPROTOCOL_DES), 'snmpv3_privpassphrase' => getRequest('snmpv3_privpassphrase', ''), 'ipmi_sensor' => getRequest('ipmi_sensor', ''), 'authtype' => getRequest('authtype', 0), 'username' => getRequest('username', ''), 'password' => getRequest('password', ''), 'publickey' => getRequest('publickey', ''), 'privatekey' => getRequest('privatekey', ''), 'formula' => getRequest('formula', 1), 'logtimefmt' => getRequest('logtimefmt', ''), 'add_groupid' => getRequest('add_groupid', getRequest('groupid', 0)), 'valuemaps' => null, 'possibleHostInventories' => null, 'alreadyPopulated' => null, 'initial_item_type' => null, 'templates' => array()); // hostid if (!empty($data['parent_discoveryid'])) { $discoveryRule = API::DiscoveryRule()->get(array('itemids' => $data['parent_discoveryid'], 'output' => API_OUTPUT_EXTEND, 'editable' => true)); $discoveryRule = reset($discoveryRule); $data['hostid'] = $discoveryRule['hostid']; } else { $data['hostid'] = getRequest('hostid', 0); } // types, http items only for internal processes $data['types'] = item_type2str(); unset($data['types'][ITEM_TYPE_HTTPTEST]); if (!empty($options['is_discovery_rule'])) { unset($data['types'][ITEM_TYPE_AGGREGATE], $data['types'][ITEM_TYPE_CALCULATED], $data['types'][ITEM_TYPE_SNMPTRAP]); } // item if ($item) { $data['item'] = $item; $data['hostid'] = !empty($data['hostid']) ? $data['hostid'] : $data['item']['hostid']; $data['limited'] = $data['item']['templateid'] != 0; // get templates $itemid = $item['itemid']; do { $params = array('itemids' => $itemid, 'output' => array('itemid', 'templateid'), 'selectHosts' => array('name')); if ($data['is_discovery_rule']) { $item = API::DiscoveryRule()->get($params); } else { $params['selectDiscoveryRule'] = array('itemid'); $params['filter'] = array('flags' => null); $item = API::Item()->get($params); } $item = reset($item); if (!empty($item)) { $host = reset($item['hosts']); if (!empty($item['hosts'])) { $host['name'] = CHtml::encode($host['name']); if (bccomp($data['itemid'], $itemid) == 0) { } elseif ($data['is_discovery_rule']) { $data['templates'][] = new CLink($host['name'], 'host_discovery.php?form=update&itemid=' . $item['itemid'], 'highlight underline weight_normal'); $data['templates'][] = SPACE . '⇒' . SPACE; } elseif ($item['discoveryRule']) { $data['templates'][] = new CLink($host['name'], 'disc_prototypes.php?form=update&itemid=' . $item['itemid'] . '&parent_discoveryid=' . $item['discoveryRule']['itemid'], 'highlight underline weight_normal'); $data['templates'][] = SPACE . '⇒' . SPACE; } else { $data['templates'][] = new CLink($host['name'], 'items.php?form=update&itemid=' . $item['itemid'], 'highlight underline weight_normal'); $data['templates'][] = SPACE . '⇒' . SPACE; } } $itemid = $item['templateid']; } else { break; } } while ($itemid != 0); $data['templates'] = array_reverse($data['templates']); array_shift($data['templates']); } // caption if (!empty($data['is_discovery_rule'])) { $data['caption'] = _('Discovery rule'); } else { $data['caption'] = !empty($data['parent_discoveryid']) ? _('Item prototype') : _('Item'); } // hostname if (empty($data['is_discovery_rule']) && empty($data['hostname'])) { if (!empty($data['hostid'])) { $hostInfo = API::Host()->get(array('hostids' => $data['hostid'], 'output' => array('name'), 'templated_hosts' => true)); $hostInfo = reset($hostInfo); $data['hostname'] = $hostInfo['name']; } else { $data['hostname'] = _('not selected'); } } // fill data from item if (!hasRequest('form_refresh') && ($item || $data['limited'])) { $data['name'] = $data['item']['name']; $data['description'] = $data['item']['description']; $data['key'] = $data['item']['key_']; $data['interfaceid'] = $data['item']['interfaceid']; $data['type'] = $data['item']['type']; $data['snmp_community'] = $data['item']['snmp_community']; $data['snmp_oid'] = $data['item']['snmp_oid']; $data['port'] = $data['item']['port']; $data['value_type'] = $data['item']['value_type']; $data['data_type'] = $data['item']['data_type']; $data['trapper_hosts'] = $data['item']['trapper_hosts']; $data['units'] = $data['item']['units']; $data['valuemapid'] = $data['item']['valuemapid']; $data['multiplier'] = $data['item']['multiplier']; $data['hostid'] = $data['item']['hostid']; $data['params'] = $data['item']['params']; $data['snmpv3_contextname'] = $data['item']['snmpv3_contextname']; $data['snmpv3_securityname'] = $data['item']['snmpv3_securityname']; $data['snmpv3_securitylevel'] = $data['item']['snmpv3_securitylevel']; $data['snmpv3_authprotocol'] = $data['item']['snmpv3_authprotocol']; $data['snmpv3_authpassphrase'] = $data['item']['snmpv3_authpassphrase']; $data['snmpv3_privprotocol'] = $data['item']['snmpv3_privprotocol']; $data['snmpv3_privpassphrase'] = $data['item']['snmpv3_privpassphrase']; $data['ipmi_sensor'] = $data['item']['ipmi_sensor']; $data['authtype'] = $data['item']['authtype']; $data['username'] = $data['item']['username']; $data['password'] = $data['item']['password']; $data['publickey'] = $data['item']['publickey']; $data['privatekey'] = $data['item']['privatekey']; $data['logtimefmt'] = $data['item']['logtimefmt']; $data['new_application'] = getRequest('new_application', ''); if (!$data['is_discovery_rule']) { $data['formula'] = $data['item']['formula']; } if (!$data['limited'] || !isset($_REQUEST['form_refresh'])) { $data['delay'] = $data['item']['delay']; if (($data['type'] == ITEM_TYPE_TRAPPER || $data['type'] == ITEM_TYPE_SNMPTRAP) && $data['delay'] == 0) { $data['delay'] = ZBX_ITEM_DELAY_DEFAULT; } $data['history'] = $data['item']['history']; $data['status'] = $data['item']['status']; $data['delta'] = $data['item']['delta']; $data['trends'] = $data['item']['trends']; $db_delay_flex = $data['item']['delay_flex']; if (isset($db_delay_flex)) { $arr_of_dellays = explode(';', $db_delay_flex); foreach ($arr_of_dellays as $one_db_delay) { $arr_of_delay = explode('/', $one_db_delay); if (!isset($arr_of_delay[0]) || !isset($arr_of_delay[1])) { continue; } array_push($data['delay_flex'], array('delay' => $arr_of_delay[0], 'period' => $arr_of_delay[1])); } } $data['applications'] = array_unique(zbx_array_merge($data['applications'], get_applications_by_itemid($data['itemid']))); } } // applications if (count($data['applications']) == 0) { array_push($data['applications'], 0); } $data['db_applications'] = DBfetchArray(DBselect('SELECT DISTINCT a.applicationid,a.name' . ' FROM applications a' . ' WHERE a.hostid=' . zbx_dbstr($data['hostid']))); order_result($data['db_applications'], 'name'); // interfaces $data['interfaces'] = API::HostInterface()->get(array('hostids' => $data['hostid'], 'output' => API_OUTPUT_EXTEND)); // valuemapid if ($data['limited']) { if (!empty($data['valuemapid'])) { if ($map_data = DBfetch(DBselect('SELECT v.name FROM valuemaps v WHERE v.valuemapid=' . zbx_dbstr($data['valuemapid'])))) { $data['valuemaps'] = $map_data['name']; } } } else { $data['valuemaps'] = DBfetchArray(DBselect('SELECT v.* FROM valuemaps v')); order_result($data['valuemaps'], 'name'); } // possible host inventories if (empty($data['parent_discoveryid'])) { $data['possibleHostInventories'] = getHostInventories(); // get already populated fields by other items $data['alreadyPopulated'] = API::item()->get(array('output' => array('inventory_link'), 'filter' => array('hostid' => $data['hostid']), 'nopermissions' => true)); $data['alreadyPopulated'] = zbx_toHash($data['alreadyPopulated'], 'inventory_link'); } // template $data['is_template'] = isTemplate($data['hostid']); // unset snmpv3 fields if ($data['type'] != ITEM_TYPE_SNMPV3) { $data['snmpv3_contextname'] = ''; $data['snmpv3_securityname'] = ''; $data['snmpv3_securitylevel'] = ITEM_SNMPV3_SECURITYLEVEL_NOAUTHNOPRIV; $data['snmpv3_authprotocol'] = ITEM_AUTHPROTOCOL_MD5; $data['snmpv3_authpassphrase'] = ''; $data['snmpv3_privprotocol'] = ITEM_PRIVPROTOCOL_DES; $data['snmpv3_privpassphrase'] = ''; } // unset ssh auth fields if ($data['type'] != ITEM_TYPE_SSH) { $data['authtype'] = ITEM_AUTHTYPE_PASSWORD; $data['publickey'] = ''; $data['privatekey'] = ''; } return $data; }
$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(itemIndicator($item['status']), itemIndicatorStyle($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') { $form = new CForm(); $form->setName('applicationform'); $form->setAttribute('id', 'applications'); $table = new CTableInfo(_('No applications found.'));
$itemForm = (new CForm())->setName('items')->addVar('hostid', $this->data['hostid'])->addVar('parent_discoveryid', $this->data['parent_discoveryid']); // create table $itemTable = (new CTableInfo())->setHeader([(new CColHeader((new CCheckBox('all_items'))->onClick("checkAll('" . $itemForm->getName() . "', 'all_items', 'group_itemid');")))->addClass(ZBX_STYLE_CELL_WIDTH), make_sorting_header(_('Name'), 'name', $this->data['sort'], $this->data['sortorder']), 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(_('History'), 'history', $this->data['sort'], $this->data['sortorder']), make_sorting_header(_('Trends'), 'trends', $this->data['sort'], $this->data['sortorder']), make_sorting_header(_('Type'), 'type', $this->data['sort'], $this->data['sortorder']), _('Applications'), make_sorting_header(_('Status'), 'status', $this->data['sort'], $this->data['sortorder'])]); foreach ($this->data['items'] as $item) { $description = []; 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))->addClass(ZBX_STYLE_LINK_ALT)->addClass(ZBX_STYLE_GREY); $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'] . '&action=' . ($item['status'] == ITEM_STATUS_DISABLED ? 'itemprototype.massenable' : 'itemprototype.massdisable')))->addClass(ZBX_STYLE_LINK_ACTION)->addClass(itemIndicatorStyle($item['status']))->addSID(); 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([new CCheckBox('group_itemid[' . $item['itemid'] . ']', $item['itemid']), $description, $item['key_'], $item['delay'] !== '' ? convertUnitsS($item['delay']) : '', $item['history'] . _x('d', 'day short'), $item['trends'] !== '' ? $item['trends'] . _x('d', 'day short') : '', item_type2str($item['type']), $applications, $status]); } zbx_add_post_js('cookie.prefix = "' . $this->data['parent_discoveryid'] . '";'); // append table to form $itemForm->addItem([$itemTable, $this->data['paging'], new CActionButtonList('action', 'group_itemid', ['itemprototype.massenable' => ['name' => _('Enable'), 'confirm' => _('Enable selected item prototypes?')], 'itemprototype.massdisable' => ['name' => _('Disable'), 'confirm' => _('Disable selected item prototypes?')], 'itemprototype.massdelete' => ['name' => _('Delete'), 'confirm' => _('Delete selected item prototypes?')]], $this->data['parent_discoveryid'])]); // append form to widget $widget->addItem($itemForm); return $widget;
function insert_mass_update_item_form($elements_array_name) { global $USER_DETAILS; $frmItem = new CFormTable(S_ITEM, null, 'post'); $frmItem->SetHelp('web.items.item.php'); $frmItem->SetTitle(S_MASS_UPDATE); $frmItem->addVar('form_mass_update', 1); $frmItem->addVar('group_itemid', get_request('group_itemid', array())); $frmItem->addVar('config', get_request('config', 0)); if ($_REQUEST['groupid'] > 0) { $frmItem->addVar('groupid', $_REQUEST['groupid']); } $frmItem->addVar('hostid', $_REQUEST['hostid']); $description = get_request('description', ''); $key = get_request('key', ''); $host = get_request('host', null); $delay = get_request('delay', 30); $history = get_request('history', 90); $status = get_request('status', 0); $type = get_request('type', 0); $snmp_community = get_request('snmp_community', 'public'); $snmp_oid = get_request('snmp_oid', 'interfaces.ifTable.ifEntry.ifInOctets.1'); $snmp_port = get_request('snmp_port', 161); $value_type = get_request('value_type', ITEM_VALUE_TYPE_UINT64); $data_type = get_request('data_type', ITEM_DATA_TYPE_DECIMAL); $trapper_hosts = get_request('trapper_hosts', ''); $units = get_request('units', ''); $valuemapid = get_request('valuemapid', 0); $delta = get_request('delta', 0); $trends = get_request('trends', 365); $applications = get_request('applications', array()); $delay_flex = get_request('delay_flex', array()); $snmpv3_securityname = get_request('snmpv3_securityname', ''); $snmpv3_securitylevel = get_request('snmpv3_securitylevel', 0); $snmpv3_authpassphrase = get_request('snmpv3_authpassphrase', ''); $snmpv3_privpassphrase = get_request('snmpv3_privpassphrase', ''); $formula = get_request('formula', '1'); $logtimefmt = get_request('logtimefmt', ''); $add_groupid = get_request('add_groupid', get_request('groupid', 0)); $delay_flex_el = array(); $i = 0; foreach ($delay_flex as $val) { if (!isset($val['delay']) && !isset($val['period'])) { continue; } array_push($delay_flex_el, array(new CCheckBox('rem_delay_flex[]', 'no', null, $i), $val['delay'], ' sec at ', $val['period']), BR()); $frmItem->addVar("delay_flex[" . $i . "][delay]", $val['delay']); $frmItem->addVar("delay_flex[" . $i . "][period]", $val['period']); $i++; if ($i >= 7) { break; } /* limit count of intervals * 7 intervals by 30 symbols = 210 characters * db storage field is 256 */ } if (count($delay_flex_el) == 0) { array_push($delay_flex_el, "No flexible intervals"); } else { array_push($delay_flex_el, new CButton('del_delay_flex', 'delete selected')); } if (count($applications) == 0) { array_push($applications, 0); } $cmbType = new CComboBox('type', $type); foreach (array(ITEM_TYPE_ZABBIX, ITEM_TYPE_ZABBIX_ACTIVE, ITEM_TYPE_SIMPLE, ITEM_TYPE_SNMPV1, ITEM_TYPE_SNMPV2C, ITEM_TYPE_SNMPV3, ITEM_TYPE_TRAPPER, ITEM_TYPE_INTERNAL, ITEM_TYPE_AGGREGATE, ITEM_TYPE_AGGREGATE, ITEM_TYPE_EXTERNAL, ITEM_TYPE_DB_MONITOR) as $it) { $cmbType->addItem($it, item_type2str($it)); } $frmItem->addRow(array(new CVisibilityBox('type_visible', get_request('type_visible'), 'type', S_ORIGINAL), S_TYPE), $cmbType); $frmItem->addRow(array(new CVisibilityBox('community_visible', get_request('community_visible'), 'snmp_community', S_ORIGINAL), S_SNMP_COMMUNITY), new CTextBox('snmp_community', $snmp_community, 16)); $frmItem->addRow(array(new CVisibilityBox('securityname_visible', get_request('securityname_visible'), 'snmpv3_securityname', S_ORIGINAL), S_SNMPV3_SECURITY_NAME), new CTextBox('snmpv3_securityname', $snmpv3_securityname, 64)); $cmbSecLevel = new CComboBox('snmpv3_securitylevel', $snmpv3_securitylevel); $cmbSecLevel->addItem(ITEM_SNMPV3_SECURITYLEVEL_NOAUTHNOPRIV, "NoAuthPriv"); $cmbSecLevel->addItem(ITEM_SNMPV3_SECURITYLEVEL_AUTHNOPRIV, "AuthNoPriv"); $cmbSecLevel->addItem(ITEM_SNMPV3_SECURITYLEVEL_AUTHPRIV, "AuthPriv"); $frmItem->addRow(array(new CVisibilityBox('securitylevel_visible', get_request('securitylevel_visible'), 'snmpv3_securitylevel', S_ORIGINAL), S_SNMPV3_SECURITY_LEVEL), $cmbSecLevel); $frmItem->addRow(array(new CVisibilityBox('authpassphrase_visible', get_request('authpassphrase_visible'), 'snmpv3_authpassphrase', S_ORIGINAL), S_SNMPV3_AUTH_PASSPHRASE), new CTextBox('snmpv3_authpassphrase', $snmpv3_authpassphrase, 64)); $frmItem->addRow(array(new CVisibilityBox('privpassphras_visible', get_request('privpassphras_visible'), 'snmpv3_privpassphrase', S_ORIGINAL), S_SNMPV3_PRIV_PASSPHRASE), new CTextBox('snmpv3_privpassphrase', $snmpv3_privpassphrase, 64)); $frmItem->addRow(array(new CVisibilityBox('port_visible', get_request('port_visible'), 'snmp_port', S_ORIGINAL), S_SNMP_PORT), new CNumericBox('snmp_port', $snmp_port, 5)); $cmbValType = new CComboBox('value_type', $value_type); $cmbValType->AddItem(ITEM_VALUE_TYPE_UINT64, S_NUMERIC_UNSIGNED); $cmbValType->AddItem(ITEM_VALUE_TYPE_FLOAT, S_NUMERIC_FLOAT); $cmbValType->AddItem(ITEM_VALUE_TYPE_STR, S_CHARACTER); $cmbValType->AddItem(ITEM_VALUE_TYPE_LOG, S_LOG); $cmbValType->AddItem(ITEM_VALUE_TYPE_TEXT, S_TEXT); $frmItem->AddRow(array(new CVisibilityBox('value_type_visible', get_request('value_type_visible'), 'value_type', S_ORIGINAL), S_TYPE_OF_INFORMATION), $cmbValType); $cmbDataType = new CComboBox('data_type', $data_type); $cmbDataType->addItem(ITEM_DATA_TYPE_DECIMAL, item_data_type2str(ITEM_DATA_TYPE_DECIMAL)); $cmbDataType->addItem(ITEM_DATA_TYPE_OCTAL, item_data_type2str(ITEM_DATA_TYPE_OCTAL)); $cmbDataType->addItem(ITEM_DATA_TYPE_HEXADECIMAL, item_data_type2str(ITEM_DATA_TYPE_HEXADECIMAL)); $frmItem->addRow(array(new CVisibilityBox('data_type_visible', get_request('data_type_visible'), 'data_type', S_ORIGINAL), S_DATA_TYPE), $cmbDataType); $frmItem->addRow(array(new CVisibilityBox('units_visible', get_request('units_visible'), 'units', S_ORIGINAL), S_UNITS), new CTextBox('units', $units, 40)); $frmItem->addRow(array(new CVisibilityBox('formula_visible', get_request('formula_visible'), 'formula', S_ORIGINAL), S_CUSTOM_MULTIPLIER . ' (0 - ' . S_DISABLED . ')'), new CTextBox('formula', $formula, 40)); $frmItem->addRow(array(new CVisibilityBox('delay_visible', get_request('delay_visible'), 'delay', S_ORIGINAL), S_UPDATE_INTERVAL_IN_SEC), new CNumericBox('delay', $delay, 5)); $delay_flex_el = new CSpan($delay_flex_el); $delay_flex_el->addOption('id', 'delay_flex_list'); $frmItem->addRow(array(new CVisibilityBox('delay_flex_visible', get_request('delay_flex_visible'), array('delay_flex_list', 'new_delay_flex_el'), S_ORIGINAL), S_FLEXIBLE_INTERVALS), $delay_flex_el); $new_delay_flex_el = new CSpan(array(S_DELAY, SPACE, new CNumericBox("new_delay_flex[delay]", "50", 5), S_PERIOD, SPACE, new CTextBox("new_delay_flex[period]", "1-7,00:00-23:59", 27), BR(), new CButton("add_delay_flex", S_ADD))); $new_delay_flex_el->addOption('id', 'new_delay_flex_el'); $frmItem->addRow(S_NEW_FLEXIBLE_INTERVAL, $new_delay_flex_el, 'new'); $frmItem->addRow(array(new CVisibilityBox('history_visible', get_request('history_visible'), 'history', S_ORIGINAL), S_KEEP_HISTORY_IN_DAYS), new CNumericBox('history', $history, 8)); $frmItem->addRow(array(new CVisibilityBox('trends_visible', get_request('trends_visible'), 'trends', S_ORIGINAL), S_KEEP_TRENDS_IN_DAYS), new CNumericBox('trends', $trends, 8)); $cmbStatus = new CComboBox('status', $status); foreach (array(ITEM_STATUS_ACTIVE, ITEM_STATUS_DISABLED, ITEM_STATUS_NOTSUPPORTED) as $st) { $cmbStatus->addItem($st, item_status2str($st)); } $frmItem->addRow(array(new CVisibilityBox('status_visible', get_request('status_visible'), 'status', S_ORIGINAL), S_STATUS), $cmbStatus); $frmItem->addRow(array(new CVisibilityBox('logtimefmt_visible', get_request('logtimefmt_visible'), 'logtimefmt', S_ORIGINAL), S_LOG_TIME_FORMAT), new CTextBox("logtimefmt", $logtimefmt, 16)); $cmbDelta = new CComboBox('delta', $delta); $cmbDelta->addItem(0, S_AS_IS); $cmbDelta->addItem(1, S_DELTA_SPEED_PER_SECOND); $cmbDelta->addItem(2, S_DELTA_SIMPLE_CHANGE); $frmItem->addRow(array(new CVisibilityBox('delta_visible', get_request('delta_visible'), 'delta', S_ORIGINAL), S_STORE_VALUE), $cmbDelta); $cmbMap = new CComboBox('valuemapid', $valuemapid); $cmbMap->addItem(0, S_AS_IS); $db_valuemaps = DBselect('SELECT * FROM valuemaps WHERE ' . DBin_node('valuemapid')); while ($db_valuemap = DBfetch($db_valuemaps)) { $cmbMap->addItem($db_valuemap["valuemapid"], get_node_name_by_elid($db_valuemap["valuemapid"]) . $db_valuemap["name"]); } $link = new CLink("throw map", "config.php?config=6", "action"); $link->addOption("target", "_blank"); $frmItem->addRow(array(new CVisibilityBox('valuemapid_visible', get_request('valuemapid_visible'), 'valuemapid', S_ORIGINAL), S_SHOW_VALUE, SPACE, $link), $cmbMap); $frmItem->addRow(array(new CVisibilityBox('trapper_hosts_visible', get_request('trapper_hosts_visible'), 'trapper_hosts', S_ORIGINAL), S_ALLOWED_HOSTS), new CTextBox('trapper_hosts', $trapper_hosts, 40)); $cmbApps = new CListBox('applications[]', $applications, 6); $cmbApps->addItem(0, "-" . S_NONE . "-"); $db_applications = DBselect("SELECT DISTINCT applicationid,name FROM applications" . " WHERE hostid=" . $_REQUEST['hostid'] . " order by name"); while ($db_app = DBfetch($db_applications)) { $cmbApps->addItem($db_app["applicationid"], $db_app["name"]); } $frmItem->addRow(array(new CVisibilityBox('applications_visible', get_request('applications_visible'), 'applications[]', S_ORIGINAL), S_APPLICATIONS), $cmbApps); $frmItem->addItemToBottomRow(array(new CButton("update", S_UPDATE), SPACE, new CButtonCancel(url_param('groupid') . url_param("hostid") . url_param("config")))); $frmItem->Show(); }
$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 = '-'; } $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']), new CCol($applications, 'wraptext'), $status)); } // create go buttons $goComboBox = new CComboBox('go'); $goOption = new CComboItem('activate', _('Enable selected')); $goOption->setAttribute('confirm', _('Enable selected item prototypes?')); $goComboBox->addItem($goOption); $goOption = new CComboItem('disable', _('Disable selected')); $goOption->setAttribute('confirm', _('Disable selected item prototypes?')); $goComboBox->addItem($goOption); $goOption = new CComboItem('delete', _('Delete selected')); $goOption->setAttribute('confirm', _('Delete selected item prototypes?')); $goComboBox->addItem($goOption); $goButton = new CSubmit('goButton', _('Go') . ' (0)'); $goButton->setAttribute('id', 'goButton'); zbx_add_post_js('chkbxRange.pageGoName = "group_itemid";');
if ($filter['showDetails']) { // item key $itemKey = $item['type'] == ITEM_TYPE_HTTPTEST || $item['flags'] == ZBX_FLAG_DISCOVERY_CREATED ? (new CSpan($item['key_expanded']))->addClass(ZBX_STYLE_GREEN) : (new CLink($item['key_expanded'], 'items.php?form=update&itemid=' . $item['itemid']))->addClass(ZBX_STYLE_LINK_ALT)->addClass(ZBX_STYLE_GREEN); // info if ($item['status'] == ITEM_STATUS_ACTIVE && $item['error'] !== '') { $info = makeErrorIcon($item['error']); } else { $info = ''; } // trend value if ($item['value_type'] == ITEM_VALUE_TYPE_FLOAT || $item['value_type'] == ITEM_VALUE_TYPE_UINT64) { $trendValue = $config['hk_trends_global'] ? $config['hk_trends'] : $item['trends']; } else { $trendValue = UNKNOWN_VALUE; } $row = new CRow(['', $checkbox, $hostColumn, (new CCol([$item['name_expanded'], BR(), $itemKey]))->addClass($state_css), (new CCol($item['type'] == ITEM_TYPE_SNMPTRAP || $item['type'] == ITEM_TYPE_TRAPPER ? UNKNOWN_VALUE : $item['delay']))->addClass($state_css), (new CCol($config['hk_history_global'] ? $config['hk_history'] : $item['history']))->addClass($state_css), (new CCol($trendValue))->addClass($state_css), (new CCol(item_type2str($item['type'])))->addClass($state_css), (new CCol($lastClock))->addClass($state_css), (new CCol($lastValue))->addClass($state_css), (new CCol($change))->addClass($state_css), $actions, $info]); } else { $row = new CRow(['', $checkbox, $hostColumn, (new CCol($item['name_expanded']))->addClass($state_css), (new CCol($lastClock))->addClass($state_css), (new CCol($lastValue))->addClass($state_css), (new CCol($change))->addClass($state_css), $actions]); } $hosts[$item['hostid']]['item_cnt']++; $tab_rows[$item['hostid']][] = $row; } foreach ($hosts as $hostId => $dbHost) { $host = $hosts[$dbHost['hostid']]; if (!isset($tab_rows[$hostId])) { continue; } $appRows = $tab_rows[$hostId]; $open_state = CProfile::get('web.latest.toggle_other', null, $host['hostid']); $hostName = null; if (!$singleHostSelected) {