/** * Validate trigger function like last(0), time(), etc. * Examples: * array('functionName' => 'last', 'functionParamList' => array(0 => '#15'), 'valueType' => 3) * * @param array $value * @param string $value['functionName'] * @param array $value['functionParamList'] * @param int $value['valueType'] * * @return bool */ public function validate($value) { $this->setError(''); if (!isset($this->allowed[$value['functionName']])) { $this->setError(_s('Incorrect trigger function "%1$s" provided in expression.', $value['functionName']) . ' ' . _('Unknown function.')); return false; } if (!isset($this->allowed[$value['functionName']]['value_types'][$value['valueType']])) { $this->setError(_s('Incorrect item value type "%1$s:%2$s" provided for trigger function "%3$s".', '', itemValueTypeString($value['valueType']), $value['functionName'])); return false; } if (count($this->allowed[$value['functionName']]['args']) < count($value['functionParamList'])) { $this->setError(_s('Incorrect trigger function "%1$s" provided in expression.', $value['functionName']) . ' ' . _s('Function supports "%1$s" parameters.', count($this->allowed[$value['functionName']]['args']))); return false; } foreach ($this->allowed[$value['functionName']]['args'] as $aNum => $arg) { // mandatory check if (isset($arg['mandat']) && $arg['mandat'] && !isset($value['functionParamList'][$aNum])) { $this->setError(_s('Incorrect trigger function "%1$s" provided in expression.', $value['functionName']) . ' ' . _('Mandatory parameter is missing.')); return false; } // type check if (isset($arg['type']) && isset($value['functionParamList'][$aNum])) { $userMacro = preg_match('/^' . ZBX_PREG_EXPRESSION_USER_MACROS . '$/', $value['functionParamList'][$aNum]); if (!$userMacro) { switch ($arg['type']) { case 'str': if (!is_string($value['functionParamList'][$aNum])) { $this->setError(_s('Incorrect trigger function "%1$s" provided in expression.', $value['functionName']) . ' ' . _s('Parameter of type string or user macro expected, "%1$s" given.', $value['functionParamList'][$aNum])); return false; } break; case 'sec': if (!$this->validateSec($value['functionParamList'][$aNum])) { $this->setError(_s('Incorrect trigger function "%1$s" provided in expression.', $value['functionName']) . ' ' . _s('Parameter sec or user macro expected, "%1$s" given.', $value['functionParamList'][$aNum])); return false; } break; case 'sec_num': if (!$this->validateSecNum($value['functionParamList'][$aNum])) { $this->setError(_s('Incorrect trigger function "%1$s" provided in expression.', $value['functionName']) . ' ' . _s('Parameter sec or #num or user macro expected, "%1$s" given.', $value['functionParamList'][$aNum])); return false; } break; case 'num': if (!is_numeric($value['functionParamList'][$aNum])) { $this->setError(_s('Incorrect trigger function "%1$s" provided in expression.', $value['functionName']) . ' ' . _s('Parameter num or user macro expected, "%1$s" given.', $value['functionParamList'][$aNum])); return false; } break; } } } } return true; }
/** * Validate trigger function like last(0), time(), etc. * Examples: * array( * 'function' => last("#15"), * 'functionName' => 'last', * 'functionParamList' => array(0 => '#15'), * 'valueType' => 3 * ) * * @param string $value['function'] * @param string $value['functionName'] * @param array $value['functionParamList'] * @param int $value['valueType'] * * @return bool */ public function validate($value) { $this->setError(''); if (!isset($this->allowed[$value['functionName']])) { $this->setError(_s('Incorrect trigger function "%1$s" provided in expression.', $value['function']) . ' ' . _('Unknown function.')); return false; } if (!isset($this->allowed[$value['functionName']]['value_types'][$value['valueType']])) { $this->setError(_s('Incorrect item value type "%1$s" provided for trigger function "%2$s".', itemValueTypeString($value['valueType']), $value['function'])); return false; } if (count($this->allowed[$value['functionName']]['args']) < count($value['functionParamList'])) { $this->setError(_s('Incorrect trigger function "%1$s" provided in expression.', $value['function']) . ' ' . _('Invalid number of parameters.')); return false; } $paramLabels = [_('Invalid first parameter.'), _('Invalid second parameter.'), _('Invalid third parameter.'), _('Invalid fourth parameter.')]; $user_macro_parser = new CUserMacroParser(); foreach ($this->allowed[$value['functionName']]['args'] as $aNum => $arg) { // mandatory check if (isset($arg['mandat']) && $arg['mandat'] && !isset($value['functionParamList'][$aNum])) { $this->setError(_s('Incorrect trigger function "%1$s" provided in expression.', $value['function']) . ' ' . _('Mandatory parameter is missing.')); return false; } if (!isset($value['functionParamList'][$aNum])) { continue; } if (isset($arg['can_be_empty']) && $value['functionParamList'][$aNum] == '') { continue; } // user macro if ($user_macro_parser->parse($value['functionParamList'][$aNum]) == CParser::PARSE_SUCCESS) { continue; } if (!$this->validateParameter($value['functionParamList'][$aNum], $arg['type'])) { $this->setError(_s('Incorrect trigger function "%1$s" provided in expression.', $value['function']) . ' ' . $paramLabels[$aNum]); return false; } } return true; }
/** * Validate trigger function like last(0), time(), etc. * Examples: * array( * 'function' => last("#15"), * 'functionName' => 'last', * 'functionParamList' => array(0 => '#15'), * 'valueType' => 3 * ) * * @param string $value['function'] * @param string $value['functionName'] * @param array $value['functionParamList'] * @param int $value['valueType'] * * @return bool */ public function validate($value) { $this->setError(''); if (!isset($this->allowed[$value['functionName']])) { $this->setError(_s('Incorrect trigger function "%1$s" provided in expression.', $value['function']) . ' ' . _('Unknown function.')); return false; } if (!isset($this->allowed[$value['functionName']]['value_types'][$value['valueType']])) { $this->setError(_s('Incorrect item value type "%1$s" provided for trigger function "%2$s".', itemValueTypeString($value['valueType']), $value['function'])); return false; } if (count($this->allowed[$value['functionName']]['args']) < count($value['functionParamList'])) { $this->setError(_s('Incorrect trigger function "%1$s" provided in expression.', $value['function']) . ' ' . _('Invalid number of parameters.')); return false; } $paramLabels = array(_('Invalid first parameter.'), _('Invalid second parameter.'), _('Invalid third parameter.'), _('Invalid fourth parameter.')); foreach ($this->allowed[$value['functionName']]['args'] as $aNum => $arg) { // mandatory check if (isset($arg['mandat']) && $arg['mandat'] && !isset($value['functionParamList'][$aNum])) { $this->setError(_s('Incorrect trigger function "%1$s" provided in expression.', $value['function']) . ' ' . _('Mandatory parameter is missing.')); return false; } if (!isset($value['functionParamList'][$aNum])) { continue; } if (isset($arg['can_be_empty']) && $value['functionParamList'][$aNum] == '') { continue; } // user macro if (preg_match('/^' . ZBX_PREG_EXPRESSION_USER_MACROS . '$/', $value['functionParamList'][$aNum])) { continue; } if (!$this->validateParameter($value['functionParamList'][$aNum], $arg['type'])) { $this->setError(_s('Incorrect trigger function "%1$s" provided in expression.', $value['function']) . ' ' . $paramLabels[$aNum]); return false; } } return true; }
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; }
$authTypeComboBox = new CComboBox('authtype', $this->data['authtype']); $authTypeComboBox->addItem(ITEM_AUTHTYPE_PASSWORD, _('Password')); $authTypeComboBox->addItem(ITEM_AUTHTYPE_PUBLICKEY, _('Public key')); $itemFormList->addRow(_('Authentication method'), $authTypeComboBox, false, 'row_authtype'); $itemFormList->addRow(_('User name'), new CTextBox('username', $this->data['username'], ZBX_TEXTBOX_SMALL_SIZE, 'no', 64), false, 'row_username'); $itemFormList->addRow(_('Public key file'), new CTextBox('publickey', $this->data['publickey'], ZBX_TEXTBOX_SMALL_SIZE, 'no', 64), false, 'row_publickey'); $itemFormList->addRow(_('Private key file'), new CTextBox('privatekey', $this->data['privatekey'], ZBX_TEXTBOX_SMALL_SIZE, 'no', 64), false, 'row_privatekey'); $itemFormList->addRow(_('Password'), new CTextBox('password', $this->data['password'], ZBX_TEXTBOX_SMALL_SIZE, 'no', 64), false, 'row_password'); $itemFormList->addRow(_('Executed script'), new CTextArea('params_es', $this->data['params'], array('rows' => ZBX_TEXTAREA_STANDARD_ROWS, 'width' => ZBX_TEXTAREA_STANDARD_WIDTH)), false, 'label_executed_script'); $itemFormList->addRow(_('SQL query'), new CTextArea('params_ap', $this->data['params'], array('rows' => ZBX_TEXTAREA_STANDARD_ROWS, 'width' => ZBX_TEXTAREA_STANDARD_WIDTH)), false, 'label_params'); $itemFormList->addRow(_('Formula'), new CTextArea('params_f', $this->data['params'], array('rows' => ZBX_TEXTAREA_STANDARD_ROWS, 'width' => ZBX_TEXTAREA_STANDARD_WIDTH)), false, 'label_formula'); // append value type to form list if (!$this->data['is_discovery_rule']) { if ($this->data['limited']) { $itemForm->addVar('value_type', $this->data['value_type']); $itemFormList->addRow(_('Type of information'), new CTextBox('value_type_name', itemValueTypeString($this->data['value_type']), ZBX_TEXTBOX_STANDARD_SIZE, 'yes')); } else { $valueTypeComboBox = new CComboBox('value_type', $this->data['value_type']); $valueTypeComboBox->addItem(ITEM_VALUE_TYPE_UINT64, _('Numeric (unsigned)')); $valueTypeComboBox->addItem(ITEM_VALUE_TYPE_FLOAT, _('Numeric (float)')); $valueTypeComboBox->addItem(ITEM_VALUE_TYPE_STR, _('Character')); $valueTypeComboBox->addItem(ITEM_VALUE_TYPE_LOG, _('Log')); $valueTypeComboBox->addItem(ITEM_VALUE_TYPE_TEXT, _('Text')); $itemFormList->addRow(_('Type of information'), $valueTypeComboBox); } // append data type to form list if ($this->data['limited']) { $itemForm->addVar('data_type', $this->data['data_type']); $dataType = new CTextBox('data_type_name', item_data_type2str($this->data['data_type']), ZBX_TEXTBOX_SMALL_SIZE, 'yes'); } else { $dataType = new CComboBox('data_type', $this->data['data_type']);
$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.'));
$itemFormList->addRow(_('Port'), (new CTextBox('port', $this->data['port'], false, 64))->setWidth(ZBX_TEXTAREA_SMALL_WIDTH), 'row_port'); $itemFormList->addRow(_('IPMI sensor'), (new CTextBox('ipmi_sensor', $this->data['ipmi_sensor'], $this->data['limited'], 128))->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH), 'row_ipmi_sensor'); // append authentication method to form list $authTypeComboBox = new CComboBox('authtype', $this->data['authtype'], null, [ITEM_AUTHTYPE_PASSWORD => _('Password'), ITEM_AUTHTYPE_PUBLICKEY => _('Public key')]); $itemFormList->addRow(_('Authentication method'), $authTypeComboBox, 'row_authtype'); $itemFormList->addRow(_('User name'), (new CTextBox('username', $this->data['username'], false, 64))->setWidth(ZBX_TEXTAREA_SMALL_WIDTH), 'row_username'); $itemFormList->addRow(_('Public key file'), (new CTextBox('publickey', $this->data['publickey'], false, 64))->setWidth(ZBX_TEXTAREA_SMALL_WIDTH), 'row_publickey'); $itemFormList->addRow(_('Private key file'), (new CTextBox('privatekey', $this->data['privatekey'], false, 64))->setWidth(ZBX_TEXTAREA_SMALL_WIDTH), 'row_privatekey'); $itemFormList->addRow(_('Password'), (new CTextBox('password', $this->data['password'], false, 64))->setWidth(ZBX_TEXTAREA_SMALL_WIDTH), 'row_password'); $itemFormList->addRow(_('Executed script'), (new CTextArea('params_es', $this->data['params']))->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH), 'label_executed_script'); $itemFormList->addRow(_('SQL query'), (new CTextArea('params_ap', $this->data['params']))->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH), 'label_params'); $itemFormList->addRow(_('Formula'), (new CTextArea('params_f', $this->data['params']))->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH), 'label_formula'); // append value type to form list if ($this->data['limited']) { $itemForm->addVar('value_type', $this->data['value_type']); $itemFormList->addRow(_('Type of information'), (new CTextBox('value_type_name', itemValueTypeString($this->data['value_type']), true))->setWidth(ZBX_TEXTAREA_SMALL_WIDTH)); } else { $itemFormList->addRow(_('Type of information'), new CComboBox('value_type', $this->data['value_type'], null, [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')])); } // append data type to form list if ($this->data['limited']) { $itemForm->addVar('data_type', $this->data['data_type']); $dataType = (new CTextBox('data_type_name', item_data_type2str($this->data['data_type']), true))->setWidth(ZBX_TEXTAREA_SMALL_WIDTH); } else { $dataType = new CComboBox('data_type', $this->data['data_type'], null, item_data_type2str()); } $itemFormList->addRow(_('Data type'), $dataType, 'row_data_type'); $itemFormList->addRow(_('Units'), (new CTextBox('units', $this->data['units'], $this->data['limited']))->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH), 'row_units'); // append multiplier to form list if ($this->data['limited']) { $itemForm->addVar('multiplier', $this->data['multiplier']);
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 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; }