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$groups = API::HostGroup()->get([ 23 'output' => ['groupid', 'name'], 24 'groupids' => $data['filter']['groupids'], 25 'hostids' => isset($data['filter']['hostids']) ? $data['filter']['hostids'] : null, 26 'monitored_hosts' => true, 27 'with_monitored_httptests' => true, 28 'preservekeys' => true 29]); 30CArrayHelper::sort($groups, ['name']); 31 32$groupIds = array_keys($groups); 33 34$availableHosts = API::Host()->get([ 35 'output' => ['hostid'], 36 'groupids' => $groupIds, 37 'hostids' => isset($data['filter']['hostids']) ? $data['filter']['hostids'] : null, 38 'filter' => ['maintenance_status' => $data['filter']['maintenance']], 39 'monitored_hosts' => true, 40 'preservekeys' => true 41]); 42$availableHostIds = array_keys($availableHosts); 43 44$table_data = []; 45 46// fetch links between HTTP tests and host groups 47$result = DbFetchArray(DBselect( 48 'SELECT DISTINCT ht.httptestid,hg.groupid'. 49 ' FROM httptest ht,hosts_groups hg'. 50 ' WHERE ht.hostid=hg.hostid'. 51 ' AND '.dbConditionInt('hg.hostid', $availableHostIds). 52 ' AND '.dbConditionInt('hg.groupid', $groupIds). 53 ' AND ht.status='.HTTPTEST_STATUS_ACTIVE 54)); 55 56// fetch HTTP test execution data 57$httpTestData = Manager::HttpTest()->getLastData(zbx_objectValues($result, 'httptestid')); 58 59foreach ($result as $row) { 60 if (!array_key_exists($row['groupid'], $table_data)) { 61 $table_data[$row['groupid']] = [ 62 'ok' => 0, 63 'failed' => 0, 64 'unknown' => 0 65 ]; 66 } 67 68 if (isset($httpTestData[$row['httptestid']]) && $httpTestData[$row['httptestid']]['lastfailedstep'] !== null) { 69 $table_data[$row['groupid']][$httpTestData[$row['httptestid']]['lastfailedstep'] != 0 ? 'failed' : 'ok']++; 70 } 71 else { 72 $table_data[$row['groupid']]['unknown']++; 73 } 74} 75 76$table = (new CTableInfo())->setHeader([_('Host group'), _('Ok'), _('Failed'), _('Unknown')]); 77 78foreach ($groups as $group) { 79 if (array_key_exists($group['groupid'], $table_data)) { 80 $table->addRow([ 81 new CLink($group['name'], 'zabbix.php?action=web.view&groupid='.$group['groupid'].'&hostid=0'), 82 (new CSpan($table_data[$group['groupid']]['ok']))->addClass(ZBX_STYLE_GREEN), 83 (new CSpan($table_data[$group['groupid']]['failed'])) 84 ->addClass($table_data[$group['groupid']]['failed'] == 0 ? ZBX_STYLE_GREEN : ZBX_STYLE_RED), 85 (new CSpan($table_data[$group['groupid']]['unknown']))->addClass(ZBX_STYLE_GREY) 86 ]); 87 } 88} 89 90$output = [ 91 'header' => _('Web monitoring'), 92 'body' => (new CDiv([getMessages(), $table]))->toString(), 93 'footer' => (new CListItem(_s('Updated: %s', zbx_date2str(TIME_FORMAT_SECONDS))))->toString() 94]; 95 96if ($data['user']['debug_mode'] == GROUP_DEBUG_MODE_ENABLED) { 97 CProfiler::getInstance()->stop(); 98 $output['debug'] = CProfiler::getInstance()->make()->toString(); 99} 100 101echo (new CJson())->encode($output); 102