-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCWidgetConfig.php
351 lines (308 loc) · 8.95 KB
/
CWidgetConfig.php
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
<?php
/*
** Zabbix
** Copyright (C) 2001-2020 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.
**/
class CWidgetConfig {
/**
* Return list of all widget types with names.
*
* @static
*
* @return array
*/
public static function getKnownWidgetTypes() {
return [
WIDGET_ACTION_LOG => _('Action log'),
WIDGET_CLOCK => _('Clock'),
WIDGET_DATA_OVER => _('Data overview'),
WIDGET_DISCOVERY => _('Discovery status'),
WIDGET_FAV_GRAPHS => _('Favourite graphs'),
WIDGET_FAV_MAPS => _('Favourite maps'),
WIDGET_FAV_SCREENS => _('Favourite screens'),
WIDGET_GRAPH => _('Graph (classic)'),
WIDGET_GRAPH_PROTOTYPE => _('Graph prototype'),
WIDGET_HOST_AVAIL => _('Host availability'),
WIDGET_MAP => _('Map'),
WIDGET_NAV_TREE => _('Map navigation tree'),
WIDGET_PLAIN_TEXT => _('Plain text'),
WIDGET_PROBLEM_HOSTS => _('Problem hosts'),
WIDGET_PROBLEMS => _('Problems'),
WIDGET_PROBLEMS_BY_SV => _('Problems by severity'),
WIDGET_PROBLEMS_TAGS => _('Problems by tags'), // New Widget
WIDGET_SVG_GRAPH => _('Graph'),
WIDGET_SYSTEM_INFO => _('System information'),
WIDGET_TRIG_OVER => _('Trigger overview'),
WIDGET_URL => _('URL'),
WIDGET_WEB => _('Web monitoring')
];
}
/**
* Get default widget dimensions.
*
* @static
*
* @return array
*/
private static function getDefaultDimensions() {
return [
WIDGET_ACTION_LOG => ['width' => 12, 'height' => 5],
WIDGET_CLOCK => ['width' => 4, 'height' => 3],
WIDGET_DATA_OVER => ['width' => 12, 'height' => 5],
WIDGET_DISCOVERY => ['width' => 6, 'height' => 3],
WIDGET_FAV_GRAPHS => ['width' => 4, 'height' => 3],
WIDGET_FAV_MAPS => ['width' => 4, 'height' => 3],
WIDGET_FAV_SCREENS => ['width' => 4, 'height' => 3],
WIDGET_GRAPH => ['width' => 12, 'height' => 5],
WIDGET_GRAPH_PROTOTYPE => ['width' => 16, 'height' => 5],
WIDGET_HOST_AVAIL => ['width' => 6, 'height' => 3],
WIDGET_MAP => ['width' => 18, 'height' => 5],
WIDGET_NAV_TREE => ['width' => 6, 'height' => 5],
WIDGET_PLAIN_TEXT => ['width' => 6, 'height' => 3],
WIDGET_PROBLEM_HOSTS => ['width' => 12, 'height' => 5],
WIDGET_PROBLEMS => ['width' => 12, 'height' => 5],
WIDGET_PROBLEMS_BY_SV => ['width' => 12, 'height' => 5],
WIDGET_PROBLEMS_TAGS => ['width' => 12, 'height' => 5], // New Widget
WIDGET_SVG_GRAPH => ['width' => 12, 'height' => 5],
WIDGET_SYSTEM_INFO => ['width' => 12, 'height' => 5],
WIDGET_TRIG_OVER => ['width' => 12, 'height' => 5],
WIDGET_URL => ['width' => 12, 'height' => 5],
WIDGET_WEB => ['width' => 6, 'height' => 3]
];
}
/**
* Return default values for widgets.
*
* @static
*
* @return array
*/
public static function getDefaults() {
$ret = [];
$dimensions = self::getDefaultDimensions();
foreach (self::getKnownWidgetTypes() as $type => $name) {
$ret[$type] = [
'header' => $name,
'size' => $dimensions[$type],
'iterator' => self::isIterator($type)
];
}
return $ret;
}
/**
* Return default refresh rate for widget type.
*
* @static
*
* @param int $type WIDGET_ constant
*
* @return int default refresh rate, "0" for no refresh
*/
public static function getDefaultRfRate($type) {
switch ($type) {
case WIDGET_ACTION_LOG:
case WIDGET_DATA_OVER:
case WIDGET_DISCOVERY:
case WIDGET_GRAPH:
case WIDGET_GRAPH_PROTOTYPE:
case WIDGET_PLAIN_TEXT:
case WIDGET_PROBLEM_HOSTS:
case WIDGET_PROBLEMS:
case WIDGET_PROBLEMS_BY_SV:
case WIDGET_PROBLEMS_TAGS: // New Widget
case WIDGET_SVG_GRAPH:
case WIDGET_TRIG_OVER:
case WIDGET_WEB:
return SEC_PER_MIN;
case WIDGET_CLOCK:
case WIDGET_FAV_GRAPHS:
case WIDGET_FAV_MAPS:
case WIDGET_FAV_SCREENS:
case WIDGET_HOST_AVAIL:
case WIDGET_MAP:
case WIDGET_NAV_TREE:
case WIDGET_SYSTEM_INFO:
return 15 * SEC_PER_MIN;
case WIDGET_URL:
return 0;
}
}
/**
* Get all possible widget refresh intervals.
*
* @return array
*/
public static function getRfRates() {
return [
0 => _('No refresh'),
SEC_PER_MIN / 6 => _n('%1$s second', '%1$s seconds', 10),
SEC_PER_MIN / 2 => _n('%1$s second', '%1$s seconds', 30),
SEC_PER_MIN => _n('%1$s minute', '%1$s minutes', 1),
SEC_PER_MIN * 2 => _n('%1$s minute', '%1$s minutes', 2),
SEC_PER_MIN * 10 => _n('%1$s minute', '%1$s minutes', 10),
SEC_PER_MIN * 15 => _n('%1$s minute', '%1$s minutes', 15)
];
}
/**
* Detect if widget uses time selector.
*
* @static
*
* @param array $widget
* @param array $widget[type]
* @param array $widget[fields]
*
* @return bool
*/
public static function usesTimeSelector(array $widget) {
switch ($widget['type']) {
case WIDGET_GRAPH:
case WIDGET_GRAPH_PROTOTYPE:
return true;
case WIDGET_SVG_GRAPH:
return !CWidgetFormSvgGraph::hasOverrideTime($widget['fields']);
default:
return false;
}
}
public static function isIterator($type) {
switch ($type) {
case WIDGET_GRAPH_PROTOTYPE:
return true;
default:
return false;
}
}
/**
* Detect if widget dialogue should be sticked to top instead of being centered vertically.
*
* @param string $type Widget type
*
* @return bool
*/
public static function getDialogueStickToTop($type) {
switch ($type) {
case WIDGET_SVG_GRAPH:
return true;
default:
return false;
}
}
/**
* Detect if widget has padding or not
*
* @static
*
* @param string $type Widget type
* @param array $fields Widget form fields
* @param int $view_mode Widget view mode. ZBX_WIDGET_VIEW_MODE_NORMAL by default
*
* @return bool
*/
private static function hasPadding($type, $fields, $view_mode) {
if ($view_mode == ZBX_WIDGET_VIEW_MODE_HIDDEN_HEADER) {
switch ($type) {
case WIDGET_CLOCK:
case WIDGET_GRAPH:
case WIDGET_MAP:
case WIDGET_SVG_GRAPH:
return true;
default:
return false;
}
}
else {
switch ($type) {
case WIDGET_HOST_AVAIL:
return (count($fields['interface_type']) != 1);
case WIDGET_PROBLEMS_BY_SV:
return $fields['show_type'] != WIDGET_PROBLEMS_BY_SV_SHOW_TOTALS;
case WIDGET_PROBLEMS_TAGS:
return $fields['show_type'] != WIDGET_PROBLEMS_TAGS_SHOW_TOTALS; // New Widget
case WIDGET_GRAPH_PROTOTYPE:
case WIDGET_URL:
return false;
default:
return true;
}
}
}
/**
* Get widget configuration based on widget type, fields and current view mode.
*
* @param string $type Widget type
* @param array $fields Widget form fields
* @param int $view_mode Widget view mode
*
* @return array
*/
public static function getConfiguration($type, $fields, $view_mode) {
return [
'padding' => self::hasPadding($type, $fields, $view_mode)
];
}
/**
* Return Form object for widget with provided data.
*
* @static
*
* @param string $type Widget type - 'WIDGET_' constant.
* @param string $data JSON string with widget fields.
*
* @return CWidgetForm
*/
public static function getForm($type, $data) {
switch ($type) {
case WIDGET_ACTION_LOG:
return new CWidgetFormActionLog($data);
case WIDGET_CLOCK:
return new CWidgetFormClock($data);
case WIDGET_DATA_OVER:
return new CWidgetFormDataOver($data);
case WIDGET_GRAPH:
return new CWidgetFormGraph($data);
case WIDGET_GRAPH_PROTOTYPE:
return new CWidgetFormGraphPrototype($data);
case WIDGET_HOST_AVAIL:
return new CWidgetFormHostAvail($data);
case WIDGET_MAP:
return new CWidgetFormMap($data);
case WIDGET_NAV_TREE:
return new CWidgetFormNavTree($data);
case WIDGET_PLAIN_TEXT:
return new CWidgetFormPlainText($data);
case WIDGET_PROBLEM_HOSTS:
return new CWidgetFormProblemHosts($data);
case WIDGET_PROBLEMS:
return new CWidgetFormProblems($data);
case WIDGET_PROBLEMS_BY_SV:
return new CWidgetFormProblemsBySv($data);
case WIDGET_PROBLEMS_TAGS:
return new CWidgetFormProblemsTags($data); // New Widget
case WIDGET_SVG_GRAPH:
return new CWidgetFormSvgGraph($data);
case WIDGET_TRIG_OVER:
return new CWidgetFormTrigOver($data);
case WIDGET_URL:
return new CWidgetFormUrl($data);
case WIDGET_WEB:
return new CWidgetFormWeb($data);
default:
return new CWidgetForm($data, $type);
}
}
}