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$this->addJsFile('layout.mode.js'); 23$web_layout_mode = CView::getLayoutMode(); 24 25$widget = (new CWidget()) 26 ->setTitle(_('Service availability report').': '.$data['service']['name']) 27 ->setWebLayoutMode($web_layout_mode); 28 29$controls = (new CList()) 30 ->addItem([ 31 new CLabel(_('Period'), 'period'), 32 (new CDiv())->addClass(ZBX_STYLE_FORM_INPUT_MARGIN), 33 new CComboBox('period', $data['period'], 'submit()', [ 34 'daily' => _('Daily'), 35 'weekly' => _('Weekly'), 36 'monthly' => _('Monthly'), 37 'yearly' => _('Yearly') 38 ]) 39 ]); 40 41if ($data['period'] != 'yearly') { 42 $years = []; 43 for ($y = (date('Y') - $data['YEAR_LEFT_SHIFT']); $y <= date('Y'); $y++) { 44 $years[$y] = $y; 45 } 46 $controls->addItem([ 47 new CLabel(_('Year'), 'year'), 48 (new CDiv())->addClass(ZBX_STYLE_FORM_INPUT_MARGIN), 49 new CComboBox('year', $data['year'], 'submit();', $years) 50 ]); 51} 52 53$widget->setControls(new CList([ 54 (new CForm()) 55 ->cleanItems() 56 ->setMethod('get') 57 ->addVar('action', 'report.services') 58 ->addVar('serviceid', $data['service']['serviceid']) 59 ->setAttribute('aria-label', _('Main filter')) 60 ->addItem($controls), 61 (new CTag('nav', true, get_icon('fullscreen'))) 62 ->setAttribute('aria-label', _('Content controls')) 63])); 64 65$header = [ 66 'yearly' => [_('Year'), null, _('Ok'), _('Problems'), _('Downtime'), _('SLA'), _('Acceptable SLA')], 67 'monthly' => [_('Month'), null, _('Ok'), _('Problems'), _('Downtime'), _('SLA'), _('Acceptable SLA')], 68 'weekly' => [_('From'), _('Till'), _('Ok'), _('Problems'), _('Downtime'), _('SLA'), _('Acceptable SLA')], 69 'daily' => [_('Day'), null, _('Ok'), _('Problems'), _('Downtime'), _('SLA'), _('Acceptable SLA')] 70]; 71 72// create table 73$table = (new CTableInfo())->setHeader($header[$data['period']]); 74 75order_result($data['sla']['sla'], 'from', ZBX_SORT_DOWN); 76 77foreach ($data['sla']['sla'] as $sla) { 78 switch ($data['period']) { 79 case 'yearly': 80 $from = zbx_date2str(_x('Y', DATE_FORMAT_CONTEXT), $sla['from']); 81 $to = null; 82 break; 83 84 case 'monthly': 85 $from = zbx_date2str(_x('F', DATE_FORMAT_CONTEXT), $sla['from']); 86 $to = null; 87 break; 88 89 case 'daily': 90 $from = zbx_date2str(DATE_FORMAT, $sla['from']); 91 $to = null; 92 break; 93 94 case 'weekly': 95 $from = zbx_date2str(DATE_TIME_FORMAT, $sla['from']); 96 $to = zbx_date2str(DATE_TIME_FORMAT, $sla['to']); 97 break; 98 } 99 100 $ok = ($sla['okTime'] != 0) 101 ? (new CSpan( 102 sprintf('%dd %dh %dm', 103 $sla['okTime'] / SEC_PER_DAY, 104 ($sla['okTime'] % SEC_PER_DAY) / SEC_PER_HOUR, 105 ($sla['okTime'] % SEC_PER_HOUR) / SEC_PER_MIN 106 ) 107 ))->addClass(ZBX_STYLE_GREEN) 108 : ''; 109 110 $problems = ($sla['problemTime'] != 0) 111 ? (new CSpan( 112 sprintf('%dd %dh %dm', 113 $sla['problemTime'] / SEC_PER_DAY, 114 ($sla['problemTime'] % SEC_PER_DAY) / SEC_PER_HOUR, 115 ($sla['problemTime'] % SEC_PER_HOUR) /SEC_PER_MIN 116 ) 117 ))->addClass(ZBX_STYLE_RED) 118 : ''; 119 120 $downtime = ($sla['downtimeTime'] != 0) 121 ? (new CSpan( 122 sprintf('%dd %dh %dm', 123 $sla['downtimeTime'] / SEC_PER_DAY, 124 ($sla['downtimeTime'] % SEC_PER_DAY) / SEC_PER_HOUR, 125 ($sla['downtimeTime'] % SEC_PER_HOUR) / SEC_PER_MIN 126 ) 127 ))->addClass(ZBX_STYLE_GREY) 128 : ''; 129 130 $percentage = $data['service']['showsla'] 131 ? (new CSpan(sprintf('%2.4f', $sla['sla']))) 132 ->addClass($sla['sla'] >= $data['service']['goodsla'] ? ZBX_STYLE_GREEN : ZBX_STYLE_RED) 133 : ''; 134 135 $goodsla = $data['service']['showsla'] ? $data['service']['goodsla'] : ''; 136 137 $table->addRow([$from, $to, $ok, $problems, $downtime, $percentage, $goodsla]); 138} 139 140$widget 141 ->addItem($table) 142 ->show(); 143