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// indicator of sort field 23$sort_div = (new CSpan())->addClass(ZBX_STYLE_ARROW_UP); 24 25$table = (new CTableInfo()) 26 ->setHeader([ 27 [_('Host group'), $sort_div], 28 _('Without problems'), 29 _('With problems'), 30 _('Total') 31 ]) 32 ->setHeadingColumn(0); 33 34$url_group = (new CUrl('zabbix.php')) 35 ->setArgument('action', 'problem.view') 36 ->setArgument('filter_set', 1) 37 ->setArgument('filter_show', TRIGGERS_OPTION_RECENT_PROBLEM) 38 ->setArgument('filter_groupids', null) 39 ->setArgument('filter_hostids', $data['filter']['hostids']) 40 ->setArgument('filter_name', $data['filter']['problem']) 41 ->setArgument('filter_show_suppressed', ($data['filter']['show_suppressed'] == ZBX_PROBLEM_SUPPRESSED_TRUE) 42 ? ZBX_PROBLEM_SUPPRESSED_TRUE 43 : null 44 ); 45$url_host = (new CUrl('zabbix.php')) 46 ->setArgument('action', 'problem.view') 47 ->setArgument('filter_set', 1) 48 ->setArgument('filter_show', TRIGGERS_OPTION_RECENT_PROBLEM) 49 ->setArgument('filter_groupids', null) 50 ->setArgument('filter_hostids', null) 51 ->setArgument('filter_name', $data['filter']['problem']) 52 ->setArgument('filter_show_suppressed', ($data['filter']['show_suppressed'] == ZBX_PROBLEM_SUPPRESSED_TRUE) 53 ? ZBX_PROBLEM_SUPPRESSED_TRUE 54 : null 55 ); 56 57foreach ($data['groups'] as $group) { 58 $problematic_count_key = ($data['filter']['ext_ack'] == EXTACK_OPTION_UNACK) 59 ? 'hosts_problematic_unack_count' 60 : 'hosts_problematic_count'; 61 62 if ($data['filter']['hide_empty_groups'] && $group[$problematic_count_key] == 0) { 63 continue; 64 } 65 66 $url_group->setArgument('filter_groupids', [$group['groupid']]); 67 $url_host->setArgument('filter_groupids', [$group['groupid']]); 68 69 $group_row = [new CLink($group['name'], $url_group->getUrl())]; 70 71 // Add cell for column 'Without problems'. 72 $group_row[] = ($group['hosts_total_count'] != $group[$problematic_count_key]) 73 ? $group['hosts_total_count'] - $group[$problematic_count_key] 74 : ''; 75 76 /** 77 * Create a CLinkAction element with hint-boxed table that contains hosts of particular host group and number of 78 * unacknowledged problems for each host, grouped per problem severity. 79 */ 80 if ($data['filter']['ext_ack'] != EXTACK_OPTION_ALL) { 81 if ($group['hosts_problematic_unack_list']) { 82 $last_unack_count = (new CLinkAction($group['hosts_problematic_unack_count']))->setHint( 83 makeProblemHostsHintBox($group['hosts_problematic_unack_list'], $data, $url_host) 84 ); 85 } 86 else { 87 $last_unack_count = null; 88 } 89 } 90 91 /** 92 * Create a CLinkAction element with hint-boxed table that contains hosts of particular host group and number of all 93 * problems for each host, grouped per problem severity. 94 */ 95 if ($data['filter']['ext_ack'] != EXTACK_OPTION_UNACK && $group['hosts_problematic_count'] != 0) { 96 $problematic_count = (new CLinkAction($group['hosts_problematic_count'])) 97 ->setHint(makeProblemHostsHintBox($group['hosts_problematic_list'], $data, $url_host)) 98 ->setAttribute('aria-label', _xs('%1$s, Severity, %2$s', 'screen reader', 99 $group['hosts_problematic_count'], getSeverityName($group['highest_severity'], $data['config']) 100 )); 101 } 102 103 // Add 'With problems' column with ext_ack specific content. 104 switch ($data['filter']['ext_ack']) { 105 case EXTACK_OPTION_ALL: 106 if ($group['hosts_problematic_count'] != 0) { 107 $group_row[] = (new CCol($problematic_count))->addClass(getSeverityStyle($group['highest_severity'])); 108 } 109 else { 110 $group_row[] = ''; 111 } 112 break; 113 114 case EXTACK_OPTION_BOTH: 115 if ($group['hosts_problematic_count'] != 0) { 116 $unack_span = ($last_unack_count !== null) ? [$last_unack_count, ' '._('of').' '] : null; 117 $group_row[] = (new CCol([$unack_span, $problematic_count])) 118 ->addClass(getSeverityStyle($group['highest_severity'])); 119 } 120 else { 121 $group_row[] = ''; 122 } 123 break; 124 125 case EXTACK_OPTION_UNACK: 126 if ($group['hosts_problematic_unack_count'] != 0) { 127 $group_row[] = (new CCol($last_unack_count))->addClass(getSeverityStyle($group['highest_severity'])); 128 } 129 else { 130 $group_row[] = ''; 131 } 132 break; 133 } 134 135 // Add 'Total' column. 136 $group_row[] = $group['hosts_total_count']; 137 138 $table->addRow($group_row); 139} 140 141$output = [ 142 'header' => $data['name'], 143 'body' => $table->toString() 144]; 145 146if (($messages = getMessages()) !== null) { 147 $output['messages'] = $messages->toString(); 148} 149 150if ($data['user']['debug_mode'] == GROUP_DEBUG_MODE_ENABLED) { 151 CProfiler::getInstance()->stop(); 152 $output['debug'] = CProfiler::getInstance()->make()->toString(); 153} 154 155echo (new CJson())->encode($output); 156