Source
xxxxxxxxxx
* @param array $prepared_data [IN/OUT] Result of items matching primary filter.
<?php
/*
** Copyright (C) 2001-2025 Zabbix SIA
**
** This program is free software: you can redistribute it and/or modify it under the terms of
** the GNU Affero General Public License as published by the Free Software Foundation, version 3.
**
** This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
** without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
** See the GNU Affero General Public License for more details.
**
** You should have received a copy of the GNU Affero General Public License along with this program.
** If not, see <https://www.gnu.org/licenses/>.
**/
/**
* Base controller for the "Latest data" page and the "Latest data" asynchronous refresh page.
*/
abstract class CControllerLatest extends CController {
// Filter idx prefix.
public const FILTER_IDX = 'web.monitoring.latest';
// Number of tag value rows allowed to be included in subfilter.
public const SUBFILTERS_TAG_VALUE_ROWS = 10;
// Number of tag value rows when tag values subfilter is expanded.
private const SUBFILTERS_TAG_VALUE_ROWS_EXPANDED = 200;
// Filter fields default values.
public const FILTER_FIELDS_DEFAULT = [
'groupids' => [],
'hostids' => [],
'name' => '',
'evaltype' => TAG_EVAL_TYPE_AND_OR,
'tags' => [],
'state' => -1,
'show_tags' => SHOW_TAGS_3,
'tag_name_format' => TAG_NAME_FULL,
'tag_priority' => '',
'show_details' => 0,
'page' => null,
'sort' => 'name',
'sortorder' => ZBX_SORT_UP,
'subfilter_hostids' => [],
'subfilter_tagnames' => [],
'subfilter_tags' => [],
'subfilter_state' => [],
'subfilter_data' => []
];
// Mandatory filter fields.
public const MANDATORY_FILTER_FIELDS = ['groupids', 'hostids', 'name', 'tags', 'state'];
/**
* Prepare the latest data based on the given filter and sorting options.
*
* @param array $filter Item filter options.
* @param array $filter['groupids'] Filter items by host groups.
* @param array $filter['hostids'] Filter items by hosts.
* @param string $filter['name'] Filter items by name.
* @param int $filter['evaltype'] Filter evaltype.
* @param array $filter['tags'] Filter tags.
* @param string $filter['tags'][]['tag']
* @param string $filter['tags'][]['value']
* @param int $filter['tags'][]['operator']
* @param int $filter['state'] Filter state.
* @param string $sort_field Sorting field.
* @param string $sort_order Sorting order.
*
* @return array
*/
protected function prepareData(array $filter, $sort_field, $sort_order) {
// Select groups for subsequent selection of hosts and items.
$groupids = $filter['groupids'] ? getSubGroups($filter['groupids']) : null;
// Select hosts for subsequent selection of items.
$hosts = API::Host()->get([
'output' => ['hostid', 'name', 'status', 'maintenanceid', 'maintenance_status', 'maintenance_type'],
'groupids' => $groupids,
'hostids' => $filter['hostids'] ?: null,
'preservekeys' => true
]);
$search_limit = CSettingsHelper::get(CSettingsHelper::SEARCH_LIMIT);
$select_items_cnt = 0;
$select_items = [];
foreach ($hosts as $hostid => $host) {
if ($select_items_cnt > $search_limit) {