diff options
Diffstat (limited to 'ui')
19 files changed, 137 insertions, 103 deletions
diff --git a/ui/app/controllers/CControllerScriptEdit.php b/ui/app/controllers/CControllerScriptEdit.php index e991cba5a68..7648e6958e3 100644 --- a/ui/app/controllers/CControllerScriptEdit.php +++ b/ui/app/controllers/CControllerScriptEdit.php @@ -156,6 +156,10 @@ class CControllerScriptEdit extends CController { $data['menu_path'] = $script['menu_path']; $data['parameters'] = $script['parameters']; $data['actions'] = $script['actions']; + + if ($data['type'] == ZBX_SCRIPT_TYPE_WEBHOOK) { + CArrayHelper::sort($data['parameters'], ['field' => 'name', 'order' => ZBX_SORT_UP]); + } } } diff --git a/ui/disc_prototypes.php b/ui/disc_prototypes.php index 73c811b5dcc..50a8b46d674 100644 --- a/ui/disc_prototypes.php +++ b/ui/disc_prototypes.php @@ -786,11 +786,6 @@ if (hasRequest('form') || (hasRequest('clone') && getRequest('itemid') != 0)) { $data['trends_mode'] = getRequest('trends_mode', ITEM_STORAGE_CUSTOM); } - // Sort interfaces to be listed starting with one selected as 'main'. - CArrayHelper::sort($data['interfaces'], [ - ['field' => 'main', 'order' => ZBX_SORT_DOWN] - ]); - // render view if (!$has_errors) { echo (new CView('configuration.item.prototype.edit', $data))->getOutput(); diff --git a/ui/host_discovery.php b/ui/host_discovery.php index b9dbef4e1f5..7e1acb19a67 100644 --- a/ui/host_discovery.php +++ b/ui/host_discovery.php @@ -267,6 +267,24 @@ if (getRequest('itemid', false)) { } $_REQUEST['hostid'] = $item['hostid']; $host = reset($item['hosts']); + + foreach ($item['overrides'] as &$override) { + if (!array_key_exists('operations', $override)) { + continue; + } + + foreach ($override['operations'] as &$operation) { + if (array_key_exists('optag', $operation)) { + CArrayHelper::sort($operation['optag'], [ + ['field' => 'tag', 'order' => ZBX_SORT_UP], + ['field' => 'value', 'order' => ZBX_SORT_UP] + ]); + $operation['optag'] = array_values($operation['optag']); + } + } + unset($operation); + } + unset($override); } elseif ($hostid) { $hosts = API::Host()->get([ @@ -845,11 +863,6 @@ if (hasRequest('form')) { $data['form'] = 'clone'; } - // Sort interfaces to be listed starting with one selected as 'main'. - CArrayHelper::sort($data['interfaces'], [ - ['field' => 'main', 'order' => ZBX_SORT_DOWN] - ]); - if ($data['type'] != ITEM_TYPE_JMX) { $data['jmx_endpoint'] = ZBX_DEFAULT_JMX_ENDPOINT; } diff --git a/ui/include/classes/user/CProfile.php b/ui/include/classes/user/CProfile.php index fdab3970793..97816f4ce17 100644 --- a/ui/include/classes/user/CProfile.php +++ b/ui/include/classes/user/CProfile.php @@ -185,6 +185,8 @@ class CProfile { self::$profiles[$idx][$row['idx2']] = $row[$value_type]; } + ksort(self::$profiles[$idx], SORT_NUMERIC); + return array_key_exists($idx2, self::$profiles[$idx]) ? self::$profiles[$idx][$idx2] : $default_value; } diff --git a/ui/include/classes/widgets/forms/CWidgetFormDataOver.php b/ui/include/classes/widgets/forms/CWidgetFormDataOver.php index 76e2362bd7d..7c92c5a3da2 100644 --- a/ui/include/classes/widgets/forms/CWidgetFormDataOver.php +++ b/ui/include/classes/widgets/forms/CWidgetFormDataOver.php @@ -29,6 +29,11 @@ class CWidgetFormDataOver extends CWidgetForm { $this->data = self::convertDottedKeys($this->data); + if (array_key_exists('tags', $this->data) && $this->data['tags']) { + // API doesn't guarantee fields to be retrieved in same order as stored. + ksort($this->data['tags'], SORT_NUMERIC); + } + // Host groups. $field_groups = new CWidgetFieldMsGroup('groupids', _('Host groups')); diff --git a/ui/include/classes/widgets/forms/CWidgetFormProblemHosts.php b/ui/include/classes/widgets/forms/CWidgetFormProblemHosts.php index 30485a31206..90030ec0969 100644 --- a/ui/include/classes/widgets/forms/CWidgetFormProblemHosts.php +++ b/ui/include/classes/widgets/forms/CWidgetFormProblemHosts.php @@ -32,6 +32,11 @@ class CWidgetFormProblemHosts extends CWidgetForm { // Host groups. $field_groups = new CWidgetFieldMsGroup('groupids', _('Host groups')); + if (array_key_exists('tags', $this->data) && $this->data['tags']) { + // API doesn't guarantee fields to be retrieved in same order as stored. + ksort($this->data['tags'], SORT_NUMERIC); + } + if (array_key_exists('groupids', $this->data)) { $field_groups->setValue($this->data['groupids']); } diff --git a/ui/include/classes/widgets/forms/CWidgetFormProblems.php b/ui/include/classes/widgets/forms/CWidgetFormProblems.php index 042901ac762..153e50fc2d2 100644 --- a/ui/include/classes/widgets/forms/CWidgetFormProblems.php +++ b/ui/include/classes/widgets/forms/CWidgetFormProblems.php @@ -29,6 +29,11 @@ class CWidgetFormProblems extends CWidgetForm { $this->data = self::convertDottedKeys($this->data); + if (array_key_exists('tags', $this->data) && $this->data['tags']) { + // API doesn't guarantee fields to be retrieved in same order as stored. + ksort($this->data['tags'], SORT_NUMERIC); + } + // Output information option. $field_show = (new CWidgetFieldRadioButtonList('show', _('Show'), [ TRIGGERS_OPTION_RECENT_PROBLEM => _('Recent problems'), diff --git a/ui/include/classes/widgets/forms/CWidgetFormProblemsBySv.php b/ui/include/classes/widgets/forms/CWidgetFormProblemsBySv.php index a325f96b1dc..db4d1d761f2 100644 --- a/ui/include/classes/widgets/forms/CWidgetFormProblemsBySv.php +++ b/ui/include/classes/widgets/forms/CWidgetFormProblemsBySv.php @@ -32,6 +32,11 @@ class CWidgetFormProblemsBySv extends CWidgetForm { // Host groups. $field_groups = new CWidgetFieldMsGroup('groupids', _('Host groups')); + if (array_key_exists('tags', $this->data) && $this->data['tags']) { + // API doesn't guarantee fields to be retrieved in same order as stored. + ksort($this->data['tags'], SORT_NUMERIC); + } + if (array_key_exists('groupids', $this->data)) { $field_groups->setValue($this->data['groupids']); } diff --git a/ui/include/classes/widgets/forms/CWidgetFormSvgGraph.php b/ui/include/classes/widgets/forms/CWidgetFormSvgGraph.php index d357f9673d8..8c177fc862d 100644 --- a/ui/include/classes/widgets/forms/CWidgetFormSvgGraph.php +++ b/ui/include/classes/widgets/forms/CWidgetFormSvgGraph.php @@ -27,9 +27,9 @@ class CWidgetFormSvgGraph extends CWidgetForm { $this->data = self::convertDottedKeys($this->data); // API doesn't guarantee fields to be retrieved in same order as stored. - foreach (['or', 'ds'] as $field) { + foreach (['or', 'ds', 'tags'] as $field) { if (array_key_exists($field, $this->data)) { - ksort($this->data[$field]); + ksort($this->data[$field], SORT_NUMERIC); } } diff --git a/ui/include/classes/widgets/forms/CWidgetFormTrigOver.php b/ui/include/classes/widgets/forms/CWidgetFormTrigOver.php index 3b4925fab55..7004236070a 100644 --- a/ui/include/classes/widgets/forms/CWidgetFormTrigOver.php +++ b/ui/include/classes/widgets/forms/CWidgetFormTrigOver.php @@ -29,6 +29,11 @@ class CWidgetFormTrigOver extends CWidgetForm { $this->data = self::convertDottedKeys($this->data); + if (array_key_exists('tags', $this->data) && $this->data['tags']) { + // API doesn't guarantee fields to be retrieved in same order as stored. + ksort($this->data['tags'], SORT_NUMERIC); + } + // Output information option. $field_show = (new CWidgetFieldRadioButtonList('show', _('Show'), [ TRIGGERS_OPTION_RECENT_PROBLEM => _('Recent problems'), diff --git a/ui/include/classes/widgets/forms/CWidgetFormWeb.php b/ui/include/classes/widgets/forms/CWidgetFormWeb.php index f31936e3a77..7ae9fcdc66d 100644 --- a/ui/include/classes/widgets/forms/CWidgetFormWeb.php +++ b/ui/include/classes/widgets/forms/CWidgetFormWeb.php @@ -32,6 +32,11 @@ class CWidgetFormWeb extends CWidgetForm { // Host groups. $field_groups = new CWidgetFieldMsGroup('groupids', _('Host groups')); + if (array_key_exists('tags', $this->data) && $this->data['tags']) { + // API doesn't guarantee fields to be retrieved in same order as stored. + ksort($this->data['tags'], SORT_NUMERIC); + } + if (array_key_exists('groupids', $this->data)) { $field_groups->setValue($this->data['groupids']); } diff --git a/ui/include/forms.inc.php b/ui/include/forms.inc.php index f2ae63e4977..e5cc3dddc09 100644 --- a/ui/include/forms.inc.php +++ b/ui/include/forms.inc.php @@ -1033,6 +1033,11 @@ function getItemFormData(array $item = [], array $options = []) { 'hostids' => $data['hostid'], 'output' => API_OUTPUT_EXTEND ]); + // Sort interfaces to be listed starting with one selected as 'main'. + CArrayHelper::sort($data['interfaces'], [ + ['field' => 'main', 'order' => ZBX_SORT_DOWN], + ['field' => 'interfaceid','order' => ZBX_SORT_UP] + ]); if (!$data['is_discovery_rule'] && $data['form'] === 'clone') { if ($data['valuemapid'] != 0) { diff --git a/ui/items.php b/ui/items.php index df31edb882a..e3dceec263e 100644 --- a/ui/items.php +++ b/ui/items.php @@ -1271,11 +1271,6 @@ if (getRequest('form') === 'create' || getRequest('form') === 'update' $data['display_interfaces'] = ($data['host']['status'] == HOST_STATUS_MONITORED || $data['host']['status'] == HOST_STATUS_NOT_MONITORED); - // Sort interfaces to be listed starting with one selected as 'main'. - CArrayHelper::sort($data['interfaces'], [ - ['field' => 'main', 'order' => ZBX_SORT_DOWN] - ]); - if (hasRequest('itemid') && !getRequest('form_refresh')) { $data['inventory_link'] = $item['inventory_link']; } diff --git a/ui/tests/include/web/elements/CCheckboxFormElement.php b/ui/tests/include/web/elements/CCheckboxFormElement.php index 924f71ef023..a74e93afb45 100644 --- a/ui/tests/include/web/elements/CCheckboxFormElement.php +++ b/ui/tests/include/web/elements/CCheckboxFormElement.php @@ -63,7 +63,7 @@ class CCheckboxFormElement extends CFormElement { * * @return */ - private function setFieldValue($field, $values) { + protected function setFieldValue($field, $values) { if ($values === null) { try { $this->getLabelCheckbox($this->getLabel($field))->uncheck(); @@ -89,7 +89,7 @@ class CCheckboxFormElement extends CFormElement { * * @throws Exception */ - private function checkFieldValue($field, $values, $raise_exception = true) { + protected function checkFieldValue($field, $values, $raise_exception = true) { if ($values === null) { try { return $this->getLabelCheckbox($this->getLabel($field))->checkValue(false, $raise_exception); diff --git a/ui/tests/include/web/elements/CFormElement.php b/ui/tests/include/web/elements/CFormElement.php index 3f9a69895b8..7b8dad68199 100644 --- a/ui/tests/include/web/elements/CFormElement.php +++ b/ui/tests/include/web/elements/CFormElement.php @@ -332,7 +332,7 @@ class CFormElement extends CElement { * * @return $this */ - private function setFieldValue($field, $values) { + protected function setFieldValue($field, $values) { $classes = [CMultifieldTableElement::class, CMultiselectElement::class, CCheckboxListElement::class]; $element = $this->getField($field); @@ -416,7 +416,7 @@ class CFormElement extends CElement { * * @throws Exception */ - private function checkFieldValue($field, $values, $raise_exception = true) { + protected function checkFieldValue($field, $values, $raise_exception = true) { $classes = [CMultifieldTableElement::class, CMultiselectElement::class, CCheckboxListElement::class]; $element = $this->getField($field); diff --git a/ui/tests/selenium/dashboard/testDashboardDynamicItemWidgets.php b/ui/tests/selenium/dashboard/testDashboardDynamicItemWidgets.php index 17b118e6cbf..6641b73eec6 100644 --- a/ui/tests/selenium/dashboard/testDashboardDynamicItemWidgets.php +++ b/ui/tests/selenium/dashboard/testDashboardDynamicItemWidgets.php @@ -72,7 +72,7 @@ class testDashboardDynamicItemWidgets extends CWebTest { ['type' => 'Graph prototype', 'header' => 'Dynamic widgets H1: Dynamic widgets GP1 (IP1)'], ['type' => 'Graph prototype', 'header' => 'Dynamic widgets H1: Dynamic widgets GP1 (IP1)'], ['type' => 'Graph prototype', 'header' => 'Dynamic widgets H1: Dynamic widgets GP2 (I1, IP1, H1I2)'], - ['type' => 'Graph prototype', 'header' => 'Dynamic widgets H1: Dynamic widgets H1 GP3 (H1IP1)'] + ['type' => 'Graph prototype', 'header' => 'Dynamic widgets H1: Dynamic widgets H1 GP3 (H1IP1)'], // ['type' => 'Graph prototype', 'header' => 'Dynamic widgets H1: Dynamic widgets H1 GP4 (H1IP1 and H2I1)'] ] ] @@ -126,7 +126,7 @@ class testDashboardDynamicItemWidgets extends CWebTest { ['type' => 'Graph prototype', 'header' => 'Dynamic widgets H1: Dynamic widgets GP1 (IP1)'], ['type' => 'Graph prototype', 'header' => 'Dynamic widgets H1: Dynamic widgets GP1 (IP1)'], ['type' => 'Graph prototype', 'header' => 'Dynamic widgets H1: Dynamic widgets GP2 (I1, IP1, H1I2)'], - ['type' => 'Graph prototype', 'header' => 'Dynamic widgets H1: Dynamic widgets H1 GP3 (H1IP1)'] + ['type' => 'Graph prototype', 'header' => 'Dynamic widgets H1: Dynamic widgets H1 GP3 (H1IP1)'], // ['type' => 'Graph prototype', 'header' => 'Dynamic widgets H1: Dynamic widgets H1 GP4 (H1IP1 and H2I1)'] ] ] diff --git a/ui/tests/selenium/dashboard/testDashboardProblemsBySeverityWidget.php b/ui/tests/selenium/dashboard/testDashboardProblemsBySeverityWidget.php index a184cce5bc1..3f7e4002d27 100644 --- a/ui/tests/selenium/dashboard/testDashboardProblemsBySeverityWidget.php +++ b/ui/tests/selenium/dashboard/testDashboardProblemsBySeverityWidget.php @@ -40,13 +40,12 @@ class testDashboardProblemsBySeverityWidget extends CWebTest { * SQL query to get widget and widget_field tables to compare hash values, but without widget_fieldid * because it can change. */ - // TODO: add wf.name in select and "order by" after fix ZBX-18271 - private $sql = 'SELECT wf.widgetid, wf.type, wf.value_int, wf.value_str, wf.value_groupid, wf.value_hostid,'. + private $sql = 'SELECT wf.widgetid, wf.type, wf.name, wf.value_int, wf.value_str, wf.value_groupid, wf.value_hostid,'. ' wf.value_itemid, wf.value_graphid, wf.value_sysmapid, w.widgetid, w.dashboard_pageid, w.type, w.name, w.x, w.y,'. ' w.width, w.height'. ' FROM widget_field wf'. ' INNER JOIN widget w'. - ' ON w.widgetid=wf.widgetid ORDER BY wf.widgetid, wf.value_int, wf.value_str, wf.value_groupid, wf.value_hostid,'. + ' ON w.widgetid=wf.widgetid ORDER BY wf.widgetid, wf.name, wf.value_int, wf.value_str, wf.value_groupid, wf.value_hostid,'. ' wf.value_itemid, wf.value_graphid'; public function getCreateWidgetData() { diff --git a/ui/tests/selenium/testFormAdministrationScripts.php b/ui/tests/selenium/testFormAdministrationScripts.php index 2e4eeb81fa1..55273a34360 100644 --- a/ui/tests/selenium/testFormAdministrationScripts.php +++ b/ui/tests/selenium/testFormAdministrationScripts.php @@ -63,31 +63,30 @@ class testFormAdministrationScripts extends CWebTest { ] ], // Remove trailing spaces. - // Uncomment this after ZBX-18271 is fixed. -// [ -// [ -// 'trim' => true, -// 'fields' => [ -// 'Name' => 'Test trailing spaces', -// 'Type' => 'Webhook', -// 'Script' => 'Webhook Script' -// ], -// 'Parameters' => [ -// [ -// 'action' => USER_ACTION_UPDATE, -// 'index' => 1, -// 'Name' => 'name', -// 'Value' => ' trimmed value ' -// ], -// [ -// 'action' => USER_ACTION_UPDATE, -// 'index' => 0, -// 'Name' => ' trimmed name ', -// 'Value' => 'value' -// ] -// ] -// ] -// ], + [ + [ + 'trim' => true, + 'fields' => [ + 'Name' => 'Test trailing spaces', + 'Type' => 'Webhook', + 'Script' => 'Webhook Script' + ], + 'Parameters' => [ + [ + 'action' => USER_ACTION_UPDATE, + 'index' => 1, + 'Name' => 'name', + 'Value' => ' trimmed value ' + ], + [ + 'action' => USER_ACTION_UPDATE, + 'index' => 0, + 'Name' => ' trimmed name ', + 'Value' => 'value' + ] + ] + ] + ], [ [ 'fields' => [ @@ -182,46 +181,45 @@ class testFormAdministrationScripts extends CWebTest { ] ] ], - // Uncomment this after ZBX-18271 is fixed. -// [ -// [ -// 'fields' => [ -// 'Name' => 'Test parameters', -// 'Type' => 'Webhook', -// 'Script' => 'Webhook Script', -// 'Timeout' => '1s', -// ], -// 'Parameters' => [ -// [ -// 'action' => USER_ACTION_UPDATE, -// 'index' => 0, -// 'Name' => '!@#$%^&*()_+<>,.\/', -// 'Value' => '!@#$%^&*()_+<>,.\/' -// ], -// [ -// 'action' => USER_ACTION_UPDATE, -// 'index' => 1, -// 'Name' => str_repeat('n', 255), -// 'Value' => str_repeat('v', 2048) -// ], -// [ -// 'Name' => '{$MACRO:A}', -// 'Value' => '{$MACRO:A}' -// ], -// [ -// 'Name' => '{$USERMACRO}', -// 'Value' => '' -// ], -// [ -// 'Name' => '{HOST.HOST}' -// ], -// [ -// 'Name' => 'Имя', -// 'Value' => 'Значение' -// ] -// ] -// ] -// ], + [ + [ + 'fields' => [ + 'Name' => 'Test parameters', + 'Type' => 'Webhook', + 'Script' => 'Webhook Script', + 'Timeout' => '1s', + ], + 'Parameters' => [ + [ + 'action' => USER_ACTION_UPDATE, + 'index' => 0, + 'Name' => '!@#$%^&*()_+<>,.\/', + 'Value' => '!@#$%^&*()_+<>,.\/' + ], + [ + 'action' => USER_ACTION_UPDATE, + 'index' => 1, + 'Name' => str_repeat('n', 255), + 'Value' => str_repeat('v', 2048) + ], + [ + 'Name' => '{$MACRO:A}', + 'Value' => '{$MACRO:A}' + ], + [ + 'Name' => '{$USERMACRO}', + 'Value' => '' + ], + [ + 'Name' => '{HOST.HOST}' + ], + [ + 'Name' => 'Имя', + 'Value' => 'Значение' + ] + ] + ] + ], [ [ 'fields' => [ diff --git a/ui/tests/selenium/testFormLowLevelDiscoveryOverrides.php b/ui/tests/selenium/testFormLowLevelDiscoveryOverrides.php index 223c1491228..f96972342cc 100644 --- a/ui/tests/selenium/testFormLowLevelDiscoveryOverrides.php +++ b/ui/tests/selenium/testFormLowLevelDiscoveryOverrides.php @@ -1468,7 +1468,7 @@ class testFormLowLevelDiscoveryOverrides extends CWebTest { [ 'action' => USER_ACTION_UPDATE, 'index' => 1, - 'Type' => 'Flexible', + 'type' => 'Flexible', 'delay' => '60s', 'period' => '1-5,01:01-13:05' ] @@ -1559,11 +1559,9 @@ class testFormLowLevelDiscoveryOverrides extends CWebTest { * * @backup items */ - // TODO: uncomment after fix ZBX-18271 -/* public function testFormLowLevelDiscoveryOverrides_Update($data) { + public function testFormLowLevelDiscoveryOverrides_Update($data) { $this->overridesUpdate($data); } -*/ private function overridesUpdate($data) { self::$old_hash = CDBHelper::getHash('SELECT * FROM items WHERE flags=1 ORDER BY itemid'); @@ -1598,7 +1596,7 @@ class testFormLowLevelDiscoveryOverrides extends CWebTest { 'operator' => 'exists' ], [ - 'macro' => '{#MACRO2}', + 'macro' => '{#MACRO4}', 'operator' => 'does not exist' ] ] @@ -2039,27 +2037,22 @@ class testFormLowLevelDiscoveryOverrides extends CWebTest { if (array_key_exists('Operations', $override)) { // Write Condititons from data to array. $condition_text = []; - foreach($override['Operations'] as $operation) { + foreach ($override['Operations'] as $operation) { $fields = array_key_exists('fields', $operation) ? $operation['fields'] : $operation; $condition_text[] = $fields['Object'].' '. $fields['Condition']['operator'].' '. $fields['Condition']['value']; } - // TODO: remove sort after fix ZBX-18271 - sort($condition_text); // Compare Conditions from table with data. $actual_conditions = []; for ($n = 0; $n < $operation_count - 1; $n++) { $actual_conditions[] = $operation_container->getRow($n)->getColumn('Condition')->getText(); } - // TODO: remove sort after fix ZBX-18271 - sort($actual_conditions); - $this->assertEquals($condition_text, $actual_conditions); - foreach($override['Operations'] as $i => $operation) { + foreach ($override['Operations'] as $i => $operation) { $operation_container->getRow($i)->query('button:Edit')->one()->click(); $operation_overlay = $this->query('id:lldoperation_form')->waitUntilPresent()->asCheckboxForm()->one(); $operation_overlay->checkValue( |