foreach ($linkedTemplates as $tpl) { $caption[] = new CLink($tpl['name'], 'templates.php?form=update&templateid=' . $tpl['templateid'], 'unknown'); $caption[] = ', '; } array_pop($caption); $caption[] = ')'; } $hostTemplates[] = $caption; $hostTemplates[] = ', '; } if ($hostTemplates) { array_pop($hostTemplates); } } // status $status = new CLink(item_status2str($hostPrototype['status']), '?group_hostid=' . $hostPrototype['hostid'] . '&parent_discoveryid=' . $discoveryRule['itemid'] . '&go=' . ($hostPrototype['status'] ? 'activate' : 'disable'), itemIndicatorStyle($hostPrototype['status'])); $hostTable->addRow(array(new CCheckBox('group_hostid[' . $hostPrototype['hostid'] . ']', null, null, $hostPrototype['hostid']), $name, new CCol($hostTemplates, 'wraptext'), $status)); } // create go buttons $goComboBox = new CComboBox('go'); $goOption = new CComboItem('activate', _('Activate selected')); $goOption->setAttribute('confirm', _('Enable selected host prototypes?')); $goComboBox->addItem($goOption); $goOption = new CComboItem('disable', _('Disable selected')); $goOption->setAttribute('confirm', _('Disable selected host prototypes?')); $goComboBox->addItem($goOption); $goOption = new CComboItem('delete', _('Delete selected')); $goOption->setAttribute('confirm', _('Delete selected host prototypes?')); $goComboBox->addItem($goOption); $goButton = new CSubmit('goButton', _('Go') . ' (0)'); $goButton->setAttribute('id', 'goButton');
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(); }
function getItemFilterForm(&$items) { $filter_groupId = $_REQUEST['filter_groupid']; $filter_hostId = $_REQUEST['filter_hostid']; $filter_application = $_REQUEST['filter_application']; $filter_name = $_REQUEST['filter_name']; $filter_type = $_REQUEST['filter_type']; $filter_key = $_REQUEST['filter_key']; $filter_snmp_community = $_REQUEST['filter_snmp_community']; $filter_snmpv3_securityname = $_REQUEST['filter_snmpv3_securityname']; $filter_snmp_oid = $_REQUEST['filter_snmp_oid']; $filter_port = $_REQUEST['filter_port']; $filter_value_type = $_REQUEST['filter_value_type']; $filter_data_type = $_REQUEST['filter_data_type']; $filter_delay = $_REQUEST['filter_delay']; $filter_history = $_REQUEST['filter_history']; $filter_trends = $_REQUEST['filter_trends']; $filter_status = $_REQUEST['filter_status']; $filter_state = $_REQUEST['filter_state']; $filter_templated_items = $_REQUEST['filter_templated_items']; $filter_with_triggers = $_REQUEST['filter_with_triggers']; $subfilter_hosts = $_REQUEST['subfilter_hosts']; $subfilter_apps = $_REQUEST['subfilter_apps']; $subfilter_types = $_REQUEST['subfilter_types']; $subfilter_value_types = $_REQUEST['subfilter_value_types']; $subfilter_status = $_REQUEST['subfilter_status']; $subfilter_state = $_REQUEST['subfilter_state']; $subfilter_templated_items = $_REQUEST['subfilter_templated_items']; $subfilter_with_triggers = $_REQUEST['subfilter_with_triggers']; $subfilter_history = $_REQUEST['subfilter_history']; $subfilter_trends = $_REQUEST['subfilter_trends']; $subfilter_interval = $_REQUEST['subfilter_interval']; $form = new CForm('get'); $form->setAttribute('name', 'zbx_filter'); $form->setAttribute('id', 'zbx_filter'); $form->addVar('subfilter_hosts', $subfilter_hosts); $form->addVar('subfilter_apps', $subfilter_apps); $form->addVar('subfilter_types', $subfilter_types); $form->addVar('subfilter_value_types', $subfilter_value_types); $form->addVar('subfilter_status', $subfilter_status); $form->addVar('subfilter_state', $subfilter_state); $form->addVar('subfilter_templated_items', $subfilter_templated_items); $form->addVar('subfilter_with_triggers', $subfilter_with_triggers); $form->addVar('subfilter_history', $subfilter_history); $form->addVar('subfilter_trends', $subfilter_trends); $form->addVar('subfilter_interval', $subfilter_interval); // type select $fTypeVisibility = array(); $cmbType = new CComboBox('filter_type', $filter_type); $cmbType->setAttribute('id', 'filter_type'); $cmbType->addItem(-1, _('all')); foreach (array('filter_delay_label', 'filter_delay') as $vItem) { zbx_subarray_push($fTypeVisibility, -1, $vItem); } $itemTypes = item_type2str(); unset($itemTypes[ITEM_TYPE_HTTPTEST]); // httptest items are only for internal zabbix logic $cmbType->addItems($itemTypes); foreach ($itemTypes as $typeNum => $typeLabel) { if ($typeNum != ITEM_TYPE_TRAPPER) { zbx_subarray_push($fTypeVisibility, $typeNum, 'filter_delay_label'); zbx_subarray_push($fTypeVisibility, $typeNum, 'filter_delay'); } switch ($typeNum) { case ITEM_TYPE_SNMPV1: case ITEM_TYPE_SNMPV2C: $snmp_types = array('filter_snmp_community_label', 'filter_snmp_community', 'filter_snmp_oid_label', 'filter_snmp_oid', 'filter_port_label', 'filter_port'); foreach ($snmp_types as $vItem) { zbx_subarray_push($fTypeVisibility, $typeNum, $vItem); } break; case ITEM_TYPE_SNMPV3: foreach (array('filter_snmpv3_securityname_label', 'filter_snmpv3_securityname', 'filter_snmp_oid_label', 'filter_snmp_oid', 'filter_port_label', 'filter_port') as $vItem) { zbx_subarray_push($fTypeVisibility, $typeNum, $vItem); } break; } } zbx_add_post_js("var filterTypeSwitcher = new CViewSwitcher('filter_type', 'change', " . zbx_jsvalue($fTypeVisibility, true) . ');'); // type of information select $fVTypeVisibility = array(); $cmbValType = new CComboBox('filter_value_type', $filter_value_type); $cmbValType->addItem(-1, _('all')); $cmbValType->addItem(ITEM_VALUE_TYPE_UINT64, _('Numeric (unsigned)')); $cmbValType->addItem(ITEM_VALUE_TYPE_FLOAT, _('Numeric (float)')); $cmbValType->addItem(ITEM_VALUE_TYPE_STR, _('Character')); $cmbValType->addItem(ITEM_VALUE_TYPE_LOG, _('Log')); $cmbValType->addItem(ITEM_VALUE_TYPE_TEXT, _('Text')); foreach (array('filter_data_type_label', 'filter_data_type') as $vItem) { zbx_subarray_push($fVTypeVisibility, ITEM_VALUE_TYPE_UINT64, $vItem); } zbx_add_post_js("var filterValueTypeSwitcher = new CViewSwitcher('filter_value_type', 'change', " . zbx_jsvalue($fVTypeVisibility, true) . ');'); // status select $cmbStatus = new CComboBox('filter_status', $filter_status); $cmbStatus->addItem(-1, _('all')); foreach (array(ITEM_STATUS_ACTIVE, ITEM_STATUS_DISABLED) as $status) { $cmbStatus->addItem($status, item_status2str($status)); } // state select $cmbState = new CComboBox('filter_state', $filter_state); $cmbState->addItem(-1, _('all')); foreach (array(ITEM_STATE_NORMAL, ITEM_STATE_NOTSUPPORTED) as $state) { $cmbState->addItem($state, itemState($state)); } // update interval $updateIntervalLabel = new CSpan(array(bold(_('Update interval')), SPACE . _('(in sec)') . NAME_DELIMITER)); $updateIntervalLabel->setAttribute('id', 'filter_delay_label'); $updateIntervalInput = new CNumericBox('filter_delay', $filter_delay, 5, false, true); $updateIntervalInput->setEnabled('no'); // data type $dataTypeLabel = new CSpan(bold(_('Data type') . NAME_DELIMITER)); $dataTypeLabel->setAttribute('id', 'filter_data_type_label'); $dataTypeInput = new CComboBox('filter_data_type', $filter_data_type); $dataTypeInput->addItem(-1, _('all')); $dataTypeInput->addItems(item_data_type2str()); $dataTypeInput->setEnabled('no'); // filter table $table = new CTable('', 'filter'); $table->setCellPadding(0); $table->setCellSpacing(0); // SNMP community $snmpCommunityLabel = new CSpan(array(bold(_('SNMP community')), SPACE . _('like') . NAME_DELIMITER)); $snmpCommunityLabel->setAttribute('id', 'filter_snmp_community_label'); $snmpCommunityField = new CTextBox('filter_snmp_community', $filter_snmp_community, ZBX_TEXTBOX_FILTER_SIZE); $snmpCommunityField->setEnabled('no'); // SNMPv3 security name $snmpSecurityLabel = new CSpan(array(bold(_('Security name')), SPACE . _('like') . NAME_DELIMITER)); $snmpSecurityLabel->setAttribute('id', 'filter_snmpv3_securityname_label'); $snmpSecurityField = new CTextBox('filter_snmpv3_securityname', $filter_snmpv3_securityname, ZBX_TEXTBOX_FILTER_SIZE); $snmpSecurityField->setEnabled('no'); // SNMP OID $snmpOidLabel = new CSpan(array(bold(_('SNMP OID')), SPACE . _('like') . NAME_DELIMITER)); $snmpOidLabel->setAttribute('id', 'filter_snmp_oid_label'); $snmpOidField = new CTextBox('filter_snmp_oid', $filter_snmp_oid, ZBX_TEXTBOX_FILTER_SIZE); $snmpOidField->setEnabled('no'); // port $portLabel = new CSpan(array(bold(_('Port')), SPACE . _('like') . NAME_DELIMITER)); $portLabel->setAttribute('id', 'filter_port_label'); $portField = new CNumericBox('filter_port', $filter_port, 5, false, true); $portField->setEnabled('no'); // row 1 $groupFilter = null; if (!empty($filter_groupId)) { $getHostInfo = API::HostGroup()->get(array('groupids' => $filter_groupId, 'output' => array('name'))); $getHostInfo = reset($getHostInfo); if (!empty($getHostInfo)) { $groupFilter[] = array('id' => $getHostInfo['groupid'], 'name' => $getHostInfo['name']); } } $table->addRow(array(new CCol(bold(_('Host group') . NAME_DELIMITER), 'label col1'), new CCol(array(new CMultiSelect(array('name' => 'filter_groupid', 'selectedLimit' => 1, 'objectName' => 'hostGroup', 'objectOptions' => array('editable' => true), 'data' => $groupFilter, 'popup' => array('parameters' => 'srctbl=host_groups&dstfrm=' . $form->getName() . '&dstfld1=filter_groupid' . '&srcfld1=groupid&writeonly=1', 'width' => 450, 'height' => 450, 'buttonClass' => 'input filter-multiselect-select-button')))), 'col1'), new CCol(bold(_('Type') . NAME_DELIMITER), 'label col2'), new CCol($cmbType, 'col2'), new CCol(bold(_('Type of information') . NAME_DELIMITER), 'label col3'), new CCol($cmbValType, 'col3'), new CCol(bold(_('State') . NAME_DELIMITER), 'label'), new CCol($cmbState, 'col4')), 'item-list-row'); // row 2 $hostFilterData = null; if (!empty($filter_hostId)) { $getHostInfo = API::Host()->get(array('hostids' => $filter_hostId, 'templated_hosts' => true, 'output' => array('name'))); $getHostInfo = reset($getHostInfo); if (!empty($getHostInfo)) { $hostFilterData[] = array('id' => $getHostInfo['hostid'], 'name' => $getHostInfo['name']); } } $table->addRow(array(new CCol(bold(_('Host') . NAME_DELIMITER), 'label'), new CCol(array(new CMultiSelect(array('name' => 'filter_hostid', 'selectedLimit' => 1, 'objectName' => 'hosts', 'objectOptions' => array('editable' => true, 'templated_hosts' => true), 'data' => $hostFilterData, 'popup' => array('parameters' => 'srctbl=host_templates&dstfrm=' . $form->getName() . '&dstfld1=filter_hostid' . '&srcfld1=hostid&writeonly=1', 'width' => 450, 'height' => 450, 'buttonClass' => 'input filter-multiselect-select-button')))), 'col1'), new CCol($updateIntervalLabel, 'label'), new CCol($updateIntervalInput), new CCol($dataTypeLabel, 'label'), new CCol($dataTypeInput), new CCol(bold(_('Status') . NAME_DELIMITER), 'label col4'), new CCol($cmbStatus, 'col4')), 'item-list-row'); // row 3 $table->addRow(array(new CCol(bold(_('Application') . NAME_DELIMITER), 'label'), new CCol(array(new CTextBox('filter_application', $filter_application, ZBX_TEXTBOX_FILTER_SIZE), new CButton('btn_app', _('Select'), 'return PopUp("popup.php?srctbl=applications&srcfld1=name' . '&dstfrm=' . $form->getName() . '&dstfld1=filter_application' . '&with_applications=1' . '" + (jQuery("input[name=\'filter_hostid\']").length > 0 ? "&hostid="+jQuery("input[name=\'filter_hostid\']").val() : "")' . ', 550, 450, "application");', 'filter-select-button')), 'col1'), new CCol(array($snmpCommunityLabel, $snmpSecurityLabel), 'label'), new CCol(array($snmpCommunityField, $snmpSecurityField)), new CCol(array(bold(_('History')), SPACE . _('(in days)') . NAME_DELIMITER), 'label'), new CCol(new CNumericBox('filter_history', $filter_history, 8, false, true)), new CCol(bold(_('Triggers') . NAME_DELIMITER), 'label'), new CCol(new CComboBox('filter_with_triggers', $filter_with_triggers, null, array(-1 => _('all'), 1 => _('With triggers'), 0 => _('Without triggers'))))), 'item-list-row'); // row 4 $table->addRow(array(new CCol(array(bold(_('Name')), SPACE . _('like') . NAME_DELIMITER), 'label'), new CCol(new CTextBox('filter_name', $filter_name, ZBX_TEXTBOX_FILTER_SIZE), 'col1'), new CCol($snmpOidLabel, 'label'), new CCol($snmpOidField), new CCol(array(bold(_('Trends')), SPACE . _('(in days)') . NAME_DELIMITER), 'label'), new CCol(new CNumericBox('filter_trends', $filter_trends, 8, false, true)), new CCol(bold(_('Template') . NAME_DELIMITER), 'label'), new CCol(new CComboBox('filter_templated_items', $filter_templated_items, null, array(-1 => _('all'), 1 => _('Templated items'), 0 => _('Not Templated items'))))), 'item-list-row'); // row 5 $table->addRow(array(new CCol(array(bold(_('Key')), SPACE . _('like') . NAME_DELIMITER), 'label'), new CCol(new CTextBox('filter_key', $filter_key, ZBX_TEXTBOX_FILTER_SIZE), 'col1'), new CCol($portLabel, 'label'), new CCol($portField), new CCol(null, 'label'), new CCol(), new CCol(null, 'label'), new CCol()), 'item-list-row'); $filter = new CSubmit('filter_set', _('Filter'), 'chkbxRange.clearSelectedOnFilterChange();'); $filter->useJQueryStyle('main'); $reset = new CSubmit('filter_rst', _('Reset'), 'chkbxRange.clearSelectedOnFilterChange();'); $reset->useJQueryStyle(); $div_buttons = new CDiv(array($filter, SPACE, $reset)); $div_buttons->setAttribute('style', 'padding: 4px 0px;'); $footer = new CCol($div_buttons, 'controls', 8); $table->addRow($footer); $form->addItem($table); // subfilters $table_subfilter = new CTable(null, 'filter sub-filter'); // array contains subfilters and number of items in each $item_params = array('hosts' => array(), 'applications' => array(), 'types' => array(), 'value_types' => array(), 'status' => array(), 'state' => array(), 'templated_items' => array(), 'with_triggers' => array(), 'history' => array(), 'trends' => array(), 'interval' => array()); // generate array with values for subfilters of selected items foreach ($items as $item) { // hosts if (zbx_empty($filter_hostId)) { $host = reset($item['hosts']); if (!isset($item_params['hosts'][$host['hostid']])) { $item_params['hosts'][$host['hostid']] = array('name' => $host['name'], 'count' => 0); } $show_item = true; foreach ($item['subfilters'] as $name => $value) { if ($name == 'subfilter_hosts') { continue; } $show_item &= $value; } if ($show_item) { $host = reset($item['hosts']); $item_params['hosts'][$host['hostid']]['count']++; } } // applications if (!empty($item['applications'])) { foreach ($item['applications'] as $application) { if (!isset($item_params['applications'][$application['name']])) { $item_params['applications'][$application['name']] = array('name' => $application['name'], 'count' => 0); } } } $show_item = true; foreach ($item['subfilters'] as $name => $value) { if ($name == 'subfilter_apps') { continue; } $show_item &= $value; } $sel_app = false; if ($show_item) { // if any of item applications are selected foreach ($item['applications'] as $app) { if (str_in_array($app['name'], $subfilter_apps)) { $sel_app = true; break; } } foreach ($item['applications'] as $app) { if (str_in_array($app['name'], $subfilter_apps) || !$sel_app) { $item_params['applications'][$app['name']]['count']++; } } } // types if ($filter_type == -1) { if (!isset($item_params['types'][$item['type']])) { $item_params['types'][$item['type']] = array('name' => item_type2str($item['type']), 'count' => 0); } $show_item = true; foreach ($item['subfilters'] as $name => $value) { if ($name == 'subfilter_types') { continue; } $show_item &= $value; } if ($show_item) { $item_params['types'][$item['type']]['count']++; } } // value types if ($filter_value_type == -1) { if (!isset($item_params['value_types'][$item['value_type']])) { $item_params['value_types'][$item['value_type']] = array('name' => itemValueTypeString($item['value_type']), 'count' => 0); } $show_item = true; foreach ($item['subfilters'] as $name => $value) { if ($name == 'subfilter_value_types') { continue; } $show_item &= $value; } if ($show_item) { $item_params['value_types'][$item['value_type']]['count']++; } } // status if ($filter_status == -1) { if (!isset($item_params['status'][$item['status']])) { $item_params['status'][$item['status']] = array('name' => item_status2str($item['status']), 'count' => 0); } $show_item = true; foreach ($item['subfilters'] as $name => $value) { if ($name == 'subfilter_status') { continue; } $show_item &= $value; } if ($show_item) { $item_params['status'][$item['status']]['count']++; } } // state if ($filter_state == -1) { if (!isset($item_params['state'][$item['state']])) { $item_params['state'][$item['state']] = array('name' => itemState($item['state']), 'count' => 0); } $show_item = true; foreach ($item['subfilters'] as $name => $value) { if ($name == 'subfilter_state') { continue; } $show_item &= $value; } if ($show_item) { $item_params['state'][$item['state']]['count']++; } } // template if ($filter_templated_items == -1) { if ($item['templateid'] == 0 && !isset($item_params['templated_items'][0])) { $item_params['templated_items'][0] = array('name' => _('Not Templated items'), 'count' => 0); } elseif ($item['templateid'] > 0 && !isset($item_params['templated_items'][1])) { $item_params['templated_items'][1] = array('name' => _('Templated items'), 'count' => 0); } $show_item = true; foreach ($item['subfilters'] as $name => $value) { if ($name == 'subfilter_templated_items') { continue; } $show_item &= $value; } if ($show_item) { if ($item['templateid'] == 0) { $item_params['templated_items'][0]['count']++; } else { $item_params['templated_items'][1]['count']++; } } } // with triggers if ($filter_with_triggers == -1) { if (count($item['triggers']) == 0 && !isset($item_params['with_triggers'][0])) { $item_params['with_triggers'][0] = array('name' => _('Without triggers'), 'count' => 0); } elseif (count($item['triggers']) > 0 && !isset($item_params['with_triggers'][1])) { $item_params['with_triggers'][1] = array('name' => _('With triggers'), 'count' => 0); } $show_item = true; foreach ($item['subfilters'] as $name => $value) { if ($name == 'subfilter_with_triggers') { continue; } $show_item &= $value; } if ($show_item) { if (count($item['triggers']) == 0) { $item_params['with_triggers'][0]['count']++; } else { $item_params['with_triggers'][1]['count']++; } } } // trends if (zbx_empty($filter_trends)) { if (!isset($item_params['trends'][$item['trends']])) { $item_params['trends'][$item['trends']] = array('name' => $item['trends'], 'count' => 0); } $show_item = true; foreach ($item['subfilters'] as $name => $value) { if ($name == 'subfilter_trends') { continue; } $show_item &= $value; } if ($show_item) { $item_params['trends'][$item['trends']]['count']++; } } // history if (zbx_empty($filter_history)) { if (!isset($item_params['history'][$item['history']])) { $item_params['history'][$item['history']] = array('name' => $item['history'], 'count' => 0); } $show_item = true; foreach ($item['subfilters'] as $name => $value) { if ($name == 'subfilter_history') { continue; } $show_item &= $value; } if ($show_item) { $item_params['history'][$item['history']]['count']++; } } // interval if (zbx_empty($filter_delay) && $filter_type != ITEM_TYPE_TRAPPER) { if (!isset($item_params['interval'][$item['delay']])) { $item_params['interval'][$item['delay']] = array('name' => $item['delay'], 'count' => 0); } $show_item = true; foreach ($item['subfilters'] as $name => $value) { if ($name == 'subfilter_interval') { continue; } $show_item &= $value; } if ($show_item) { $item_params['interval'][$item['delay']]['count']++; } } } // output if (zbx_empty($filter_hostId) && count($item_params['hosts']) > 1) { $hosts_output = prepareSubfilterOutput($item_params['hosts'], $subfilter_hosts, 'subfilter_hosts'); $table_subfilter->addRow(array(_('Hosts'), $hosts_output)); } if (!empty($item_params['applications']) && count($item_params['applications']) > 1) { $application_output = prepareSubfilterOutput($item_params['applications'], $subfilter_apps, 'subfilter_apps'); $table_subfilter->addRow(array(_('Applications'), $application_output)); } if ($filter_type == -1 && count($item_params['types']) > 1) { $type_output = prepareSubfilterOutput($item_params['types'], $subfilter_types, 'subfilter_types'); $table_subfilter->addRow(array(_('Types'), $type_output)); } if ($filter_value_type == -1 && count($item_params['value_types']) > 1) { $value_types_output = prepareSubfilterOutput($item_params['value_types'], $subfilter_value_types, 'subfilter_value_types'); $table_subfilter->addRow(array(_('Type of information'), $value_types_output)); } if ($filter_status == -1 && count($item_params['status']) > 1) { $status_output = prepareSubfilterOutput($item_params['status'], $subfilter_status, 'subfilter_status'); $table_subfilter->addRow(array(_('Status'), $status_output)); } if ($filter_state == -1 && count($item_params['state']) > 1) { $state_output = prepareSubfilterOutput($item_params['state'], $subfilter_state, 'subfilter_state'); $table_subfilter->addRow(array(_('State'), $state_output)); } if ($filter_templated_items == -1 && count($item_params['templated_items']) > 1) { $templated_items_output = prepareSubfilterOutput($item_params['templated_items'], $subfilter_templated_items, 'subfilter_templated_items'); $table_subfilter->addRow(array(_('Template'), $templated_items_output)); } if ($filter_with_triggers == -1 && count($item_params['with_triggers']) > 1) { $with_triggers_output = prepareSubfilterOutput($item_params['with_triggers'], $subfilter_with_triggers, 'subfilter_with_triggers'); $table_subfilter->addRow(array(_('With triggers'), $with_triggers_output)); } if (zbx_empty($filter_history) && count($item_params['history']) > 1) { $history_output = prepareSubfilterOutput($item_params['history'], $subfilter_history, 'subfilter_history'); $table_subfilter->addRow(array(_('History'), $history_output)); } if (zbx_empty($filter_trends) && count($item_params['trends']) > 1) { $trends_output = prepareSubfilterOutput($item_params['trends'], $subfilter_trends, 'subfilter_trends'); $table_subfilter->addRow(array(_('Trends'), $trends_output)); } if (zbx_empty($filter_delay) && $filter_type != ITEM_TYPE_TRAPPER && count($item_params['interval']) > 1) { $interval_output = prepareSubfilterOutput($item_params['interval'], $subfilter_interval, 'subfilter_interval'); $table_subfilter->addRow(array(_('Interval'), $interval_output)); } $form->addItem(new CDiv(_('Subfilter [affects only filtered data!]'), 'thin_header')); $form->addItem($table_subfilter); return $form; }
$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')));
} $itemFormList->addRow(array(_('Flexible intervals'), SPACE, new CVisibilityBox('visible[delay_flex]', isset($this->data['visible']['delay_flex']), array('delayFlexDiv', 'row-new-delay-flex-fields'), _('Original'))), new CDiv($delayFlexTable, 'objectgroup inlineblock border_dotted ui-corner-all', 'delayFlexDiv')); // append new delay to form list $newFlexInt = new CDiv(array(_('Interval (in sec)'), SPACE, new CNumericBox('new_delay_flex[delay]', 50, 5), SPACE, _('Period'), SPACE, new CTextBox('new_delay_flex[period]', ZBX_DEFAULT_INTERVAL, 20), SPACE, new CSubmit('add_delay_flex', _('Add'), null, 'formlist')), null, 'row-new-delay-flex-fields'); $maxFlexMsg = new CSpan(_('Maximum number of flexible intervals added'), 'red'); $maxFlexMsg->setAttribute('id', 'row-new-delay-flex-max-reached'); $maxFlexMsg->setAttribute('style', 'display: none;'); $itemFormList->addRow(_('New flexible interval'), array($newFlexInt, $maxFlexMsg), false, 'row_new_delay_flex', 'new'); // append history to form list $itemFormList->addRow(array(_('History storage period (in days)'), SPACE, new CVisibilityBox('visible[history]', isset($this->data['visible']['history']), 'history', _('Original'))), new CNumericBox('history', $this->data['history'], 8)); // append trends to form list $itemFormList->addRow(array(_('Trend storage period (in days)'), SPACE, new CVisibilityBox('visible[trends]', isset($this->data['visible']['trends']), 'trends', _('Original'))), new CNumericBox('trends', $this->data['trends'], 8)); // append status to form list $statusComboBox = new CComboBox('status', $this->data['status']); foreach (array(ITEM_STATUS_ACTIVE, ITEM_STATUS_DISABLED) as $status) { $statusComboBox->addItem($status, item_status2str($status)); } $itemFormList->addRow(array(_('Status'), SPACE, new CVisibilityBox('visible[status]', isset($this->data['visible']['status']), 'status', _('Original'))), $statusComboBox); // append logtime to form list $itemFormList->addRow(array(_('Log time format'), SPACE, new CVisibilityBox('visible[logtimefmt]', isset($this->data['visible']['logtimefmt']), 'logtimefmt', _('Original'))), new CTextBox('logtimefmt', $this->data['logtimefmt'], ZBX_TEXTBOX_SMALL_SIZE)); // append delta to form list $deltaComboBox = new CComboBox('delta', $this->data['delta']); $deltaComboBox->addItem(0, _('As is')); $deltaComboBox->addItem(1, _('Delta (speed per second)')); $deltaComboBox->addItem(2, _('Delta (simple change)')); $itemFormList->addRow(array(_('Store value'), SPACE, new CVisibilityBox('visible[delta]', isset($this->data['visible']['delta']), 'delta', _('Original'))), $deltaComboBox); // append valuemap to form list $valueMapsComboBox = new CComboBox('valuemapid', $this->data['valuemapid']); $valueMapsComboBox->addItem(0, _('As is')); foreach ($this->data['valuemaps'] as $valuemap) { $valueMapsComboBox->addItem($valuemap['valuemapid'], get_node_name_by_elid($valuemap['valuemapid'], null, NAME_DELIMITER) . $valuemap['name']);
function getItemFilterForm(&$items) { $filter_groupId = $_REQUEST['filter_groupid']; $filter_hostId = $_REQUEST['filter_hostid']; $filter_application = $_REQUEST['filter_application']; $filter_name = $_REQUEST['filter_name']; $filter_type = $_REQUEST['filter_type']; $filter_key = $_REQUEST['filter_key']; $filter_snmp_community = $_REQUEST['filter_snmp_community']; $filter_snmpv3_securityname = $_REQUEST['filter_snmpv3_securityname']; $filter_snmp_oid = $_REQUEST['filter_snmp_oid']; $filter_port = $_REQUEST['filter_port']; $filter_value_type = $_REQUEST['filter_value_type']; $filter_data_type = $_REQUEST['filter_data_type']; $filter_delay = $_REQUEST['filter_delay']; $filter_history = $_REQUEST['filter_history']; $filter_trends = $_REQUEST['filter_trends']; $filter_status = $_REQUEST['filter_status']; $filter_state = $_REQUEST['filter_state']; $filter_templated_items = $_REQUEST['filter_templated_items']; $filter_with_triggers = $_REQUEST['filter_with_triggers']; $subfilter_hosts = $_REQUEST['subfilter_hosts']; $subfilter_apps = $_REQUEST['subfilter_apps']; $subfilter_types = $_REQUEST['subfilter_types']; $subfilter_value_types = $_REQUEST['subfilter_value_types']; $subfilter_status = $_REQUEST['subfilter_status']; $subfilter_state = $_REQUEST['subfilter_state']; $subfilter_templated_items = $_REQUEST['subfilter_templated_items']; $subfilter_with_triggers = $_REQUEST['subfilter_with_triggers']; $subfilter_history = $_REQUEST['subfilter_history']; $subfilter_trends = $_REQUEST['subfilter_trends']; $subfilter_interval = $_REQUEST['subfilter_interval']; $form = (new CFilter('web.items.filter.state'))->addVar('subfilter_hosts', $subfilter_hosts)->addVar('subfilter_apps', $subfilter_apps)->addVar('subfilter_types', $subfilter_types)->addVar('subfilter_value_types', $subfilter_value_types)->addVar('subfilter_status', $subfilter_status)->addVar('subfilter_state', $subfilter_state)->addVar('subfilter_templated_items', $subfilter_templated_items)->addVar('subfilter_with_triggers', $subfilter_with_triggers)->addVar('subfilter_history', $subfilter_history)->addVar('subfilter_trends', $subfilter_trends)->addVar('subfilter_interval', $subfilter_interval); $filterColumn1 = new CFormList(); $filterColumn2 = new CFormList(); $filterColumn3 = new CFormList(); $filterColumn4 = new CFormList(); // type select $fTypeVisibility = []; $cmbType = new CComboBox('filter_type', $filter_type, null, [-1 => _('all')]); zbx_subarray_push($fTypeVisibility, -1, 'filter_delay_row'); $item_types = item_type2str(); unset($item_types[ITEM_TYPE_HTTPTEST]); // httptest items are only for internal zabbix logic $cmbType->addItems($item_types); foreach ($item_types as $type => $name) { if ($type != ITEM_TYPE_TRAPPER && $type != ITEM_TYPE_SNMPTRAP) { zbx_subarray_push($fTypeVisibility, $type, 'filter_delay_row'); } switch ($type) { case ITEM_TYPE_SNMPV1: case ITEM_TYPE_SNMPV2C: zbx_subarray_push($fTypeVisibility, $type, 'filter_snmp_community_row'); zbx_subarray_push($fTypeVisibility, $type, 'filter_snmp_oid_row'); zbx_subarray_push($fTypeVisibility, $type, 'filter_port_row'); break; case ITEM_TYPE_SNMPV3: zbx_subarray_push($fTypeVisibility, $type, 'filter_snmpv3_securityname_row'); zbx_subarray_push($fTypeVisibility, $type, 'filter_snmp_oid_row'); zbx_subarray_push($fTypeVisibility, $type, 'filter_port_row'); break; } } zbx_add_post_js("var filterTypeSwitcher = new CViewSwitcher('filter_type', 'change', " . zbx_jsvalue($fTypeVisibility, true) . ');'); // type of information select $fVTypeVisibility = []; zbx_subarray_push($fVTypeVisibility, ITEM_VALUE_TYPE_UINT64, 'filter_data_type_row'); zbx_add_post_js("var filterValueTypeSwitcher = new CViewSwitcher('filter_value_type', 'change', " . zbx_jsvalue($fVTypeVisibility, true) . ');'); // row 1 $groupFilter = null; if (!empty($filter_groupId)) { $getHostInfo = API::HostGroup()->get(['groupids' => $filter_groupId, 'output' => ['name']]); $getHostInfo = reset($getHostInfo); if (!empty($getHostInfo)) { $groupFilter[] = ['id' => $getHostInfo['groupid'], 'name' => $getHostInfo['name']]; } } $filterColumn1->addRow(_('Host group'), (new CMultiSelect(['name' => 'filter_groupid', 'selectedLimit' => 1, 'objectName' => 'hostGroup', 'objectOptions' => ['editable' => true], 'data' => $groupFilter, 'popup' => ['parameters' => 'srctbl=host_groups&dstfrm=' . $form->getName() . '&dstfld1=filter_groupid' . '&srcfld1=groupid&writeonly=1']]))->setWidth(ZBX_TEXTAREA_FILTER_SMALL_WIDTH)); $filterColumn2->addRow(_('Type'), $cmbType); $filterColumn3->addRow(_('Type of information'), new CComboBox('filter_value_type', $filter_value_type, null, [-1 => _('all'), ITEM_VALUE_TYPE_UINT64 => _('Numeric (unsigned)'), ITEM_VALUE_TYPE_FLOAT => _('Numeric (float)'), ITEM_VALUE_TYPE_STR => _('Character'), ITEM_VALUE_TYPE_LOG => _('Log'), ITEM_VALUE_TYPE_TEXT => _('Text')])); $filterColumn4->addRow(_('State'), new CComboBox('filter_state', $filter_state, null, [-1 => _('all'), ITEM_STATE_NORMAL => itemState(ITEM_STATE_NORMAL), ITEM_STATE_NOTSUPPORTED => itemState(ITEM_STATE_NOTSUPPORTED)])); // row 2 $hostFilterData = null; if (!empty($filter_hostId)) { $getHostInfo = API::Host()->get(['hostids' => $filter_hostId, 'templated_hosts' => true, 'output' => ['name']]); $getHostInfo = reset($getHostInfo); if (!empty($getHostInfo)) { $hostFilterData[] = ['id' => $getHostInfo['hostid'], 'name' => $getHostInfo['name']]; } } $filterColumn1->addRow(_('Host'), (new CMultiSelect(['name' => 'filter_hostid', 'selectedLimit' => 1, 'objectName' => 'hosts', 'objectOptions' => ['editable' => true, 'templated_hosts' => true], 'data' => $hostFilterData, 'popup' => ['parameters' => 'srctbl=host_templates&dstfrm=' . $form->getName() . '&dstfld1=filter_hostid' . '&srcfld1=hostid&writeonly=1']]))->setWidth(ZBX_TEXTAREA_FILTER_SMALL_WIDTH)); $filterColumn2->addRow(_('Update interval (in sec)'), (new CNumericBox('filter_delay', $filter_delay, 5, false, true))->setWidth(ZBX_TEXTAREA_NUMERIC_STANDARD_WIDTH), 'filter_delay_row'); $filterColumn3->addRow(_('Data type'), (new CComboBox('filter_data_type', $filter_data_type))->addItem(-1, _('all'))->addItems(item_data_type2str()), 'filter_data_type_row'); $filterColumn4->addRow(_('Status'), new CComboBox('filter_status', $filter_status, null, [-1 => _('all'), ITEM_STATUS_ACTIVE => item_status2str(ITEM_STATUS_ACTIVE), ITEM_STATUS_DISABLED => item_status2str(ITEM_STATUS_DISABLED)])); // row 3 $filterColumn1->addRow(_('Application'), [(new CTextBox('filter_application', $filter_application))->setWidth(ZBX_TEXTAREA_FILTER_SMALL_WIDTH), (new CDiv())->addClass(ZBX_STYLE_FORM_INPUT_MARGIN), (new CButton(null, _('Select')))->addClass(ZBX_STYLE_BTN_GREY)->onClick('return PopUp("popup.php?srctbl=applications&srcfld1=name' . '&dstfrm=' . $form->getName() . '&dstfld1=filter_application' . '&with_applications=1' . '" + (jQuery("input[name=\'filter_hostid\']").length > 0 ? "&hostid="+jQuery("input[name=\'filter_hostid\']").val() : "")' . ', 0, 0, "application");')]); $filterColumn2->addRow(_('SNMP community'), (new CTextBox('filter_snmp_community', $filter_snmp_community))->setWidth(ZBX_TEXTAREA_FILTER_SMALL_WIDTH), 'filter_snmp_community_row'); $filterColumn2->addRow(_('Security name'), (new CTextBox('filter_snmpv3_securityname', $filter_snmpv3_securityname))->setWidth(ZBX_TEXTAREA_FILTER_SMALL_WIDTH), 'filter_snmpv3_securityname_row'); $filterColumn3->addRow(_('History (in days)'), (new CNumericBox('filter_history', $filter_history, 8, false, true))->setWidth(ZBX_TEXTAREA_NUMERIC_STANDARD_WIDTH)); $filterColumn4->addRow(_('Triggers'), new CComboBox('filter_with_triggers', $filter_with_triggers, null, [-1 => _('all'), 1 => _('With triggers'), 0 => _('Without triggers')])); // row 4 $filterColumn1->addRow(_('Name like'), (new CTextBox('filter_name', $filter_name))->setWidth(ZBX_TEXTAREA_FILTER_SMALL_WIDTH)); $filterColumn2->addRow(_('SNMP OID'), (new CTextBox('filter_snmp_oid', $filter_snmp_oid))->setWidth(ZBX_TEXTAREA_FILTER_SMALL_WIDTH), 'filter_snmp_oid_row'); $filterColumn3->addRow(_('Trends (in days)'), (new CNumericBox('filter_trends', $filter_trends, 8, false, true))->setWidth(ZBX_TEXTAREA_NUMERIC_STANDARD_WIDTH)); $filterColumn4->addRow(_('Template'), new CComboBox('filter_templated_items', $filter_templated_items, null, [-1 => _('all'), 1 => _('Templated items'), 0 => _('Not Templated items')])); // row 5 $filterColumn1->addRow(_('Key like'), (new CTextBox('filter_key', $filter_key))->setWidth(ZBX_TEXTAREA_FILTER_SMALL_WIDTH)); $filterColumn2->addRow(_('Port'), (new CNumericBox('filter_port', $filter_port, 5, false, true))->setWidth(ZBX_TEXTAREA_NUMERIC_STANDARD_WIDTH), 'filter_port_row'); $form->addColumn($filterColumn1); $form->addColumn($filterColumn2); $form->addColumn($filterColumn3); $form->addColumn($filterColumn4); // subfilters $table_subfilter = (new CTableInfo())->addRow([new CTag('h4', true, [_('Subfilter'), SPACE, (new CSpan(_('affects only filtered data')))->addClass(ZBX_STYLE_GREY)])]); // array contains subfilters and number of items in each $item_params = ['hosts' => [], 'applications' => [], 'types' => [], 'value_types' => [], 'status' => [], 'state' => [], 'templated_items' => [], 'with_triggers' => [], 'history' => [], 'trends' => [], 'interval' => []]; // generate array with values for subfilters of selected items foreach ($items as $item) { // hosts if (zbx_empty($filter_hostId)) { $host = reset($item['hosts']); if (!isset($item_params['hosts'][$host['hostid']])) { $item_params['hosts'][$host['hostid']] = ['name' => $host['name'], 'count' => 0]; } $show_item = true; foreach ($item['subfilters'] as $name => $value) { if ($name == 'subfilter_hosts') { continue; } $show_item &= $value; } if ($show_item) { $host = reset($item['hosts']); $item_params['hosts'][$host['hostid']]['count']++; } } // applications if (!empty($item['applications'])) { foreach ($item['applications'] as $application) { if (!isset($item_params['applications'][$application['name']])) { $item_params['applications'][$application['name']] = ['name' => $application['name'], 'count' => 0]; } } } $show_item = true; foreach ($item['subfilters'] as $name => $value) { if ($name == 'subfilter_apps') { continue; } $show_item &= $value; } $sel_app = false; if ($show_item) { // if any of item applications are selected foreach ($item['applications'] as $app) { if (str_in_array($app['name'], $subfilter_apps)) { $sel_app = true; break; } } foreach ($item['applications'] as $app) { if (str_in_array($app['name'], $subfilter_apps) || !$sel_app) { $item_params['applications'][$app['name']]['count']++; } } } // types if ($filter_type == -1) { if (!isset($item_params['types'][$item['type']])) { $item_params['types'][$item['type']] = ['name' => item_type2str($item['type']), 'count' => 0]; } $show_item = true; foreach ($item['subfilters'] as $name => $value) { if ($name == 'subfilter_types') { continue; } $show_item &= $value; } if ($show_item) { $item_params['types'][$item['type']]['count']++; } } // value types if ($filter_value_type == -1) { if (!isset($item_params['value_types'][$item['value_type']])) { $item_params['value_types'][$item['value_type']] = ['name' => itemValueTypeString($item['value_type']), 'count' => 0]; } $show_item = true; foreach ($item['subfilters'] as $name => $value) { if ($name == 'subfilter_value_types') { continue; } $show_item &= $value; } if ($show_item) { $item_params['value_types'][$item['value_type']]['count']++; } } // status if ($filter_status == -1) { if (!isset($item_params['status'][$item['status']])) { $item_params['status'][$item['status']] = ['name' => item_status2str($item['status']), 'count' => 0]; } $show_item = true; foreach ($item['subfilters'] as $name => $value) { if ($name == 'subfilter_status') { continue; } $show_item &= $value; } if ($show_item) { $item_params['status'][$item['status']]['count']++; } } // state if ($filter_state == -1) { if (!isset($item_params['state'][$item['state']])) { $item_params['state'][$item['state']] = ['name' => itemState($item['state']), 'count' => 0]; } $show_item = true; foreach ($item['subfilters'] as $name => $value) { if ($name == 'subfilter_state') { continue; } $show_item &= $value; } if ($show_item) { $item_params['state'][$item['state']]['count']++; } } // template if ($filter_templated_items == -1) { if ($item['templateid'] == 0 && !isset($item_params['templated_items'][0])) { $item_params['templated_items'][0] = ['name' => _('Not Templated items'), 'count' => 0]; } elseif ($item['templateid'] > 0 && !isset($item_params['templated_items'][1])) { $item_params['templated_items'][1] = ['name' => _('Templated items'), 'count' => 0]; } $show_item = true; foreach ($item['subfilters'] as $name => $value) { if ($name == 'subfilter_templated_items') { continue; } $show_item &= $value; } if ($show_item) { if ($item['templateid'] == 0) { $item_params['templated_items'][0]['count']++; } else { $item_params['templated_items'][1]['count']++; } } } // with triggers if ($filter_with_triggers == -1) { if (count($item['triggers']) == 0 && !isset($item_params['with_triggers'][0])) { $item_params['with_triggers'][0] = ['name' => _('Without triggers'), 'count' => 0]; } elseif (count($item['triggers']) > 0 && !isset($item_params['with_triggers'][1])) { $item_params['with_triggers'][1] = ['name' => _('With triggers'), 'count' => 0]; } $show_item = true; foreach ($item['subfilters'] as $name => $value) { if ($name == 'subfilter_with_triggers') { continue; } $show_item &= $value; } if ($show_item) { if (count($item['triggers']) == 0) { $item_params['with_triggers'][0]['count']++; } else { $item_params['with_triggers'][1]['count']++; } } } // trends if (zbx_empty($filter_trends)) { if (!isset($item_params['trends'][$item['trends']]) && $item['trends'] !== '') { $item_params['trends'][$item['trends']] = ['name' => $item['trends'], 'count' => 0]; } $show_item = true; foreach ($item['subfilters'] as $name => $value) { if ($name === 'subfilter_trends') { continue; } $show_item &= $value; } if ($show_item && $item['trends'] !== '') { $item_params['trends'][$item['trends']]['count']++; } } // history if (zbx_empty($filter_history)) { if (!isset($item_params['history'][$item['history']])) { $item_params['history'][$item['history']] = ['name' => $item['history'], 'count' => 0]; } $show_item = true; foreach ($item['subfilters'] as $name => $value) { if ($name == 'subfilter_history') { continue; } $show_item &= $value; } if ($show_item) { $item_params['history'][$item['history']]['count']++; } } // interval if (zbx_empty($filter_delay) && $filter_type != ITEM_TYPE_TRAPPER) { if (!isset($item_params['interval'][$item['delay']]) && $item['delay'] !== '') { $item_params['interval'][$item['delay']] = ['name' => $item['delay'], 'count' => 0]; } $show_item = true; foreach ($item['subfilters'] as $name => $value) { if ($name === 'subfilter_interval') { continue; } $show_item &= $value; } if ($show_item && $item['delay'] !== '') { $item_params['interval'][$item['delay']]['count']++; } } } // output if (zbx_empty($filter_hostId) && count($item_params['hosts']) > 1) { $hosts_output = prepareSubfilterOutput(_('Hosts'), $item_params['hosts'], $subfilter_hosts, 'subfilter_hosts'); $table_subfilter->addRow($hosts_output); } if (!empty($item_params['applications']) && count($item_params['applications']) > 1) { $application_output = prepareSubfilterOutput(_('Applications'), $item_params['applications'], $subfilter_apps, 'subfilter_apps'); $table_subfilter->addRow([$application_output]); } if ($filter_type == -1 && count($item_params['types']) > 1) { $type_output = prepareSubfilterOutput(_('Types'), $item_params['types'], $subfilter_types, 'subfilter_types'); $table_subfilter->addRow([$type_output]); } if ($filter_value_type == -1 && count($item_params['value_types']) > 1) { $value_types_output = prepareSubfilterOutput(_('Type of information'), $item_params['value_types'], $subfilter_value_types, 'subfilter_value_types'); $table_subfilter->addRow([$value_types_output]); } if ($filter_status == -1 && count($item_params['status']) > 1) { $status_output = prepareSubfilterOutput(_('Status'), $item_params['status'], $subfilter_status, 'subfilter_status'); $table_subfilter->addRow([$status_output]); } if ($filter_state == -1 && count($item_params['state']) > 1) { $state_output = prepareSubfilterOutput(_('State'), $item_params['state'], $subfilter_state, 'subfilter_state'); $table_subfilter->addRow([$state_output]); } if ($filter_templated_items == -1 && count($item_params['templated_items']) > 1) { $templated_items_output = prepareSubfilterOutput(_('Template'), $item_params['templated_items'], $subfilter_templated_items, 'subfilter_templated_items'); $table_subfilter->addRow([$templated_items_output]); } if ($filter_with_triggers == -1 && count($item_params['with_triggers']) > 1) { $with_triggers_output = prepareSubfilterOutput(_('With triggers'), $item_params['with_triggers'], $subfilter_with_triggers, 'subfilter_with_triggers'); $table_subfilter->addRow([$with_triggers_output]); } if (zbx_empty($filter_history) && count($item_params['history']) > 1) { $history_output = prepareSubfilterOutput(_('History'), $item_params['history'], $subfilter_history, 'subfilter_history'); $table_subfilter->addRow([$history_output]); } if (zbx_empty($filter_trends) && count($item_params['trends']) > 1) { $trends_output = prepareSubfilterOutput(_('Trends'), $item_params['trends'], $subfilter_trends, 'subfilter_trends'); $table_subfilter->addRow([$trends_output]); } if (zbx_empty($filter_delay) && $filter_type != ITEM_TYPE_TRAPPER && count($item_params['interval']) > 1) { $interval_output = prepareSubfilterOutput(_('Interval'), $item_params['interval'], $subfilter_interval, 'subfilter_interval'); $table_subfilter->addRow([$interval_output]); } $form->setFooter($table_subfilter); return $form; }
foreach ($hostPrototype['templates'] as $template) { $caption = []; $caption[] = (new CLink($template['name'], 'templates.php?form=update&templateid=' . $template['templateid']))->addClass(ZBX_STYLE_LINK_ALT)->addClass(ZBX_STYLE_GREY); $linkedTemplates = $this->data['linkedTemplates'][$template['templateid']]['parentTemplates']; if ($linkedTemplates) { order_result($linkedTemplates, 'name'); $caption[] = ' ('; foreach ($linkedTemplates as $tpl) { $caption[] = (new CLink($tpl['name'], 'templates.php?form=update&templateid=' . $tpl['templateid']))->addClass(ZBX_STYLE_LINK_ALT)->addClass(ZBX_STYLE_GREY); $caption[] = ', '; } array_pop($caption); $caption[] = ')'; } $hostTemplates[] = $caption; $hostTemplates[] = ', '; } if ($hostTemplates) { array_pop($hostTemplates); } } // status $status = (new CLink(item_status2str($hostPrototype['status']), '?group_hostid=' . $hostPrototype['hostid'] . '&parent_discoveryid=' . $this->data['discovery_rule']['itemid'] . '&action=' . ($hostPrototype['status'] == HOST_STATUS_NOT_MONITORED ? 'hostprototype.massenable' : 'hostprototype.massdisable')))->addClass(ZBX_STYLE_LINK_ACTION)->addClass(itemIndicatorStyle($hostPrototype['status']))->addSID(); $hostTable->addRow([new CCheckBox('group_hostid[' . $hostPrototype['hostid'] . ']', $hostPrototype['hostid']), $name, $hostTemplates, $status]); } zbx_add_post_js('cookie.prefix = "' . $this->data['discovery_rule']['itemid'] . '";'); // append table to form $itemForm->addItem([$hostTable, $this->data['paging'], new CActionButtonList('action', 'group_hostid', ['hostprototype.massenable' => ['name' => _('Enable'), 'confirm' => _('Enable selected host prototypes?')], 'hostprototype.massdisable' => ['name' => _('Disable'), 'confirm' => _('Disable selected host prototypes?')], 'hostprototype.massdelete' => ['name' => _('Delete'), 'confirm' => _('Delete selected host prototypes?')]], $this->data['discovery_rule']['itemid'])]); // append form to widget $widget->addItem($itemForm); return $widget;
foreach ($linkedTemplates as $tpl) { $caption[] = new CLink($tpl['name'], 'templates.php?form=update&templateid=' . $tpl['templateid'], 'unknown'); $caption[] = ', '; } array_pop($caption); $caption[] = ')'; } $hostTemplates[] = $caption; $hostTemplates[] = ', '; } if ($hostTemplates) { array_pop($hostTemplates); } } // status $status = new CLink(item_status2str($hostPrototype['status']), '?group_hostid=' . $hostPrototype['hostid'] . '&parent_discoveryid=' . $discoveryRule['itemid'] . '&action=' . ($hostPrototype['status'] == HOST_STATUS_NOT_MONITORED ? 'hostprototype.massenable' : 'hostprototype.massdisable'), itemIndicatorStyle($hostPrototype['status'])); $hostTable->addRow(array(new CCheckBox('group_hostid[' . $hostPrototype['hostid'] . ']', null, null, $hostPrototype['hostid']), $name, new CCol($hostTemplates, 'wraptext'), $status)); } // create go buttons $goComboBox = new CComboBox('action'); $goOption = new CComboItem('hostprototype.massenable', _('Enable selected')); $goOption->setAttribute('confirm', _('Enable selected host prototypes?')); $goComboBox->addItem($goOption); $goOption = new CComboItem('hostprototype.massdisable', _('Disable selected')); $goOption->setAttribute('confirm', _('Disable selected host prototypes?')); $goComboBox->addItem($goOption); $goOption = new CComboItem('hostprototype.massdelete', _('Delete selected')); $goOption->setAttribute('confirm', _('Delete selected host prototypes?')); $goComboBox->addItem($goOption); $goButton = new CSubmit('goButton', _('Go') . ' (0)'); $goButton->setAttribute('id', 'goButton');
$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)) {
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; }
//* $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();
} $itemFormList->addRow(_('Populates host inventory field'), $hostInventoryFieldComboBox, false, 'row_inventory_link'); } } // append description to form list $description = new CTextArea('description', $this->data['description']); $description->addStyle('margin-top: 5px;'); $itemFormList->addRow(_('Description'), $description); // status if (isset($this->data['is_item_prototype'])) { $enabledCheckBox = new CCheckBox('status', !$this->data['status'], null, ITEM_STATUS_ACTIVE); $enabledCheckBox->addStyle('vertical-align: middle;'); $itemFormList->addRow(_('Enabled'), $enabledCheckBox); } else { $statusComboBox = new CComboBox('status', $this->data['status']); $statusComboBox->addItems(item_status2str()); $itemFormList->addRow(_('Status'), $statusComboBox); } // append tabs to form $itemTab = new CTabView(); $itemTab->addTab('itemTab', $this->data['caption'], $itemFormList); $itemForm->addItem($itemTab); // append buttons to form $buttons = array(); if (!empty($this->data['itemid'])) { array_push($buttons, new CSubmit('clone', _('Clone'))); if (!$this->data['is_template'] && !empty($this->data['itemid']) && empty($this->data['parent_discoveryid']) && !$this->data['is_discovery_rule']) { array_push($buttons, new CButtonQMessage('del_history', _('Clear history and trends'), _('History clearing can take a long time. Continue?'))); } if (!$this->data['limited']) { if ($this->data['is_discovery_rule']) {