Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/zabbix/zabbix.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/ui
diff options
context:
space:
mode:
authorMiks Kronkalns <miks.kronkalns@zabbix.com>2020-12-11 20:14:58 +0300
committerMiks Kronkalns <miks.kronkalns@zabbix.com>2020-12-11 20:17:13 +0300
commita458914ffa5da03ec68da96d2196ace3cb9035d2 (patch)
tree8ba1e831372a2c23e5b409dd67251059ca4800f0 /ui
parentcdc8c9ec1169f845025e1ee0f5907c4972fc7a75 (diff)
..F....... [ZBX-18086] fixed missing data selection in data overview and trigger overview screens
* commit '7c41c9178d1cf1936f040b42e34e88b4bbba4461': ..F....... [ZBX-18086] fixed applying of limits for data overview ..F....... [ZBX-18086] simlified code ..F....... [ZBX-18086] improved performance ..F....... [ZBX-18086] simplified code; removed dead code ..F....... [ZBX-18086] fixed coding style ..F....... [ZBX-18086] fixed item grouping in data overview widget ..F....... [ZBX-18086] fixed selection of triggers to display in triggers overview ..F....... [ZBX-18086] fixed undefined offset error ..F....... [ZBX-18086] fixed unneeded references for function arguments ..F....... [ZBX-18086] fixed trigger grouping ..F....... [ZBX-18086] fixed item naming in data overview report header ..F....... [ZBX-18086] fixed nested API request .D........ [ZBX-18086] fixed changelog ..F....... [ZBX-18086] fixed trigger overview data selection ..F....... [ZBX-18086] fixed undefined index error in data overview screen item ..F....... [ZBX-18086] fixed items to be grouped by name instead of key in data overview screen ..F....... [ZBX-18086] fixed warning mesage not be displayed in data overview report ..F....... [ZBX-18086] fixed hostid selection in getDataOverviewItems function ..F....... [ZBX-18086] fixed missing data selection in data overview screen (cherry picked from commit 9e4febe1a3c1b63bdcc5ae9671dde0571f0a61a6)
Diffstat (limited to 'ui')
-rw-r--r--ui/app/controllers/CControllerWidgetDataOverView.php18
-rw-r--r--ui/app/controllers/CControllerWidgetTrigOverView.php6
-rw-r--r--ui/app/partials/dataoverview.table.left.php34
-rw-r--r--ui/app/partials/dataoverview.table.top.php28
-rw-r--r--ui/app/partials/trigoverview.table.left.php2
-rw-r--r--ui/app/partials/trigoverview.table.top.php2
-rw-r--r--ui/include/classes/screens/CScreenDataOverview.php38
-rw-r--r--ui/include/classes/screens/CScreenTriggersOverview.php6
-rw-r--r--ui/include/items.inc.php280
-rw-r--r--ui/include/triggers.inc.php161
-rw-r--r--ui/include/views/monitoring.overview.items.php22
-rw-r--r--ui/overview.php27
12 files changed, 266 insertions, 358 deletions
diff --git a/ui/app/controllers/CControllerWidgetDataOverView.php b/ui/app/controllers/CControllerWidgetDataOverView.php
index 7407fa87175..33463e25e08 100644
--- a/ui/app/controllers/CControllerWidgetDataOverView.php
+++ b/ui/app/controllers/CControllerWidgetDataOverView.php
@@ -37,18 +37,7 @@ class CControllerWidgetDataOverView extends CControllerWidget {
$groupids = $fields['groupids'] ? getSubGroups($fields['groupids']) : null;
$hostids = $fields['hostids'] ? $fields['hostids'] : null;
- if ($fields['style'] == STYLE_TOP) {
- list($db_items, $db_hosts, $items_by_name, $has_hidden_data) = getDataOverviewTop($groupids, $hostids,
- $fields['application']
- );
- }
- else {
- list($db_items, $db_hosts, $items_by_name, $has_hidden_data) = getDataOverviewLeft($groupids, $hostids,
- $fields['application']
- );
- }
-
- $visible_items = getDataOverviewCellData($db_hosts, $db_items, $items_by_name, $fields['show_suppressed']);
+ [$items, $hosts, $has_hidden_data] = getDataOverview($groupids, $hostids, $fields);
$this->setResponse(new CControllerResponseData([
'name' => $this->getInput('name', $this->getDefaultHeader()),
@@ -56,9 +45,8 @@ class CControllerWidgetDataOverView extends CControllerWidget {
'application' => $fields['application'],
'show_suppressed' => $fields['show_suppressed'],
'style' => $fields['style'],
- 'visible_items' => $visible_items,
- 'db_hosts' => $db_hosts,
- 'items_by_name' => $items_by_name,
+ 'items' => $items,
+ 'hosts' => $hosts,
'has_hidden_data' => $has_hidden_data,
'user' => [
'debug_mode' => $this->getDebugMode()
diff --git a/ui/app/controllers/CControllerWidgetTrigOverView.php b/ui/app/controllers/CControllerWidgetTrigOverView.php
index 339134866a7..c6e5877dd4e 100644
--- a/ui/app/controllers/CControllerWidgetTrigOverView.php
+++ b/ui/app/controllers/CControllerWidgetTrigOverView.php
@@ -61,9 +61,9 @@ class CControllerWidgetTrigOverView extends CControllerWidget {
'hostids' => $fields['hostids'] ? $fields['hostids'] : null
];
- list($data['db_hosts'], $data['db_triggers'], $data['dependencies'], $data['triggers_by_name'],
- $data['hosts_by_name'], $data['exceeded_hosts'], $data['exceeded_trigs']
- ) = getTriggersOverviewData(getSubGroups($fields['groupids']), $fields['application'], $host_options,
+ [$data['db_hosts'], $data['db_triggers'], $data['dependencies'], $data['triggers_by_name'],
+ $data['hosts_by_name'], $data['exceeded_limit']
+ ] = getTriggersOverviewData(getSubGroups($fields['groupids']), $fields['application'], $host_options,
$trigger_options, $problem_options
);
diff --git a/ui/app/partials/dataoverview.table.left.php b/ui/app/partials/dataoverview.table.left.php
index 2f368154ed1..b8a900cc8e2 100644
--- a/ui/app/partials/dataoverview.table.left.php
+++ b/ui/app/partials/dataoverview.table.left.php
@@ -26,27 +26,29 @@ $table = (new CTableInfo())
->makeVerticalRotation()
->setHeadingColumn(0);
-$headings[] = _('Hosts');
-foreach ($data['items_by_name'] as $name => $hostid_to_itemid) {
- $headings[] = (new CColHeader($name))
- ->addClass('vertical_rotation')
- ->setTitle($name);
+$header = [_('Hosts')];
+foreach ($data['items'] as $item_name => $item_data) {
+ foreach ($item_data as $columns_data) {
+ $header[] = (new CColHeader($item_name))
+ ->addClass('vertical_rotation')
+ ->setTitle($item_name);
+ }
}
+$table->setHeader($header);
-$table->setHeader($headings);
-
-foreach ($data['db_hosts'] as $hostid => $host) {
+foreach ($data['hosts'] as $hostid => $host) {
$name = (new CLinkAction($host['name']))->setMenuPopup(CMenuPopupHelper::getHost($hostid));
$row = [(new CColHeader($name))->addClass(ZBX_STYLE_NOWRAP)];
- foreach ($data['items_by_name'] as $hostid_to_itemid) {
- if (!array_key_exists($host['hostid'], $hostid_to_itemid)) {
- $row[] = new CCol();
- }
- else {
- $itemid = $hostid_to_itemid[$host['hostid']];
- $item = $data['visible_items'][$itemid];
- $row[] = getItemDataOverviewCell($item, $item['trigger']);
+ foreach ($data['items'] as $item_name => $columns_data) {
+ foreach ($columns_data as $column_data) {
+ if (array_key_exists($host['name'], $column_data)) {
+ $item = $column_data[$host['name']];
+ $row[] = getItemDataOverviewCell($item, $item['trigger']);
+ }
+ else {
+ $row[] = new CCol();
+ }
}
}
diff --git a/ui/app/partials/dataoverview.table.top.php b/ui/app/partials/dataoverview.table.top.php
index 38a82ef15ef..d4bb0639253 100644
--- a/ui/app/partials/dataoverview.table.top.php
+++ b/ui/app/partials/dataoverview.table.top.php
@@ -27,7 +27,7 @@ $table = (new CTableInfo())
->setHeadingColumn(0);
$headings[] = _('Items');
-foreach ($data['db_hosts'] as $host) {
+foreach ($data['hosts'] as $host) {
$headings[] = (new CColHeader($host['name']))
->addClass('vertical_rotation')
->setTitle($host['name']);
@@ -35,21 +35,21 @@ foreach ($data['db_hosts'] as $host) {
$table->setHeader($headings);
-foreach ($data['items_by_name'] as $name => $hostid_to_itemid) {
- $row = [(new CColHeader($name))->addClass(ZBX_STYLE_NOWRAP)];
-
- foreach ($data['db_hosts'] as $hostid => $host) {
- if (!array_key_exists($host['hostid'], $hostid_to_itemid)) {
- $row[] = new CCol();
- }
- else {
- $itemid = $hostid_to_itemid[$host['hostid']];
- $item = $data['visible_items'][$itemid];
- $row[] = getItemDataOverviewCell($item, $item['trigger']);
+foreach ($data['items'] as $item_name => $item_data) {
+ foreach ($item_data as $items) {
+ $row = [(new CColHeader($item_name))->addClass(ZBX_STYLE_NOWRAP)];
+ foreach ($data['hosts'] as $host) {
+ if (array_key_exists($host['name'], $items)) {
+ $item = $items[$host['name']];
+ $row[] = getItemDataOverviewCell($item, $item['trigger']);
+ }
+ else {
+ $row[] = new CCol();
+ }
}
- }
- $table->addRow($row);
+ $table->addRow($row);
+ }
}
if ($data['has_hidden_data']) {
diff --git a/ui/app/partials/trigoverview.table.left.php b/ui/app/partials/trigoverview.table.left.php
index 66f13c76095..c21166b2954 100644
--- a/ui/app/partials/trigoverview.table.left.php
+++ b/ui/app/partials/trigoverview.table.left.php
@@ -57,7 +57,7 @@ foreach ($data['hosts_by_name'] as $hostname => $hostid) {
$table->addRow($row);
}
-if ($data['exceeded_hosts'] || $data['exceeded_trigs']) {
+if ($data['exceeded_limit']) {
$table->setFooter([
(new CCol(_('Not all results are displayed. Please provide more specific search criteria.')))
->setColSpan($table->getNumCols())
diff --git a/ui/app/partials/trigoverview.table.top.php b/ui/app/partials/trigoverview.table.top.php
index ea73cce647a..2770baac3cb 100644
--- a/ui/app/partials/trigoverview.table.top.php
+++ b/ui/app/partials/trigoverview.table.top.php
@@ -56,7 +56,7 @@ foreach ($data['triggers_by_name'] as $trigname => $host_to_trig) {
$table->addRow($row);
}
-if ($data['exceeded_hosts'] || $data['exceeded_trigs']) {
+if ($data['exceeded_limit']) {
$table->setFooter([
(new CCol(_('Not all results are displayed. Please provide more specific search criteria.')))
->setColSpan($table->getNumCols())
diff --git a/ui/include/classes/screens/CScreenDataOverview.php b/ui/include/classes/screens/CScreenDataOverview.php
index 9e8b6ea3594..6fcb82e72e7 100644
--- a/ui/include/classes/screens/CScreenDataOverview.php
+++ b/ui/include/classes/screens/CScreenDataOverview.php
@@ -40,35 +40,15 @@ class CScreenDataOverview extends CScreenBase {
->addItem([_('Group'), ':', SPACE, $groups[0]['name']])
]))->addClass(ZBX_STYLE_DASHBRD_WIDGET_HEAD);
- $data = [];
- if ($this->screenitem['style'] == STYLE_TOP) {
- list($db_items, $db_hosts, $items_by_name, $has_hidden_data) = getDataOverviewTop((array) $groupid, null,
- $this->screenitem['application']
- );
-
- $data['visible_items'] = getDataOverviewCellData($db_hosts, $db_items, $items_by_name,
- ZBX_PROBLEM_SUPPRESSED_FALSE
- );
- $data['db_hosts'] = $db_hosts;
- $data['items_by_name'] = $items_by_name;
- $data['has_hidden_data'] = $has_hidden_data;
-
- $table = new CPartial('dataoverview.table.top', $data);
- }
- else {
- list($db_items, $db_hosts, $items_by_name, $has_hidden_data) = getDataOverviewLeft((array) $groupid, null,
- $this->screenitem['application']
- );
-
- $data['visible_items'] = getDataOverviewCellData($db_hosts, $db_items, $items_by_name,
- ZBX_PROBLEM_SUPPRESSED_FALSE
- );
- $data['db_hosts'] = $db_hosts;
- $data['items_by_name'] = $items_by_name;
- $data['has_hidden_data'] = $has_hidden_data;
-
- $table = new CPartial('dataoverview.table.left', $data);
- }
+ $data = array_combine(['items', 'hosts', 'has_hidden_data'],
+ getDataOverview((array) $groupid, null, [
+ 'application' => $this->screenitem['application'],
+ 'show_suppressed' => ZBX_PROBLEM_SUPPRESSED_FALSE
+ ])
+ );
+
+ $partial = ($this->screenitem['style'] == STYLE_TOP) ? 'dataoverview.table.top' : 'dataoverview.table.left';
+ $table = new CPartial($partial, $data);
$footer = (new CList())
->addItem(_s('Updated: %1$s', zbx_date2str(TIME_FORMAT_SECONDS)))
diff --git a/ui/include/classes/screens/CScreenTriggersOverview.php b/ui/include/classes/screens/CScreenTriggersOverview.php
index 8a438f0f590..b4fdf419279 100644
--- a/ui/include/classes/screens/CScreenTriggersOverview.php
+++ b/ui/include/classes/screens/CScreenTriggersOverview.php
@@ -38,9 +38,9 @@ class CScreenTriggersOverview extends CScreenBase {
]))->addClass(ZBX_STYLE_DASHBRD_WIDGET_HEAD);
$data = [];
- list($data['db_hosts'], $data['db_triggers'], $data['dependencies'], $data['triggers_by_name'],
- $data['hosts_by_name'], $data['exceeded_hosts'], $data['exceeded_trigs']
- ) = getTriggersOverviewData((array) $this->screenitem['resourceid'], $this->screenitem['application']);
+ [$data['db_hosts'], $data['db_triggers'], $data['dependencies'], $data['triggers_by_name'],
+ $data['hosts_by_name'], $data['exceeded_limit']
+ ] = getTriggersOverviewData((array) $this->screenitem['resourceid'], $this->screenitem['application']);
if ($this->screenitem['style'] == STYLE_TOP) {
$table = new CPartial('trigoverview.table.top', $data);
diff --git a/ui/include/items.inc.php b/ui/include/items.inc.php
index 61fc193cfcd..13176484db6 100644
--- a/ui/include/items.inc.php
+++ b/ui/include/items.inc.php
@@ -1001,32 +1001,27 @@ function makeItemTemplatesHtml($itemid, array $parent_templates, $flag, bool $pr
}
/**
- * @param array $db_hosts
+ * Collect latest value and actual severity value for each item of Data overview table.
+ *
* @param array $db_items
- * @param array $items_by_name
+ * @param array $data
* @param int $show_suppressed
*
* @return array
*/
-function getDataOverviewCellData(array &$db_hosts, array &$db_items, array &$items_by_name, int $show_suppressed): array {
- $visible_items = [];
- foreach ($items_by_name as $hostid_to_itemids) {
- foreach ($hostid_to_itemids as $itemid) {
- $visible_items[$itemid] = $db_items[$itemid];
- }
- }
-
- $history = Manager::History()->getLastValues($visible_items, 1,
+function getDataOverviewCellData(array $db_items, array $data, int $show_suppressed): array {
+ $history = Manager::History()->getLastValues($db_items, 1,
timeUnitToSeconds(CSettingsHelper::get(CSettingsHelper::HISTORY_PERIOD))
);
$db_triggers = getTriggersWithActualSeverity([
'output' => ['triggerid', 'priority', 'value'],
'selectItems' => ['itemid'],
- 'itemids' => array_keys($visible_items),
+ 'itemids' => array_keys($db_items),
'monitored' => true,
'preservekeys' => true
], ['show_suppressed' => $show_suppressed]);
+
$itemid_to_triggerids = [];
foreach ($db_triggers as $triggerid => $db_trigger) {
foreach ($db_trigger['items'] as $item) {
@@ -1037,38 +1032,41 @@ function getDataOverviewCellData(array &$db_hosts, array &$db_items, array &$ite
}
}
- foreach ($items_by_name as $hostid_to_itemids) {
- foreach ($db_hosts as $host) {
- if (!array_key_exists($host['hostid'], $hostid_to_itemids)) {
- continue;
- }
+ // Apply values and trigger severity to each $data cell.
+ foreach ($data as &$data_clusters) {
+ foreach ($data_clusters as &$data_cluster) {
+ foreach ($data_cluster as &$item) {
+ $itemid = $item['itemid'];
+
+ if (array_key_exists($itemid, $itemid_to_triggerids)) {
+ $max_priority = -1;
+ $max_priority_triggerid = -1;
+ foreach ($itemid_to_triggerids[$itemid] as $triggerid) {
+ $trigger = $db_triggers[$triggerid];
- $itemid = $hostid_to_itemids[$host['hostid']];
- $visible_items[$itemid]['value'] = array_key_exists($itemid, $history)
- ? $history[$itemid][0]['value']
- : null;
- $trigger = null;
-
- if (array_key_exists($itemid, $itemid_to_triggerids)) {
- $max_priority = -1;
- $max_priority_triggerid = -1;
- foreach ($itemid_to_triggerids[$itemid] as $triggerid) {
- $trigger = $db_triggers[$triggerid];
-
- // Bump lower priority triggers of value "true" ahead of triggers with value "false".
- $multiplier = ($trigger['value'] == TRIGGER_VALUE_TRUE) ? TRIGGER_SEVERITY_COUNT : 0;
- if ($trigger['priority'] + $multiplier > $max_priority) {
- $max_priority_triggerid = $triggerid;
- $max_priority = $trigger['priority'] + $multiplier;
+ // Bump lower priority triggers of value "true" ahead of triggers with value "false".
+ $multiplier = ($trigger['value'] == TRIGGER_VALUE_TRUE) ? TRIGGER_SEVERITY_COUNT : 0;
+ if ($trigger['priority'] + $multiplier > $max_priority) {
+ $max_priority_triggerid = $triggerid;
+ $max_priority = $trigger['priority'] + $multiplier;
+ }
}
+ $trigger = $db_triggers[$max_priority_triggerid];
}
- $trigger = $db_triggers[$max_priority_triggerid];
+ else {
+ $trigger = null;
+ }
+
+ $item += [
+ 'value' => array_key_exists($itemid, $history) ? $history[$itemid][0]['value'] : null,
+ 'trigger' => $trigger
+ ];
}
- $visible_items[$itemid]['trigger'] = $trigger;
}
}
+ unset($data_clusters, $data_cluster, $item);
- return $visible_items;
+ return $data;
}
/**
@@ -1079,33 +1077,54 @@ function getDataOverviewCellData(array &$db_hosts, array &$db_items, array &$ite
* @return array
*/
function getDataOverviewItems(?array $groupids = null, ?array $hostids = null, ?string $application = ''): array {
- $limit = CSettingsHelper::get(CSettingsHelper::SEARCH_LIMIT);
if ($application !== '') {
- $applicationids = array_keys(API::Application()->get([
- 'output' => [],
+ $db_applications = API::Application()->get([
+ 'output' => ['hostid'],
'hostids' => $hostids,
'groupids' => $groupids,
'search' => ['name' => $application],
'preservekeys' => true
- ]));
+ ]);
+
+ $applicationids = array_keys($db_applications);
+ $hostids = array_keys(array_flip(array_column($db_applications, 'hostid')));
+ }
+ else {
+ $applicationids = null;
+ }
+ if ($hostids === null) {
+ $limit = (int) CSettingsHelper::get(CSettingsHelper::MAX_OVERVIEW_TABLE_SIZE) + 1;
+ $db_hosts = API::Host()->get([
+ 'output' => [],
+ 'groupids' => $groupids,
+ 'applicationids' => $applicationids,
+ 'monitored_hosts' => true,
+ 'with_monitored_items' => true,
+ 'preservekeys' => true,
+ 'limit' => $limit
+ ]);
+ $hostids = array_keys($db_hosts);
+ }
+
+ if ($application !== '') {
$db_items = API::Item()->get([
'output' => ['itemid', 'hostid', 'name', 'key_', 'value_type', 'units', 'valuemapid'],
+ 'selectHosts' => ['name'],
'applicationids' => $applicationids,
'monitored' => true,
'webitems' => true,
- 'limit' => $limit,
'preservekeys' => true
]);
}
else {
$db_items = API::Item()->get([
'output' => ['itemid', 'hostid', 'name', 'key_', 'value_type', 'units', 'valuemapid'],
+ 'selectHosts' => ['name'],
'hostids' => $hostids,
'groupids' => $groupids,
'monitored' => true,
'webitems' => true,
- 'limit' => $limit,
'preservekeys' => true
]);
}
@@ -1117,128 +1136,101 @@ function getDataOverviewItems(?array $groupids = null, ?array $hostids = null, ?
['field' => 'itemid', 'order' => ZBX_SORT_UP]
]);
- return $db_items;
+ return [$db_items, $hostids];
}
/**
- * @param array $groupids
- * @param array $hostids
- * @param array $itemids
- * @param string $application
+ * @param array $groupids
+ * @param array $hostids
+ * @param array $filter
+ * @param string $filter['application']
+ * @param int $filter['show_suppressed']
*
* @return array
*/
-function getDataOverviewHosts(?array $groupids, ?array $hostids, ?array $itemids, ?string $application = ''): array {
- $limit = CSettingsHelper::get(CSettingsHelper::SEARCH_LIMIT);
- if ($application !== '') {
- $applicationids = array_keys(API::Application()->get([
- 'output' => [],
- 'hostids' => $hostids ? $hostids : null,
- 'groupids' => $groupids ? $groupids : null,
- 'search' => ['name' => $application],
- 'preservekeys' => true
- ]));
+function getDataOverview(?array $groupids, ?array $hostids, array $filter): array {
+ [$db_items, $hostids] = getDataOverviewItems($groupids, $hostids, $filter['application']);
- $db_hosts = API::Host()->get([
- 'output' => ['name', 'hostid'],
- 'groupids' => $groupids,
- 'applicationids' => $applicationids,
- 'monitored_hosts' => true,
- 'with_monitored_items' => true,
- 'preservekeys' => true,
- 'limit' => $limit
- ]);
- }
- else {
- $db_hosts = API::Host()->get([
- 'output' => ['name', 'hostid'],
- 'monitored_hosts' => true,
- 'hostids' => $hostids,
- 'itemids' => $itemids,
- 'groupids' => $groupids,
- 'with_monitored_items' => true,
- 'preservekeys' => true,
- 'limit' => $limit
- ]);
- }
+ $data = [];
+ $item_counter = [];
+ $db_hosts = [];
- CArrayHelper::sort($db_hosts, [
- ['field' => 'name', 'order' => ZBX_SORT_UP]
- ]);
+ foreach ($db_items as $db_item) {
+ $item_name = $db_item['name_expanded'];
+ $host_name = $db_item['hosts'][0]['name'];
+ $db_hosts[$db_item['hostid']] = $db_item['hosts'][0];
- return $db_hosts;
-}
+ if (!array_key_exists($host_name, $item_counter)) {
+ $item_counter[$host_name] = [];
+ }
-/**
- * @param array $groupids
- * @param array $hostids
- * @param string $application
- *
- * @return array
- */
-function getDataOverviewLeft(?array $groupids, ?array $hostids, string $application = ''): array {
- $db_items = getDataOverviewItems($groupids, $hostids, $application);
- $items_by_name = [];
- foreach ($db_items as $itemid => $db_item) {
- if (!array_key_exists($db_item['name_expanded'], $items_by_name)) {
- $items_by_name[$db_item['name_expanded']] = [];
+ if (!array_key_exists($item_name, $item_counter[$host_name])) {
+ $item_counter[$host_name][$item_name] = 0;
}
- $items_by_name[$db_item['name_expanded']][$db_item['hostid']] = $itemid;
- }
- $hidden_items_cnt = count(array_splice($items_by_name, (int) CSettingsHelper::get(
- CSettingsHelper::MAX_OVERVIEW_TABLE_SIZE
- )));
+ $item_place = $item_counter[$host_name][$item_name];
+ $item_counter[$host_name][$item_name]++;
- $itemids = [];
- foreach ($items_by_name as $hostid_to_itemid) {
- foreach ($hostid_to_itemid as $itemid) {
- $itemids[] = $itemid;
+ $item = [
+ 'itemid' => $db_item['itemid'],
+ 'value_type' => $db_item['value_type'],
+ 'units' => $db_item['units'],
+ 'valuemapid' => $db_item['valuemapid'],
+ 'acknowledged' => array_key_exists('acknowledged', $db_item) ? $db_item['acknowledged'] : 0
+ ];
+
+ if (array_key_exists('triggerid', $db_item)) {
+ $item += [
+ 'triggerid' => $db_item['triggerid'],
+ 'severity' => $db_item['priority'],
+ 'tr_value' => $db_item['value']
+ ];
+ }
+ else {
+ $item += [
+ 'triggerid' => null,
+ 'severity' => null,
+ 'tr_value' => null
+ ];
}
+
+ $data[$item_name][$item_place][$host_name] = $item;
}
- $db_items = array_intersect_key($db_items, array_flip($itemids));
- $db_hosts = getDataOverviewHosts(null, null, $itemids);
- $db_hosts_ctn = count($db_hosts);
- $db_hosts = array_slice($db_hosts, 0, (int) CSettingsHelper::get(CSettingsHelper::MAX_OVERVIEW_TABLE_SIZE), true);
+ CArrayHelper::sort($db_hosts, [
+ ['field' => 'name', 'order' => ZBX_SORT_UP],
+ ]);
- $has_hidden_data = ($hidden_items_cnt || ($db_hosts_ctn > count($db_hosts)));
+ $data_display_limit = (int) CSettingsHelper::get(CSettingsHelper::MAX_OVERVIEW_TABLE_SIZE);
+ $has_hidden_hosts = (count($db_hosts) > $data_display_limit);
+ $db_hosts = array_slice($db_hosts, 0, $data_display_limit, true);
- return [$db_items, $db_hosts, $items_by_name, $has_hidden_data];
-}
+ $data = array_slice($data, 0, $data_display_limit);
+ $items_left = $data_display_limit;
+ $itemids = [];
+ array_walk($data, function (array &$item_columns) use ($data_display_limit, &$itemids, &$items_left) {
+ if ($items_left != 0) {
+ $item_columns = array_slice($item_columns, 0, min($data_display_limit, $items_left));
+ $items_left -= count($item_columns);
+ }
+ else {
+ $item_columns = null;
+ return;
+ }
-/**
- * @param array $groupids
- * @param array $hostids
- * @param string $application
- *
- * @return array
- */
-function getDataOverviewTop(?array $groupids, ?array $hostids, string $application = ''): array {
- $db_hosts = getDataOverviewHosts($groupids, $hostids, null, $application);
- $hostids = array_keys($db_hosts);
- $hidden_db_hosts_cnt = count(array_splice($hostids, (int) CSettingsHelper::get(
- CSettingsHelper::MAX_OVERVIEW_TABLE_SIZE
- )));
- $db_hosts = array_intersect_key($db_hosts, array_flip($hostids));
-
- $db_items = getDataOverviewItems(null, $hostids, $application);
- $items_by_name = [];
- foreach ($db_items as $itemid => $db_item) {
- if (!array_key_exists($db_item['name_expanded'], $items_by_name)) {
- $items_by_name[$db_item['name_expanded']] = [];
- }
- $items_by_name[$db_item['name_expanded']][$db_item['hostid']] = $itemid;
- }
-
- $items_by_name_ctn = count($items_by_name);
- $items_by_name = array_slice($items_by_name, 0,
- (int) CSettingsHelper::get(CSettingsHelper::MAX_OVERVIEW_TABLE_SIZE), true
- );
+ array_walk($item_columns, function (array &$item_column) use ($data_display_limit, &$itemids) {
+ $item_column = array_slice($item_column, 0, $data_display_limit);
+ $itemids += array_column($item_column, 'itemid', 'itemid');
+ });
+ });
+ $data = array_filter($data);
+
+ $has_hidden_items = (count($db_items) != count($itemids));
- $has_hidden_data = ($hidden_db_hosts_cnt || ($items_by_name_ctn > count($items_by_name)));
+ $db_items = array_intersect_key($db_items, $itemids);
+ $data = getDataOverviewCellData($db_items, $data, $filter['show_suppressed']);
- return [$db_items, $db_hosts, $items_by_name, $has_hidden_data];
+ return [$data, $db_hosts, ($has_hidden_items || $has_hidden_hosts)];
}
/**
diff --git a/ui/include/triggers.inc.php b/ui/include/triggers.inc.php
index a9625c269bd..9dbe4ae2fcc 100644
--- a/ui/include/triggers.inc.php
+++ b/ui/include/triggers.inc.php
@@ -676,55 +676,47 @@ function replace_template_dependencies($deps, $hostid) {
}
/**
+ * Prepare arrays containing only hosts and triggers that will be shown results table.
+ *
* @param array $db_hosts
* @param array $db_triggers
- * @param int $limit
*
* @return array
*/
-function getTriggersOverviewTableData(array $db_hosts, array $db_triggers, int $limit): array {
+function getTriggersOverviewTableData(array $db_hosts, array $db_triggers): array {
+ // Prepare triggers to show in results table.
$triggers_by_name = [];
- $hosts_by_name = [];
- $exceeded_hosts = false;
- $exceeded_trigs = false;
-
foreach ($db_triggers as $trigger) {
- $trigger_name = $trigger['description'];
- $triggerid = $trigger['triggerid'];
-
- CArrayHelper::sort($trigger['hosts'], ['name']);
-
foreach ($trigger['hosts'] as $host) {
- $host_name = $host['name'];
- $hostid = $host['hostid'];
-
- if (!array_key_exists($hostid, $db_hosts)) {
+ if (!array_key_exists($host['hostid'], $db_hosts)) {
continue;
}
- if (!array_key_exists($trigger_name, $triggers_by_name)) {
- $triggers_by_name[$trigger_name] = [];
- }
-
- if (!array_key_exists($host_name, $hosts_by_name)) {
- $hosts_by_name[$host_name] = [];
- }
-
- $triggers_by_name[$trigger_name][$hostid] = $triggerid;
- $hosts_by_name[$host_name] = $hostid;
+ $triggers_by_name[$trigger['description']][$host['hostid']] = $trigger['triggerid'];
+ }
+ }
- $exceeded_trigs = (count($triggers_by_name) > $limit);
- $exceeded_hosts = (count($hosts_by_name) > $limit);
+ $limit = (int) CSettingsHelper::get(CSettingsHelper::MAX_OVERVIEW_TABLE_SIZE);
+ $exceeded_trigs = (count($triggers_by_name) > $limit);
+ $triggers_by_name = array_slice($triggers_by_name, 0, $limit);
+ foreach ($triggers_by_name as $name => $triggers) {
+ $triggers_by_name[$name] = array_slice($triggers, 0, $limit, true);
+ }
- if ($exceeded_hosts || $exceeded_trigs) {
- $hosts_by_name = array_slice($hosts_by_name, 0, $limit, true);
- $triggers_by_name = array_slice($triggers_by_name, 0, $limit, true);
- break 2;
- }
+ // Prepare hosts to show in results table.
+ $exceeded_hosts = false;
+ $hosts_by_name = [];
+ foreach ($db_hosts as $host) {
+ if (count($hosts_by_name) >= $limit) {
+ $exceeded_hosts = true;
+ break;
+ }
+ else {
+ $hosts_by_name[$host['name']] = $host['hostid'];
}
}
- return [$triggers_by_name, $hosts_by_name, $exceeded_hosts, $exceeded_trigs];
+ return [$triggers_by_name, $hosts_by_name, ($exceeded_hosts || $exceeded_trigs)];
}
/**
@@ -742,16 +734,10 @@ function getTriggersOverviewTableData(array $db_hosts, array $db_triggers, int $
function getTriggersOverviewData(array $groupids, string $application, array $host_options = [],
array $trigger_options = [], array $problem_options = []): array {
- $exhausted_hosts = false;
- $exhausted_triggers = false;
- $exceeded_hosts = false;
- $exceeded_trigs = false;
-
$host_options = [
'output' => ['hostid', 'name'],
'groupids' => $groupids ? $groupids : null,
- 'sortfield' => 'name',
- 'sortorder' => ZBX_SORT_UP,
+ 'with_monitored_triggers' => true,
'preservekeys' => true
] + $host_options;
@@ -761,78 +747,65 @@ function getTriggersOverviewData(array $groupids, string $application, array $ho
],
'selectHosts' => ['hostid', 'name'],
'selectDependencies' => ['triggerid'],
- 'monitored' => true,
- 'sortfield' => 'description',
- 'sortorder' => ZBX_SORT_UP,
- 'preservekeys' => true
+ 'monitored' => true
] + $trigger_options;
$problem_options += [
- 'min_severity' => TRIGGER_SEVERITY_NOT_CLASSIFIED,
- 'show_suppressed' => ZBX_PROBLEM_SUPPRESSED_FALSE,
- 'time_from' => null
+ 'show_suppressed' => ZBX_PROBLEM_SUPPRESSED_FALSE
];
- $db_triggers = [];
- $db_hosts = [];
- $applicationids = [];
- $dependencies = [];
-
- $triggers_by_name = [];
- $hosts_by_name = [];
-
$limit = (int) CSettingsHelper::get(CSettingsHelper::MAX_OVERVIEW_TABLE_SIZE);
- $axis_limit = (int) CSettingsHelper::get(CSettingsHelper::MAX_OVERVIEW_TABLE_SIZE);
do {
- if (!$exhausted_hosts) {
- $db_hosts = API::Host()->get(['limit' => $limit + 1] + $host_options);
- $exhausted_hosts = (count($db_hosts) < $limit);
-
- if ($application !== '') {
- $applications = API::Application()->get([
- 'output' => [],
- 'hostids' => array_keys($db_hosts),
- 'search' => ['name' => $application],
- 'preservekeys' => true
- ]);
- $applicationids = array_keys($applications);
- }
- }
+ $db_hosts = API::Host()->get(['limit' => $limit + 1] + $host_options);
+ $fetch_hosts = (count($db_hosts) > $limit);
- if (!$exhausted_triggers) {
- $db_triggers = getTriggersWithActualSeverity([
- 'applicationids' => ($application !== '') ? $applicationids : null,
+ $applicationids = ($application !== '')
+ ? array_keys(API::Application()->get([
+ 'output' => [],
'hostids' => array_keys($db_hosts),
- 'limit' => $limit + 1
- ]+ $trigger_options, $problem_options);
+ 'search' => ['name' => $application],
+ 'preservekeys' => true
+ ]))
+ : null;
- $db_triggers = CMacrosResolverHelper::resolveTriggerNames($db_triggers, true);
+ $db_triggers = getTriggersWithActualSeverity([
+ 'applicationids' => $applicationids,
+ 'hostids' => array_keys($db_hosts)
+ ] + $trigger_options, $problem_options);
- if ($db_triggers) {
- $dependencies = getTriggerDependencies($db_triggers);
- }
+ if (!$db_triggers) {
+ $db_hosts = [];
+ }
- $exhausted_triggers = (count($db_triggers) < $limit);
+ // Unset hosts without having matching triggers.
+ $represented_hosts = [];
+ foreach ($db_triggers as $trigger) {
+ $hostids = array_column($trigger['hosts'], 'hostid');
+ $represented_hosts += array_combine($hostids, $hostids);
}
- CArrayHelper::sort($db_triggers, ['description']);
+ $db_hosts = array_intersect_key($db_hosts, $represented_hosts);
- list($triggers_by_name, $hosts_by_name, $exceeded_hosts, $exceeded_trigs) = getTriggersOverviewTableData(
- $db_hosts, $db_triggers, $axis_limit
- );
+ $fetch_hosts &= (count($db_hosts) < $limit);
+ $limit += (int) CSettingsHelper::get(CSettingsHelper::MAX_OVERVIEW_TABLE_SIZE);
- if ($exceeded_hosts || $exceeded_trigs) {
- break;
- }
+ } while ($fetch_hosts);
- $limit += $limit;
- } while (!($exhausted_triggers && $exhausted_hosts));
+ CArrayHelper::sort($db_hosts, [
+ ['field' => 'name', 'order' => ZBX_SORT_UP]
+ ]);
- CArrayHelper::sort($db_hosts, ['name']);
+ $db_triggers = CMacrosResolverHelper::resolveTriggerNames($db_triggers, true);
+ $dependencies = $db_triggers ? getTriggerDependencies($db_triggers) : [];
- return [$db_hosts, $db_triggers, $dependencies, $triggers_by_name, $hosts_by_name, $exceeded_hosts, $exceeded_trigs
- ];
+ CArrayHelper::sort($db_triggers, [
+ ['field' => 'description', 'order' => ZBX_SORT_UP]
+ ]);
+
+ [$triggers_by_name, $hosts_by_name, $exceeded_limit] = getTriggersOverviewTableData($db_hosts, $db_triggers);
+
+ return [$db_hosts, $db_triggers, $dependencies, $triggers_by_name, $hosts_by_name, $exceeded_limit];
}
/**
@@ -963,8 +936,8 @@ function getTriggersWithActualSeverity(array $trigger_options, array $problem_op
/**
* Creates and returns a trigger status cell for the trigger overview table.
*
- * @param array $trigger
- * @param array $dependencies The list of trigger dependencies, prepared by getTriggerDependencies() function.
+ * @param array $trigger
+ * @param array $dependencies The list of trigger dependencies, prepared by getTriggerDependencies() function.
*
* @return CCol
*/
diff --git a/ui/include/views/monitoring.overview.items.php b/ui/include/views/monitoring.overview.items.php
index a5409e68dd0..57233418f43 100644
--- a/ui/include/views/monitoring.overview.items.php
+++ b/ui/include/views/monitoring.overview.items.php
@@ -156,22 +156,12 @@ if ($web_layout_mode == ZBX_LAYOUT_NORMAL) {
);
}
-if ($data['view_style'] == STYLE_TOP) {
- $table = new CPartial('dataoverview.table.top', [
- 'visible_items' => $data['visible_items'],
- 'db_hosts' => $data['db_hosts'],
- 'items_by_name' => $data['items_by_name'],
- 'has_hidden_data' => $data['has_hidden_data']
- ]);
-}
-else {
- $table = new CPartial('dataoverview.table.left', [
- 'visible_items' => $data['visible_items'],
- 'db_hosts' => $data['db_hosts'],
- 'items_by_name' => $data['items_by_name'],
- 'has_hidden_data' => $data['has_hidden_data']
- ]);
-}
+$partial = ($data['view_style'] == STYLE_TOP) ? 'dataoverview.table.top' : 'dataoverview.table.left';
+$table = new CPartial($partial, [
+ 'items' => $data['items'],
+ 'hosts' => $data['hosts'],
+ 'has_hidden_data' => $data['has_hidden_data']
+]);
$widget->addItem($table);
diff --git a/ui/overview.php b/ui/overview.php
index 8526a8ff299..0c20441345d 100644
--- a/ui/overview.php
+++ b/ui/overview.php
@@ -134,8 +134,7 @@ $data = [
'dependencies' => [],
'triggers_by_name' => [],
'hosts_by_name' => [],
- 'exceeded_hosts' => false,
- 'exceeded_trigs' => false
+ 'exceeded_limit' => false
];
// fetch trigger data
@@ -219,9 +218,9 @@ if ($type == SHOW_TRIGGERS) {
'close' => CWebUser::checkAccess(CRoleHelper::ACTIONS_CLOSE_PROBLEMS)
];
- list($data['db_hosts'], $data['db_triggers'], $data['dependencies'], $data['triggers_by_name'],
- $data['hosts_by_name'], $data['exceeded_hosts'], $data['exceeded_trigs']
- ) = getTriggersOverviewData($groupids, $filter['application'], $host_options, $trigger_options, $problem_options);
+ [$data['db_hosts'], $data['db_triggers'], $data['dependencies'], $data['triggers_by_name'], $data['hosts_by_name'],
+ $data['exceeded_limit']
+ ] = getTriggersOverviewData($groupids, $filter['application'], $host_options, $trigger_options, $problem_options);
$data['filter'] = $filter;
@@ -262,23 +261,7 @@ else {
$groupids = $data['filter']['groups'] ? getSubGroups(array_keys($data['filter']['groups'])) : null;
$hostids = $data['filter']['hosts'] ? array_keys($data['filter']['hosts']) : null;
- if ($data['view_style'] == STYLE_TOP) {
- list($db_items, $db_hosts, $items_by_name, $has_hidden_data) = getDataOverviewTop($groupids, $hostids,
- $data['filter']['application']
- );
- }
- else {
- list($db_items, $db_hosts, $items_by_name, $has_hidden_data) = getDataOverviewLeft($groupids, $hostids,
- $data['filter']['application']
- );
- }
-
- $data['visible_items'] = getDataOverviewCellData($db_hosts, $db_items, $items_by_name,
- $data['filter']['show_suppressed']
- );
- $data['db_hosts'] = $db_hosts;
- $data['items_by_name'] = $items_by_name;
- $data['has_hidden_data'] = $has_hidden_data;
+ [$data['items'], $data['hosts'], $data['has_hidden_data']] = getDataOverview($groupids, $hostids, $data['filter']);
// Render view.
echo (new CView('monitoring.overview.items', $data))->getOutput();