Source
array $submaps_relations, $severity_min = 0, array &$problems_counted = [], array $triggers_per_hosts = [],
<?php
/*
** Zabbix
** Copyright (C) 2001-2024 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.
**/
require_once dirname(__FILE__).'/../../include/blocks.inc.php';
class CControllerWidgetNavTreeView extends CControllerWidget {
private $problems_per_severity_tpl;
public function __construct() {
parent::__construct();
$this->setType(WIDGET_NAV_TREE);
$this->setValidationRules([
'name' => 'string',
'widgetid' => 'db widget.widgetid',
'initial_load' => 'in 0,1',
'fields' => 'json'
]);
}
protected function getNumberOfProblemsBySysmap(array $navtree_items = []) {
$response = [];
$sysmapids = [];
foreach ($navtree_items as $navtree_item) {
$sysmapids[$navtree_item['sysmapid']] = true;
}
unset($sysmapids[0]);
$sysmaps = $sysmapids
? API::Map()->get([
'output' => ['sysmapid', 'severity_min'],
'selectLinks' => ['linktriggers', 'permission'],
'selectSelements' => ['elements', 'elementtype', 'permission'],
'sysmapids' => array_keys($sysmapids),
'preservekeys' => true
])
: [];
if ($sysmaps) {
$triggers_per_hosts = [];
$triggers_per_host_groups = [];
$problems_per_trigger = [];
$submaps_relations = [];
$submaps_found = [];
$host_groups = [];
$hosts = [];
// Gather submaps from all selected maps.
foreach ($sysmaps as $map) {
foreach ($map['selements'] as $selement) {
if ($selement['elementtype'] == SYSMAP_ELEMENT_TYPE_MAP) {
if (($element = reset($selement['elements'])) !== false) {
$submaps_relations[$map['sysmapid']][] = $element['sysmapid'];
$submaps_found[] = $element['sysmapid'];
}
}
}
}
// Gather maps added as submaps for each of map in any depth.
$sysmaps_resolved = array_keys($sysmaps);
while ($diff = array_diff($submaps_found, $sysmaps_resolved)) {
$submaps = API::Map()->get([
'output' => ['sysmapid', 'severity_min'],
'selectLinks' => ['linktriggers', 'permission'],
'selectSelements' => ['elements', 'elementtype', 'permission'],
'sysmapids' => $diff,
'preservekeys' => true
]);
$sysmaps_resolved = array_merge($sysmaps_resolved, $diff);