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
|
<?php declare(strict_types = 1);
/*
** Zabbix
** Copyright (C) 2001-2021 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 CControllerHostView extends CControllerHost {
protected function init(): void {
$this->disableSIDValidation();
}
protected function checkInput(): bool {
$fields = [
'name' => 'string',
'groupids' => 'array_id',
'ip' => 'string',
'dns' => 'string',
'port' => 'string',
'status' => 'in -1,'.HOST_STATUS_MONITORED.','.HOST_STATUS_NOT_MONITORED,
'evaltype' => 'in '.TAG_EVAL_TYPE_AND_OR.','.TAG_EVAL_TYPE_OR,
'tags' => 'array',
'severities' => 'array',
'show_suppressed' => 'in '.ZBX_PROBLEM_SUPPRESSED_FALSE.','.ZBX_PROBLEM_SUPPRESSED_TRUE,
'maintenance_status' => 'in '.HOST_MAINTENANCE_STATUS_OFF.','.HOST_MAINTENANCE_STATUS_ON,
'sort' => 'in name,status',
'sortorder' => 'in '.ZBX_SORT_UP.','.ZBX_SORT_DOWN,
'page' => 'ge 1',
'filter_name' => 'string',
'filter_custom_time' => 'in 1,0',
'filter_show_counter' => 'in 1,0',
'filter_counters' => 'in 1',
'filter_reset' => 'in 1',
'counter_index' => 'ge 0'
];
$ret = $this->validateInput($fields);
// Validate tags filter.
if ($ret && $this->hasInput('tags')) {
foreach ($this->getInput('tags') as $filter_tag) {
if (!is_array($filter_tag)
|| count($filter_tag) != 3
|| !array_key_exists('tag', $filter_tag) || !is_string($filter_tag['tag'])
|| !array_key_exists('value', $filter_tag) || !is_string($filter_tag['value'])
|| !array_key_exists('operator', $filter_tag) || !is_string($filter_tag['operator'])) {
$ret = false;
break;
}
}
}
// Validate severity checkbox filter.
if ($ret && $this->hasInput('severities')) {
$ret = !array_diff($this->getInput('severities'),
range(TRIGGER_SEVERITY_NOT_CLASSIFIED, TRIGGER_SEVERITY_COUNT - 1)
);
}
if (!$ret) {
$this->setResponse(new CControllerResponseFatal());
}
return $ret;
}
protected function checkPermissions(): bool {
return $this->checkAccess(CRoleHelper::UI_MONITORING_HOSTS);
}
protected function doAction(): void {
$filter_tabs = [];
$profile = (new CTabFilterProfile(static::FILTER_IDX, static::FILTER_FIELDS_DEFAULT))
->read()
->setInput($this->cleanInput($this->getInputAll()));
foreach ($profile->getTabsWithDefaults() as $index => $filter_tab) {
if ($index == $profile->selected) {
// Initialize multiselect data for filter_scr to allow tabfilter correctly handle unsaved state.
$filter_tab['filter_src']['filter_view_data'] = $this->getAdditionalData($filter_tab['filter_src']);
}
$filter_tabs[] = $filter_tab + ['filter_view_data' => $this->getAdditionalData($filter_tab)];
}
$filter = $filter_tabs[$profile->selected];
$refresh_curl = new CUrl('zabbix.php');
$filter['action'] = 'host.view.refresh';
array_map([$refresh_curl, 'setArgument'], array_keys($filter), $filter);
$data = [
'refresh_url' => $refresh_curl->getUrl(),
'refresh_interval' => CWebUser::getRefresh() * 1000,
'filter_view' => 'monitoring.host.filter',
'filter_defaults' => $profile->filter_defaults,
'filter_tabs' => $filter_tabs,
'tabfilter_options' => [
'idx' => static::FILTER_IDX,
'selected' => $profile->selected,
'support_custom_time' => 0,
'expanded' => $profile->expanded,
'page' => $filter['page']
]
] + $this->getData($filter);
$response = new CControllerResponseData($data);
$response->setTitle(_('Hosts'));
$this->setResponse($response);
}
}
|