1<?php
2/*
3** Zabbix
4** Copyright (C) 2001-2021 Zabbix SIA
5**
6** This program is free software; you can redistribute it and/or modify
7** it under the terms of the GNU General Public License as published by
8** the Free Software Foundation; either version 2 of the License, or
9** (at your option) any later version.
10**
11** This program is distributed in the hope that it will be useful,
12** but WITHOUT ANY WARRANTY; without even the implied warranty of
13** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14** GNU General Public License for more details.
15**
16** You should have received a copy of the GNU General Public License
17** along with this program; if not, write to the Free Software
18** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19**/
20
21
22/**
23 * @var CView $this
24 */
25
26// indicator of sort field
27$sort_div = (new CSpan())->addClass(ZBX_STYLE_ARROW_UP);
28
29$table = (new CTableInfo())
30	->setHeader([[_('Host group'), $sort_div], _('Ok'), _('Failed'), _('Unknown')])
31	->setHeadingColumn(0);
32
33$url = $data['allowed_ui_hosts']
34	? (new CUrl('zabbix.php'))
35		->setArgument('action', 'web.view')
36		->setArgument('filter_set', '1')
37	: null;
38
39foreach ($data['groups'] as $group) {
40	if ($url !== null) {
41		$url->setArgument('filter_groupids', [$group['groupid']]);
42		$group_name = new CLink($group['name'], $url->getUrl());
43	}
44	else {
45		$group_name = $group['name'];
46	}
47
48	$table->addRow([
49		$group_name,
50		($group['ok'] != 0) ? (new CSpan($group['ok']))->addClass(ZBX_STYLE_GREEN) : '',
51		($group['failed'] != 0) ? (new CSpan($group['failed']))->addClass(ZBX_STYLE_RED) : '',
52		($group['unknown'] != 0) ? (new CSpan($group['unknown']))->addClass(ZBX_STYLE_GREY) : ''
53	]);
54}
55
56$output = [
57	'name' => $data['name'],
58	'body' => $table->toString()
59];
60
61if (($messages = getMessages()) !== null) {
62	$output['messages'] = $messages->toString();
63}
64
65if ($data['user']['debug_mode'] == GROUP_DEBUG_MODE_ENABLED) {
66	CProfiler::getInstance()->stop();
67	$output['debug'] = CProfiler::getInstance()->make()->toString();
68}
69
70echo json_encode($output);
71