-
-
Notifications
You must be signed in to change notification settings - Fork 404
/
Copy pathrrdcheck.php
283 lines (238 loc) · 8.29 KB
/
rrdcheck.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
<?php
/*
+-------------------------------------------------------------------------+
| Copyright (C) 2004-2024 The Cacti Group |
| |
| 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. |
+-------------------------------------------------------------------------+
| Cacti: The Complete RRDtool-based Graphing Solution |
+-------------------------------------------------------------------------+
| This code is designed, written, and maintained by the Cacti Group. See |
| about.php and/or the AUTHORS file for specific developer information. |
+-------------------------------------------------------------------------+
| http://www.cacti.net/ |
+-------------------------------------------------------------------------+
*/
include_once('./include/auth.php');
include_once(CACTI_PATH_LIBRARY . '/functions.php');
$rra_path = CACTI_PATH_RRA . '/';
top_header();
set_default_action();
if (read_config_option('rrdcheck_enable') != 'on') {
html_start_box(__('RRD check'), '100%', '', '3', 'center', '');
print __('RRD check is disabled, please enable in Configuration -> Settings -> Data');
html_end_box();
}
switch(get_request_var('action')) {
case 'purge':
rrdcheck_purge();
default:
rrdcheck_display_problems();
}
bottom_footer();
function rrdcheck_purge() {
db_execute('TRUNCATE TABLE rrdcheck');
}
/*
* Display all rrdcheck entries
*/
function rrdcheck_display_problems() {
global $config, $item_rows;
/* suppress warnings */
error_reporting(0);
process_sanitize_draw_filter(true);
if (get_request_var('rows') == '-1') {
$rows = read_config_option('num_rows_table');
} else {
$rows = get_request_var('rows');
}
$sql_where = '';
$sql_params = array();
$secsback = get_request_var('age');
if (get_request_var('age') == 0) {
$sql_where .= ($sql_where != '' ? ' AND ':'WHERE ') . 'test_date >= ?';
$sql_params[] = date('Y-m-d H:i:s', time() - (7200));
} else {
$sql_where .= ($sql_where != '' ? ' AND ':'WHERE ') . 'test_date <= ?';
$sql_params[] = date('Y-m-d H:i:s', (time() - $secsback));
}
if (get_request_var('filter') != '') {
$sql_where .= ($sql_where != '' ? ' AND ':'WHERE ') .
'(message LIKE ? OR h.description LIKE ? OR dtd.name_cache LIKE ? OR dtd.local_data_id LIKE ?)';
$sql_params[] = '%' . get_request_var('filter') . '%';
$sql_params[] = '%' . get_request_var('filter') . '%';
$sql_params[] = '%' . get_request_var('filter') . '%';
$sql_params[] = '%' . get_request_var('filter') . '%';
}
$total_rows = db_fetch_cell_prepared("SELECT COUNT(rc.local_data_id)
FROM rrdcheck AS rc
LEFT JOIN data_local AS dl
ON rc.local_data_id = dl.id
LEFT JOIN data_template_data AS dtd
ON rc.local_data_id = dtd.local_data_id
LEFT JOIN host AS h
ON dl.host_id = h.id
$sql_where",
$sql_params);
$sql_order = get_order_string();
$sql_limit = ' LIMIT ' . ($rows * (get_request_var('page') - 1)) . ',' . $rows;
$problems = db_fetch_assoc_prepared("SELECT h.description, dtd.name_cache,
rc.local_data_id, rc.test_date, rc.message
FROM rrdcheck AS rc
LEFT JOIN data_local AS dl
ON rc.local_data_id = dl.id
LEFT JOIN data_template_data AS dtd
ON rc.local_data_id = dtd.local_data_id
LEFT JOIN host AS h
ON dl.host_id = h.id
$sql_where
$sql_order
$sql_limit",
$sql_params);
$nav = html_nav_bar(CACTI_PATH_URL . 'rrdcheck.php?filter'. get_request_var('filter'), MAX_DISPLAY_PAGES, get_request_var('page'), $rows, $total_rows, 8, __('RRDcheck Problems'), 'page', 'main');
form_start('rrdcheck.php');
print $nav;
html_start_box('', '100%', '', '3', 'center', '');
$display_text = array(
'description' => array(
'display' => __('Host Description'),
'sort' => 'ASC'
),
'name_cache' => array(
'display' => __('Data Source'),
'sort' => 'ASC'
),
'local_data_id' => array(
'display' => __('Local Data ID'),
'align' => 'center',
'sort' => 'ASC'
),
'message' => array(
'display' => __('Message'),
'sort' => 'ASC'
),
'test_date' => array(
'display' => __('Date'),
'align' => 'right',
'sort' => 'DESC'
),
);
html_header_sort($display_text, get_request_var('sort_column'), get_request_var('sort_direction'), false);
if (cacti_sizeof($problems)) {
foreach ($problems as $p) {
form_alternate_row('line' . $p['local_data_id'], true);
if ($p['description'] == '') {
$p['description'] = __('Deleted');
}
if ($p['name_cache'] == '') {
$p['name_cache'] = __('Deleted');
}
form_selectable_cell(filter_value($p['description'], get_request_var('filter')), $p['local_data_id']);
form_selectable_cell(filter_value($p['name_cache'], get_request_var('filter')), $p['local_data_id']);
form_selectable_cell(filter_value($p['local_data_id'], get_request_var('filter')), $p['local_data_id'], '', 'center');
form_selectable_cell(filter_value($p['message'], get_request_var('filter')), $p['local_data_id']);
form_selectable_cell($p['test_date'], $p['local_data_id'], '', 'right');
form_end_row();
}
} else {
print '<tr class="tableRow odd"><td colspan="5"><em>' . __('No RRDcheck Problems Found') . '</em></td></tr>';
}
html_end_box(false);
if (cacti_sizeof($problems)) {
print $nav;
}
form_end();
/* restore original error handler */
restore_error_handler();
}
function create_filter() {
global $item_rows, $page_refresh_interval;
$all = array('-1' => __('All'));
$any = array('-1' => __('Any'));
$none = array('0' => __('None'));
$ages = array(
'0' => '< ' . __('%d hours', 2),
'14400' => '> ' . __('%d hours', 4),
'43200' => '> ' . __('%d hours',12),
'86400' => '> ' . __('%d day', 1),
'259200' => '> ' . __('%d days', 3),
'604800' => '> ' . __('%d days', 5)
);
return array(
'rows' => array(
array(
'filter' => array(
'method' => 'textbox',
'friendly_name' => __('Search'),
'filter' => FILTER_DEFAULT,
'placeholder' => __('Enter a search term'),
'size' => '30',
'default' => '',
'pageset' => true,
'max_length' => '120',
'value' => ''
),
'age' => array(
'method' => 'drop_array',
'friendly_name' => __('Age'),
'filter' => FILTER_VALIDATE_INT,
'default' => '0',
'pageset' => true,
'array' => $ages,
'value' => '0'
),
'rows' => array(
'method' => 'drop_array',
'friendly_name' => __('Attempts'),
'filter' => FILTER_VALIDATE_INT,
'default' => '-1',
'pageset' => true,
'array' => $item_rows,
'value' => '-1'
)
)
),
'buttons' => array(
'go' => array(
'method' => 'submit',
'display' => __('Go'),
'title' => __('Apply filter to table'),
),
'clear' => array(
'method' => 'button',
'display' => __('Clear'),
'title' => __('Reset filter to default values'),
),
'purge' => array(
'method' => 'button',
'display' => __('Purge'),
'action' => 'default',
'title' => __('Purge Data Source Checks from the Database'),
)
),
'sort' => array(
'sort_column' => 'test_date',
'sort_direction' => 'DESC'
)
);
}
function process_sanitize_draw_filter($render = false) {
$filters = create_filter();
/* create the page filter */
$pageFilter = new CactiTableFilter(__('RRDfile Checker'), 'rrdcheck.php', 'form_rrdcheck', 'sess_rrdc');
$pageFilter->rows_label = __('Data Sources');
$pageFilter->set_filter_array($filters);
if ($render) {
$pageFilter->render();
} else {
$pageFilter->sanitize();
}
}