1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
|
<?php
/*
** Zabbix
** Copyright (C) 2001-2018 Zabbix SIA
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**/
$this->addJsFile('layout.mode.js');
$web_layout_mode = CView::getLayoutMode();
$widget = (new CWidget())
->setTitle(_('Service availability report').': '.$data['service']['name'])
->setWebLayoutMode($web_layout_mode);
$controls = (new CList())
->addItem([
new CLabel(_('Period'), 'period'),
(new CDiv())->addClass(ZBX_STYLE_FORM_INPUT_MARGIN),
new CComboBox('period', $data['period'], 'submit()', [
'daily' => _('Daily'),
'weekly' => _('Weekly'),
'monthly' => _('Monthly'),
'yearly' => _('Yearly')
])
]);
if ($data['period'] != 'yearly') {
$years = [];
for ($y = (date('Y') - $data['YEAR_LEFT_SHIFT']); $y <= date('Y'); $y++) {
$years[$y] = $y;
}
$controls->addItem([
new CLabel(_('Year'), 'year'),
(new CDiv())->addClass(ZBX_STYLE_FORM_INPUT_MARGIN),
new CComboBox('year', $data['year'], 'submit();', $years)
]);
}
$widget->setControls(new CList([
(new CForm())
->cleanItems()
->setMethod('get')
->addVar('action', 'report.services')
->addVar('serviceid', $data['service']['serviceid'])
->setAttribute('aria-label', _('Main filter'))
->addItem($controls),
(new CTag('nav', true, get_icon('fullscreen')))
->setAttribute('aria-label', _('Content controls'))
]));
$header = [
'yearly' => [_('Year'), null, _('Ok'), _('Problems'), _('Downtime'), _('SLA'), _('Acceptable SLA')],
'monthly' => [_('Month'), null, _('Ok'), _('Problems'), _('Downtime'), _('SLA'), _('Acceptable SLA')],
'weekly' => [_('From'), _('Till'), _('Ok'), _('Problems'), _('Downtime'), _('SLA'), _('Acceptable SLA')],
'daily' => [_('Day'), null, _('Ok'), _('Problems'), _('Downtime'), _('SLA'), _('Acceptable SLA')]
];
// create table
$table = (new CTableInfo())->setHeader($header[$data['period']]);
order_result($data['sla']['sla'], 'from', ZBX_SORT_DOWN);
foreach ($data['sla']['sla'] as $sla) {
switch ($data['period']) {
case 'yearly':
$from = zbx_date2str(_x('Y', DATE_FORMAT_CONTEXT), $sla['from']);
$to = null;
break;
case 'monthly':
$from = zbx_date2str(_x('F', DATE_FORMAT_CONTEXT), $sla['from']);
$to = null;
break;
case 'daily':
$from = zbx_date2str(DATE_FORMAT, $sla['from']);
$to = null;
break;
case 'weekly':
$from = zbx_date2str(DATE_TIME_FORMAT, $sla['from']);
$to = zbx_date2str(DATE_TIME_FORMAT, $sla['to']);
break;
}
$ok = ($sla['okTime'] != 0)
? (new CSpan(
sprintf('%dd %dh %dm',
$sla['okTime'] / SEC_PER_DAY,
($sla['okTime'] % SEC_PER_DAY) / SEC_PER_HOUR,
($sla['okTime'] % SEC_PER_HOUR) / SEC_PER_MIN
)
))->addClass(ZBX_STYLE_GREEN)
: '';
$problems = ($sla['problemTime'] != 0)
? (new CSpan(
sprintf('%dd %dh %dm',
$sla['problemTime'] / SEC_PER_DAY,
($sla['problemTime'] % SEC_PER_DAY) / SEC_PER_HOUR,
($sla['problemTime'] % SEC_PER_HOUR) /SEC_PER_MIN
)
))->addClass(ZBX_STYLE_RED)
: '';
$downtime = ($sla['downtimeTime'] != 0)
? (new CSpan(
sprintf('%dd %dh %dm',
$sla['downtimeTime'] / SEC_PER_DAY,
($sla['downtimeTime'] % SEC_PER_DAY) / SEC_PER_HOUR,
($sla['downtimeTime'] % SEC_PER_HOUR) / SEC_PER_MIN
)
))->addClass(ZBX_STYLE_GREY)
: '';
$percentage = $data['service']['showsla']
? (new CSpan(sprintf('%2.4f', $sla['sla'])))
->addClass($sla['sla'] >= $data['service']['goodsla'] ? ZBX_STYLE_GREEN : ZBX_STYLE_RED)
: '';
$goodsla = $data['service']['showsla'] ? $data['service']['goodsla'] : '';
$table->addRow([$from, $to, $ok, $problems, $downtime, $percentage, $goodsla]);
}
$widget
->addItem($table)
->show();
|