Source
* Calculate which items retrieved using the primary filter matches selected subfilter options. Results are added to
<?php declare(strict_types = 0);
/*
** Zabbix
** Copyright (C) 2001-2022 Zabbix SIA
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** 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 General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**/
/**
* Common methods for "charts.view" and "charts.view.json" actions.
*/
abstract class CControllerCharts extends CController {
// Number of subfilter values per row.
const SUBFILTERS_VALUES_PER_ROW = 100;
// Number of tag value rows allowed to be included in subfilter.
const SUBFILTERS_TAG_VALUE_ROWS = 20;
/**
* Fetches all host graphs based on hostid and graph name or item name used in graph.
*
* @param array $hostids Limit returned graphs to these hosts.
* @param string $name Graphs or items in them should contain this string in their name.
*
* @return array
*/
protected function getHostGraphs(array $hostids, string $name): array {
$graphs = API::Graph()->get([
'output' => ['graphid', 'name'],
'hostids' => $hostids,
'search' => $name !== '' ? ['name' => $name] : null,
'selectItems' => ['itemid'],
'preservekeys' => true
]);
$graph_items = [];
foreach ($graphs as $graph) {
foreach ($graph['items'] as $item) {
$graph_items[$item['itemid']] = $item;
}
}
$filter_items = [];
if ($name !== '') {
$filter_items = API::Item()->get([
'output' => ['itemid'],
'hostids' => $hostids,
'search' => ['name' => $name],
'preservekeys' => true
]);
if ($filter_items) {
$graphs += API::Graph()->get([
'output' => ['graphid', 'name'],
'hostids' => $hostids,
'itemids' => array_keys($filter_items),
'selectItems' => ['itemid'],
'preservekeys' => true
]);
}
}
$items = [];
if ($graph_items || $filter_items) {
$items = API::Item()->get([
'output' => ['itemid', 'name'],
'hostids' => $hostids,
'itemids' => array_keys($graph_items + $filter_items),
'selectTags' => ['tag', 'value'],
'preservekeys' => true
]);
}
return $this->addTagsToGraphs($graphs, $items);
}
private function addTagsToGraphs(array $graphs, array $items): array {
foreach ($graphs as &$graph) {