-
-
Notifications
You must be signed in to change notification settings - Fork 405
/
rrdcheck.php
307 lines (262 loc) · 9.57 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
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
<?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);
/* ================= input validation and session storage ================= */
$filters = array(
'rows' => array(
'filter' => FILTER_VALIDATE_INT,
'pageset' => true,
'default' => '-1'
),
'page' => array(
'filter' => FILTER_VALIDATE_INT,
'default' => '1'
),
'filter' => array(
'filter' => FILTER_DEFAULT,
'pageset' => true,
'default' => ''
),
'sort_column' => array(
'filter' => FILTER_CALLBACK,
'default' => 'test_date',
'options' => array('options' => 'sanitize_search_string')
),
'sort_direction' => array(
'filter' => FILTER_CALLBACK,
'default' => 'ASC',
'options' => array('options' => 'sanitize_search_string')
),
'age' => array(
'filter' => FILTER_VALIDATE_INT,
'pageset' => true,
'default' => '0'
)
);
validate_store_request_vars($filters, 'sess_rrdc');
/* ================= input validation and session storage ================= */
if (get_request_var('rows') == '-1') {
$rows = read_config_option('num_rows_table');
} else {
$rows = get_request_var('rows');
}
html_start_box(__('RRDfile Checker'), '100%', '', '3', 'center', '');
filter();
html_end_box();
$sql_where = 'WHERE ';
/* form the 'where' clause for our main sql query */
$secsback = get_request_var('age');
if (get_request_var('age') == 0) {
$sql_where .= " test_date>='" . date('Y-m-d H:i:s', time() - (7200)) . "'";
} else {
$sql_where .= " test_date<='" . date('Y-m-d H:i:s', (time() - $secsback)) . "'";
}
if (get_request_var('filter') != '') {
$sql_where .= ' AND (
message LIKE ' . db_qstr('%' . get_request_var('filter') . '%') . ')';
}
$total_rows = db_fetch_cell("SELECT COUNT(local_data_id)
FROM rrdcheck
$sql_where");
$sql_order = get_order_string();
$sql_limit = ' LIMIT ' . ($rows * (get_request_var('page') - 1)) . ',' . $rows;
$problems = db_fetch_assoc("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");
$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 $problem) {
form_alternate_row('line' . $problem['local_data_id'], true);
if ($problem['description'] == '') {
$problem['description'] = __('Deleted');
}
if ($problem['name_cache'] == '') {
$problem['name_cache'] = __('Deleted');
}
form_selectable_cell(filter_value($problem['description'], get_request_var('filter')), $problem['local_data_id']);
form_selectable_cell(filter_value($problem['name_cache'], get_request_var('filter')), $problem['local_data_id']);
form_selectable_cell(filter_value($problem['local_data_id'], get_request_var('filter')), $problem['local_data_id'], '', 'center');
form_selectable_cell(filter_value($problem['message'], get_request_var('filter')), $problem['local_data_id']);
form_selectable_cell($problem['test_date'], $problem['local_data_id'], '', 'right');
form_end_row();
}
} else {
print "<tr><td colspan='5'><em>" . __('No RRDcheck Problems Found') . "</em></td></tr>\n";
}
html_end_box(false);
if (cacti_sizeof($problems)) {
print $nav;
}
form_end();
/* restore original error handler */
restore_error_handler();
}
function filter() {
global $item_rows;
?>
<tr class='even'>
<td>
<form id='form_rrdcheck' method='get' action='rrdcheck.php'>
<table class='filterTable'>
<tr>
<td>
<?php print __('Search');?>
</td>
<td>
<input type='text' class='ui-state-default ui-corner-all' id='filter' size='25' value='<?php print html_escape_request_var('filter');?>'>
</td>
<td>
<?php print __('Age');?>
</td>
<td>
<select id='age' onChange='refreshForm()' data-defaultLabel='<?php print __('Age');?>'>
<option value='0' <?php print(get_request_var('age') == '0' ? ' selected':'');?>>< <?php print __('%d hours', 2);?></option>
<option value='14400' <?php print(get_request_var('age') == '14400' ? ' selected':'');?>>> <?php print __('%d hours', 4);?></option>
<option value='43200' <?php print(get_request_var('age') == '43200' ? ' selected':'');?>>> <?php print __('%d hours',12);?></option>
<option value='86400' <?php print(get_request_var('age') == '86400' ? ' selected':'');?>>> <?php print __('%d day', 1);?></option>
<option value='259200' <?php print(get_request_var('age') == '259200' ? ' selected':'');?>>> <?php print __('%d days', 3);?></option>
<option value='604800' <?php print(get_request_var('age') == '604800' ? ' selected':'');?>>> <?php print __('%d days', 5);?></option>
</select>
</td>
<td>
<?php print __('Messages');?>
</td>
<td>
<select id='rows' data-defaultLabel='<?php print __('Messages');?>'>
<option value='-1'<?php print(get_request_var('rows') == '-1' ? ' selected>':'>') . __('Default');?></option>
<?php
if (cacti_sizeof($item_rows)) {
foreach ($item_rows as $key => $value) {
print '<option value="' . $key . '"';
if (get_request_var('rows') == $key) {
print ' selected';
} print '>' . $value . "</option>\n";
}
}
?>
</select>
</td>
<td>
<span>
<input type='submit' class='ui-button ui-corner-all ui-widget' id='go' value='<?php print __x('filter: use', 'Go');?>'>
<input type='button' class='ui-button ui-corner-all ui-widget' id='clear' value='<?php print __x('filter: reset', 'Clear');?>'>
<input type='button' class='ui-button ui-corner-all ui-widget' id='purge' value='<?php print __x('filter: purge', 'Purge');?>'>
</span>
</td>
<td id='text'></td>
</tr>
</table>
</form>
<script type="text/javascript">
function refreshForm() {
strURL = 'rrdcheck.php?'+
'&filter='+$('#filter').val()+
'&age='+$('#age').val()+
'&rows='+$('#rows').val();
loadUrl({url:strURL});
}
$(function() {
$('#form_rrdcheck').submit(function() {
refreshForm();
return false;
});
$('#rows').change(function() {
refreshForm();
});
$('#clear').click(function() {
strURL = 'rrdcheck.php?&clear=1';
loadUrl({url:strURL});
});
$('#purge').click(function() {
strURL = 'rrdcheck.php?action=purge';
loadUrl({url:strURL});
});
});
</script>
</td>
</tr>
<?php
}