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$type_field_names = [ 27 INTERFACE_TYPE_AGENT => _('Zabbix agent'), 28 INTERFACE_TYPE_SNMP => _('SNMP'), 29 INTERFACE_TYPE_JMX => _('JMX'), 30 INTERFACE_TYPE_IPMI => _('IPMI') 31]; 32 33$header = [ 34 STYLE_HORIZONTAL => ['', _('Available'), _('Not available'), _('Unknown'), _('Total')], 35 STYLE_VERTICAL => [''] 36]; 37 38foreach ($type_field_names as $key => $value) { 39 if (!in_array($key, $data['hosts_types'])) { 40 continue; 41 } 42 43 $header[STYLE_VERTICAL][] = $value; 44} 45 46if (count($data['hosts_types']) == 1) { 47 $counts = $data['hosts_count'][$data['hosts_types'][0]]; 48 49 $table = (new CDiv()) 50 ->addClass(ZBX_STYLE_HOST_AVAIL_WIDGET) 51 ->addClass(ZBX_STYLE_TOTALS_LIST) 52 ->addClass(($data['layout'] == STYLE_HORIZONTAL) 53 ? ZBX_STYLE_TOTALS_LIST_HORIZONTAL 54 : ZBX_STYLE_TOTALS_LIST_VERTICAL 55 ); 56 57 $table->addItem((new CDiv([ 58 (new CSpan($counts[INTERFACE_AVAILABLE_TRUE]))->addClass(ZBX_STYLE_TOTALS_LIST_COUNT), _('Available') 59 ]))->addClass(ZBX_STYLE_HOST_AVAIL_TRUE)); 60 61 $table->addItem((new CDiv([ 62 (new CSpan($counts[INTERFACE_AVAILABLE_FALSE]))->addClass(ZBX_STYLE_TOTALS_LIST_COUNT), _('Not available') 63 ]))->addClass(ZBX_STYLE_HOST_AVAIL_FALSE)); 64 65 $table->addItem((new CDiv([ 66 (new CSpan($counts[INTERFACE_AVAILABLE_UNKNOWN]))->addClass(ZBX_STYLE_TOTALS_LIST_COUNT), _('Unknown') 67 ]))->addClass(ZBX_STYLE_HOST_AVAIL_UNKNOWN)); 68 69 $table->addItem((new CDiv([ 70 (new CSpan($data['hosts_total'][$data['hosts_types'][0]]))->addClass(ZBX_STYLE_TOTALS_LIST_COUNT), _('Total') 71 ]))->addClass(ZBX_STYLE_HOST_AVAIL_TOTAL)); 72} 73else { 74 $table = (new CTableInfo) 75 ->setHeader($header[$data['layout']]) 76 ->setHeadingColumn(0) 77 ->addClass(ZBX_STYLE_HOST_AVAIL_WIDGET); 78 79 foreach ($type_field_names as $key => $value) { 80 if (in_array($key, $data['hosts_types'])) { 81 $counts = $data['hosts_count'][$key]; 82 83 $available_row = (new CCol($counts[INTERFACE_AVAILABLE_TRUE]))->addClass(ZBX_STYLE_HOST_AVAIL_TRUE); 84 $not_available_row = (new CCol($counts[INTERFACE_AVAILABLE_FALSE]))->addClass(ZBX_STYLE_HOST_AVAIL_FALSE); 85 $unknown_row = (new CCol($counts[INTERFACE_AVAILABLE_UNKNOWN]))->addClass(ZBX_STYLE_HOST_AVAIL_UNKNOWN); 86 $total_row = (new CCol($data['hosts_total'][$key]))->addClass(ZBX_STYLE_HOST_AVAIL_TOTAL); 87 88 if ($data['layout'] == STYLE_HORIZONTAL) { 89 $table->addRow([$value, $available_row, $not_available_row, $unknown_row, $total_row]); 90 } 91 else { 92 $rows[INTERFACE_AVAILABLE_TRUE][] = $available_row; 93 $rows[INTERFACE_AVAILABLE_FALSE][] = $not_available_row; 94 $rows[INTERFACE_AVAILABLE_UNKNOWN][] = $unknown_row; 95 $rows['hosts_total'][] = $total_row; 96 } 97 } 98 } 99 100 if ($data['layout'] == STYLE_VERTICAL) { 101 $table 102 ->addRow(array_merge([_('Available')], $rows[INTERFACE_AVAILABLE_TRUE])) 103 ->addRow(array_merge([_('Not available')], $rows[INTERFACE_AVAILABLE_FALSE])) 104 ->addRow(array_merge([_('Unknown')], $rows[INTERFACE_AVAILABLE_UNKNOWN])) 105 ->addRow(array_merge([_('Total')], $rows['hosts_total'])); 106 } 107} 108 109$output = [ 110 'name' => $data['name'], 111 'body' => $table->toString() 112]; 113 114if (($messages = getMessages()) !== null) { 115 $output['messages'] = $messages->toString(); 116} 117 118if ($data['user']['debug_mode'] == GROUP_DEBUG_MODE_ENABLED) { 119 CProfiler::getInstance()->stop(); 120 $output['debug'] = CProfiler::getInstance()->make()->toString(); 121} 122 123echo json_encode($output); 124