commit | author | age
|
0d0cd9
|
1 |
<?php |
dead5c
|
2 |
|
0d0cd9
|
3 |
/* |
dead5c
|
4 |
Copyright (c) 2007-2011, Till Brehm, projektfarm Gmbh and Oliver Vogel www.muv.com |
V |
5 |
All rights reserved. |
0d0cd9
|
6 |
|
dead5c
|
7 |
Redistribution and use in source and binary forms, with or without modification, |
V |
8 |
are permitted provided that the following conditions are met: |
0d0cd9
|
9 |
|
dead5c
|
10 |
* Redistributions of source code must retain the above copyright notice, |
V |
11 |
this list of conditions and the following disclaimer. |
|
12 |
* Redistributions in binary form must reproduce the above copyright notice, |
|
13 |
this list of conditions and the following disclaimer in the documentation |
|
14 |
and/or other materials provided with the distribution. |
|
15 |
* Neither the name of ISPConfig nor the names of its contributors |
|
16 |
may be used to endorse or promote products derived from this software without |
|
17 |
specific prior written permission. |
0d0cd9
|
18 |
|
dead5c
|
19 |
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
V |
20 |
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|
21 |
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
|
22 |
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, |
|
23 |
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
|
24 |
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
25 |
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
|
26 |
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
|
27 |
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, |
|
28 |
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
29 |
*/ |
436ed8
|
30 |
|
0d0cd9
|
31 |
class monitor_core_module { |
V |
32 |
|
dead5c
|
33 |
var $interval = 5; // do the monitoring every 5 minutes |
220bb9
|
34 |
var $module_name = 'monitor_core_module'; |
V |
35 |
var $class_name = 'monitor_core_module'; |
|
36 |
/* No actions at this time. maybe later... */ |
|
37 |
var $actions_available = array(); |
51cf60
|
38 |
/** The Tools */ |
7fe908
|
39 |
|
MC |
40 |
|
dead5c
|
41 |
private $_tools = null; |
7fe908
|
42 |
//** time the script was called |
MC |
43 |
private $_run_time = null; |
bf47aa
|
44 |
|
dead5c
|
45 |
/** |
V |
46 |
* This function is called during ispconfig installation to determine |
|
47 |
* if a symlink shall be created for this plugin. |
|
48 |
*/ |
|
49 |
public function onInstall() { |
392450
|
50 |
global $conf; |
T |
51 |
return true; |
|
52 |
} |
220bb9
|
53 |
|
dead5c
|
54 |
/** |
V |
55 |
* This function is called when the module is loaded |
|
56 |
*/ |
|
57 |
public function onLoad() { |
220bb9
|
58 |
global $app; |
7fe908
|
59 |
|
MC |
60 |
//* store the running time |
|
61 |
$this->_run_time = time(); |
|
62 |
|
220bb9
|
63 |
/* |
dead5c
|
64 |
* Do the monitor every n minutes and write the result to the db |
V |
65 |
*/ |
615a0a
|
66 |
$min = @date('i', $this->_run_time); |
220bb9
|
67 |
if (($min % $this->interval) == 0) { |
dead5c
|
68 |
$this->_doMonitor(); |
220bb9
|
69 |
} |
V |
70 |
} |
8793b3
|
71 |
|
dead5c
|
72 |
/** |
V |
73 |
* This function is called when a change in one of the registered tables is detected. |
|
74 |
* The function then raises the events for the plugins. |
|
75 |
*/ |
|
76 |
public function process($tablename, $action, $data) { |
c9d97b
|
77 |
// not needed |
220bb9
|
78 |
} |
V |
79 |
|
dead5c
|
80 |
/** |
V |
81 |
* This method is called every n minutes, when the module ist loaded. |
|
82 |
* The method then does a system-monitoring |
|
83 |
*/ |
220bb9
|
84 |
// TODO: what monitoring is done should be a config-var |
dead5c
|
85 |
private function _doMonitor() { |
f63bda
|
86 |
global $app; |
dead5c
|
87 |
/* |
V |
88 |
* We need the tools in almost every method, so initialize them once... |
|
89 |
*/ |
|
90 |
$app->load('monitor_tools'); |
|
91 |
$this->_tools = new monitor_tools(); |
51cf60
|
92 |
|
dead5c
|
93 |
/* |
7fe908
|
94 |
* Calls the single Monitoring steps |
dead5c
|
95 |
*/ |
4a75ab
|
96 |
$this->_monitorEmailQuota(); |
dead5c
|
97 |
$this->_monitorHDQuota(); |
V |
98 |
$this->_monitorServer(); |
|
99 |
$this->_monitorOsVer(); |
|
100 |
$this->_monitorIspcVer(); |
|
101 |
$this->_monitorDiskUsage(); |
|
102 |
$this->_monitorMemUsage(); |
|
103 |
$this->_monitorCpu(); |
|
104 |
$this->_monitorServices(); |
|
105 |
if (@file_exists('/proc/user_beancounters')) { |
|
106 |
$this->_monitorOpenVzHost(); |
|
107 |
$this->_monitorOpenVzUserBeancounter(); |
|
108 |
} |
|
109 |
$this->_monitorMailLog(); |
|
110 |
$this->_monitorMailWarnLog(); |
|
111 |
$this->_monitorMailErrLog(); |
|
112 |
$this->_monitorMessagesLog(); |
|
113 |
$this->_monitorISPCCronLog(); |
|
114 |
$this->_monitorFreshClamLog(); |
|
115 |
$this->_monitorClamAvLog(); |
|
116 |
$this->_monitorIspConfigLog(); |
|
117 |
$this->_monitorSystemUpdate(); |
|
118 |
$this->_monitorMailQueue(); |
|
119 |
$this->_monitorRaid(); |
|
120 |
$this->_monitorRkHunter(); |
|
121 |
$this->_monitorFail2ban(); |
28548b
|
122 |
$this->_monitorIPTables(); |
dead5c
|
123 |
$this->_monitorSysLog(); |
504908
|
124 |
$this->_cleanupAPS(); |
dead5c
|
125 |
} |
8793b3
|
126 |
|
7fe908
|
127 |
private function _monitorEmailQuota() { |
MC |
128 |
global $app, $conf; |
7ee55f
|
129 |
|
7fe908
|
130 |
/* |
edf806
|
131 |
* This monitoring is expensive, so do it only every 15 minutes |
T |
132 |
*/ |
615a0a
|
133 |
$min = @date('i', $this->_run_time); |
edf806
|
134 |
if ($min % 15 != 0) return; |
7fe908
|
135 |
|
9db567
|
136 |
$app->uses('getconf'); |
T |
137 |
$mail_config = $app->getconf->get_server_config($conf['server_id'], 'mail'); |
|
138 |
if($mail_config['mailbox_quota_stats'] == 'n') return; |
7fe908
|
139 |
|
MC |
140 |
|
edf806
|
141 |
/* |
7ee55f
|
142 |
* First we get the Monitoring-data from the tools |
L |
143 |
*/ |
7fe908
|
144 |
$res = $this->_tools->monitorEmailQuota(); |
7ee55f
|
145 |
|
7fe908
|
146 |
/* |
7ee55f
|
147 |
* Insert the data into the database |
L |
148 |
*/ |
7fe908
|
149 |
$sql = 'REPLACE INTO monitor_data (server_id, type, created, data, state) ' . |
MC |
150 |
'VALUES (' . |
|
151 |
$res['server_id'] . ', ' . |
|
152 |
"'" . $app->dbmaster->quote($res['type']) . "', " . |
|
153 |
'UNIX_TIMESTAMP(), ' . |
|
154 |
"'" . $app->dbmaster->quote(serialize($res['data'])) . "', " . |
|
155 |
"'" . $res['state'] . "'" . |
|
156 |
')'; |
|
157 |
$app->dbmaster->query($sql); |
7ee55f
|
158 |
|
7fe908
|
159 |
/* The new data is written, now we can delete the old one */ |
MC |
160 |
$this->_delOldRecords($res['type'], $res['server_id']); |
|
161 |
} |
7ee55f
|
162 |
|
dead5c
|
163 |
private function _monitorHDQuota() { |
V |
164 |
global $app; |
446416
|
165 |
|
dead5c
|
166 |
/* |
V |
167 |
* First we get the Monitoring-data from the tools |
|
168 |
*/ |
|
169 |
$res = $this->_tools->monitorHDQuota(); |
51cf60
|
170 |
|
dead5c
|
171 |
/* |
V |
172 |
* Insert the data into the database |
|
173 |
*/ |
bfcdef
|
174 |
$sql = 'REPLACE INTO monitor_data (server_id, type, created, data, state) ' . |
7fe908
|
175 |
'VALUES (' . |
MC |
176 |
$res['server_id'] . ', ' . |
|
177 |
"'" . $app->dbmaster->quote($res['type']) . "', " . |
|
178 |
'UNIX_TIMESTAMP(), ' . |
|
179 |
"'" . $app->dbmaster->quote(serialize($res['data'])) . "', " . |
|
180 |
"'" . $res['state'] . "'" . |
|
181 |
')'; |
dead5c
|
182 |
$app->dbmaster->query($sql); |
446416
|
183 |
|
dead5c
|
184 |
/* The new data is written, now we can delete the old one */ |
fd5e71
|
185 |
$this->_delOldRecords($res['type'], $res['server_id']); |
dead5c
|
186 |
} |
V |
187 |
|
|
188 |
private function _monitorServer() { |
|
189 |
global $app; |
446416
|
190 |
|
T |
191 |
/* |
dead5c
|
192 |
* First we get the Monitoring-data from the tools |
V |
193 |
*/ |
|
194 |
$res = $this->_tools->monitorServer(); |
51cf60
|
195 |
|
446416
|
196 |
/* |
dead5c
|
197 |
* Insert the data into the database |
V |
198 |
*/ |
bfcdef
|
199 |
$sql = 'REPLACE INTO monitor_data (server_id, type, created, data, state) ' . |
7fe908
|
200 |
'VALUES (' . |
MC |
201 |
$res['server_id'] . ', ' . |
|
202 |
"'" . $app->dbmaster->quote($res['type']) . "', " . |
|
203 |
'UNIX_TIMESTAMP(), ' . |
|
204 |
"'" . $app->dbmaster->quote(serialize($res['data'])) . "', " . |
|
205 |
"'" . $res['state'] . "'" . |
|
206 |
')'; |
446416
|
207 |
$app->dbmaster->query($sql); |
T |
208 |
|
|
209 |
/* The new data is written, now we can delete the old one */ |
fd5e71
|
210 |
$this->_delOldRecords($res['type'], $res['server_id']); |
446416
|
211 |
} |
dead5c
|
212 |
|
V |
213 |
private function _monitorOsVer() { |
220bb9
|
214 |
global $app; |
8793b3
|
215 |
|
220bb9
|
216 |
/* |
dead5c
|
217 |
* First we get the Monitoring-data from the tools |
V |
218 |
*/ |
|
219 |
$res = $this->_tools->monitorOsVer(); |
51cf60
|
220 |
|
220bb9
|
221 |
/* |
dead5c
|
222 |
* Insert the data into the database |
V |
223 |
*/ |
bfcdef
|
224 |
$sql = 'REPLACE INTO monitor_data (server_id, type, created, data, state) ' . |
7fe908
|
225 |
'VALUES (' . |
MC |
226 |
$res['server_id'] . ', ' . |
|
227 |
"'" . $app->dbmaster->quote($res['type']) . "', " . |
|
228 |
'UNIX_TIMESTAMP(), ' . |
|
229 |
"'" . $app->dbmaster->quote(serialize($res['data'])) . "', " . |
|
230 |
"'" . $res['state'] . "'" . |
|
231 |
')'; |
220bb9
|
232 |
$app->dbmaster->query($sql); |
fb4c27
|
233 |
|
220bb9
|
234 |
/* The new data is written, now we can delete the old one */ |
fd5e71
|
235 |
$this->_delOldRecords($res['type'], $res['server_id']); |
220bb9
|
236 |
} |
8793b3
|
237 |
|
dead5c
|
238 |
private function _monitorIspcVer() { |
220bb9
|
239 |
global $app; |
8793b3
|
240 |
|
220bb9
|
241 |
/* |
dead5c
|
242 |
* First we get the Monitoring-data from the tools |
V |
243 |
*/ |
|
244 |
$res = $this->_tools->monitorIspcVer(); |
51cf60
|
245 |
|
220bb9
|
246 |
/* |
dead5c
|
247 |
* Insert the data into the database |
V |
248 |
*/ |
bfcdef
|
249 |
$sql = 'REPLACE INTO monitor_data (server_id, type, created, data, state) ' . |
7fe908
|
250 |
'VALUES (' . |
MC |
251 |
$res['server_id'] . ', ' . |
|
252 |
"'" . $app->dbmaster->quote($res['type']) . "', " . |
|
253 |
'UNIX_TIMESTAMP(), ' . |
|
254 |
"'" . $app->dbmaster->quote(serialize($res['data'])) . "', " . |
|
255 |
"'" . $res['state'] . "'" . |
|
256 |
')'; |
220bb9
|
257 |
$app->dbmaster->query($sql); |
V |
258 |
|
|
259 |
/* The new data is written, now we can delete the old one */ |
fd5e71
|
260 |
$this->_delOldRecords($res['type'], $res['server_id']); |
220bb9
|
261 |
} |
V |
262 |
|
dead5c
|
263 |
private function _monitorDiskUsage() { |
3bdfa3
|
264 |
global $app; |
V |
265 |
|
|
266 |
/* |
dead5c
|
267 |
* First we get the Monitoring-data from the tools |
V |
268 |
*/ |
|
269 |
$res = $this->_tools->monitorDiskUsage(); |
51cf60
|
270 |
|
3bdfa3
|
271 |
/* |
dead5c
|
272 |
* Insert the data into the database |
V |
273 |
*/ |
bfcdef
|
274 |
$sql = 'REPLACE INTO monitor_data (server_id, type, created, data, state) ' . |
7fe908
|
275 |
'VALUES (' . |
MC |
276 |
$res['server_id'] . ', ' . |
|
277 |
"'" . $app->dbmaster->quote($res['type']) . "', " . |
|
278 |
'UNIX_TIMESTAMP(), ' . |
|
279 |
"'" . $app->dbmaster->quote(serialize($res['data'])) . "', " . |
|
280 |
"'" . $res['state'] . "'" . |
|
281 |
')'; |
3bdfa3
|
282 |
$app->dbmaster->query($sql); |
V |
283 |
|
|
284 |
/* The new data is written, now we can delete the old one */ |
fd5e71
|
285 |
$this->_delOldRecords($res['type'], $res['server_id']); |
3bdfa3
|
286 |
} |
V |
287 |
|
dead5c
|
288 |
private function _monitorMemUsage() { |
220bb9
|
289 |
global $app; |
V |
290 |
/* |
dead5c
|
291 |
* First we get the Monitoring-data from the tools |
V |
292 |
*/ |
|
293 |
$res = $this->_tools->monitorMemUsage(); |
51cf60
|
294 |
|
220bb9
|
295 |
/* |
dead5c
|
296 |
* Insert the data into the database |
V |
297 |
*/ |
bfcdef
|
298 |
$sql = 'REPLACE INTO monitor_data (server_id, type, created, data, state) ' . |
7fe908
|
299 |
'VALUES (' . |
MC |
300 |
$res['server_id'] . ', ' . |
|
301 |
"'" . $app->dbmaster->quote($res['type']) . "', " . |
|
302 |
'UNIX_TIMESTAMP(), ' . |
|
303 |
"'" . $app->dbmaster->quote(serialize($res['data'])) . "', " . |
|
304 |
"'" . $res['state'] . "'" . |
|
305 |
')'; |
220bb9
|
306 |
$app->dbmaster->query($sql); |
fb4c27
|
307 |
|
220bb9
|
308 |
/* The new data is written, now we can delete the old one */ |
fd5e71
|
309 |
$this->_delOldRecords($res['type'], $res['server_id']); |
220bb9
|
310 |
} |
8793b3
|
311 |
|
dead5c
|
312 |
private function _monitorCpu() { |
220bb9
|
313 |
global $app; |
V |
314 |
/* |
dead5c
|
315 |
* First we get the Monitoring-data from the tools |
V |
316 |
*/ |
|
317 |
$res = $this->_tools->monitorCpu(); |
51cf60
|
318 |
|
220bb9
|
319 |
/* |
dead5c
|
320 |
* Insert the data into the database |
V |
321 |
*/ |
bfcdef
|
322 |
$sql = 'REPLACE INTO monitor_data (server_id, type, created, data, state) ' . |
7fe908
|
323 |
'VALUES (' . |
MC |
324 |
$res['server_id'] . ', ' . |
|
325 |
"'" . $app->dbmaster->quote($res['type']) . "', " . |
|
326 |
'UNIX_TIMESTAMP(), ' . |
|
327 |
"'" . $app->dbmaster->quote(serialize($res['data'])) . "', " . |
|
328 |
"'" . $res['state'] . "'" . |
|
329 |
')'; |
220bb9
|
330 |
$app->dbmaster->query($sql); |
fb4c27
|
331 |
|
220bb9
|
332 |
/* The new data is written, now we can delete the old one */ |
fd5e71
|
333 |
$this->_delOldRecords($res['type'], $res['server_id']); |
220bb9
|
334 |
} |
8793b3
|
335 |
|
dead5c
|
336 |
private function _monitorServices() { |
220bb9
|
337 |
global $app; |
51cf60
|
338 |
|
220bb9
|
339 |
/* |
dead5c
|
340 |
* First we get the Monitoring-data from the tools |
V |
341 |
*/ |
|
342 |
$res = $this->_tools->monitorServices(); |
51cf60
|
343 |
|
220bb9
|
344 |
/* |
dead5c
|
345 |
* Insert the data into the database |
V |
346 |
*/ |
bfcdef
|
347 |
$sql = 'REPLACE INTO monitor_data (server_id, type, created, data, state) ' . |
7fe908
|
348 |
'VALUES (' . |
MC |
349 |
$res['server_id'] . ', ' . |
|
350 |
"'" . $app->dbmaster->quote($res['type']) . "', " . |
|
351 |
'UNIX_TIMESTAMP(), ' . |
|
352 |
"'" . $app->dbmaster->quote(serialize($res['data'])) . "', " . |
|
353 |
"'" . $res['state'] . "'" . |
|
354 |
')'; |
220bb9
|
355 |
$app->dbmaster->query($sql); |
fb4c27
|
356 |
|
220bb9
|
357 |
/* The new data is written, now we can delete the old one */ |
fd5e71
|
358 |
$this->_delOldRecords($res['type'], $res['server_id']); |
220bb9
|
359 |
} |
8793b3
|
360 |
|
dead5c
|
361 |
private function _monitorOpenVzHost() { |
220bb9
|
362 |
global $app; |
51cf60
|
363 |
|
220bb9
|
364 |
/* |
dead5c
|
365 |
* First we get the Monitoring-data from the tools |
V |
366 |
*/ |
|
367 |
$res = $this->_tools->monitorOpenVzHost(); |
51cf60
|
368 |
|
dead5c
|
369 |
/* |
V |
370 |
* Insert the data into the database |
|
371 |
*/ |
bfcdef
|
372 |
$sql = 'REPLACE INTO monitor_data (server_id, type, created, data, state) ' . |
7fe908
|
373 |
'VALUES (' . |
MC |
374 |
$res['server_id'] . ', ' . |
|
375 |
"'" . $app->dbmaster->quote($res['type']) . "', " . |
|
376 |
'UNIX_TIMESTAMP(), ' . |
|
377 |
"'" . $app->dbmaster->quote(serialize($res['data'])) . "', " . |
|
378 |
"'" . $res['state'] . "'" . |
|
379 |
')'; |
220bb9
|
380 |
$app->dbmaster->query($sql); |
8793b3
|
381 |
|
220bb9
|
382 |
/* The new data is written, now we can delete the old one */ |
fd5e71
|
383 |
$this->_delOldRecords($res['type'], $res['server_id']); |
c9d97b
|
384 |
} |
V |
385 |
|
dead5c
|
386 |
private function _monitorOpenVzUserBeancounter() { |
c9d97b
|
387 |
global $app; |
51cf60
|
388 |
|
c9d97b
|
389 |
/* |
dead5c
|
390 |
* First we get the Monitoring-data from the tools |
V |
391 |
*/ |
|
392 |
$res = $this->_tools->monitorOpenVzUserBeancounter(); |
51cf60
|
393 |
|
c9d97b
|
394 |
/* |
dead5c
|
395 |
* Insert the data into the database |
V |
396 |
*/ |
bfcdef
|
397 |
$sql = 'REPLACE INTO monitor_data (server_id, type, created, data, state) ' . |
7fe908
|
398 |
'VALUES (' . |
MC |
399 |
$res['server_id'] . ', ' . |
|
400 |
"'" . $app->dbmaster->quote($res['type']) . "', " . |
|
401 |
'UNIX_TIMESTAMP(), ' . |
|
402 |
"'" . $app->dbmaster->quote(serialize($res['data'])) . "', " . |
|
403 |
"'" . $res['state'] . "'" . |
|
404 |
')'; |
c9d97b
|
405 |
$app->dbmaster->query($sql); |
V |
406 |
|
|
407 |
/* The new data is written, now we can delete the old one */ |
fd5e71
|
408 |
$this->_delOldRecords($res['type'], $res['server_id']); |
c9d97b
|
409 |
} |
V |
410 |
|
dead5c
|
411 |
private function _monitorSystemUpdate() { |
c9d97b
|
412 |
/* |
dead5c
|
413 |
* This monitoring is expensive, so do it only once an hour |
V |
414 |
*/ |
615a0a
|
415 |
$min = @date('i', $this->_run_time); |
dead5c
|
416 |
if ($min != 0) |
V |
417 |
return; |
716255
|
418 |
|
220bb9
|
419 |
/* |
dead5c
|
420 |
* OK - here we go... |
V |
421 |
*/ |
220bb9
|
422 |
global $app; |
82ff62
|
423 |
|
TB |
424 |
$app->uses('getconf'); |
|
425 |
$server_config = $app->getconf->get_server_config($conf['server_id'], 'server'); |
|
426 |
if($server_config['monitor_system_updates'] == 'n') return; |
51cf60
|
427 |
|
220bb9
|
428 |
/* |
dead5c
|
429 |
* First we get the Monitoring-data from the tools |
V |
430 |
*/ |
|
431 |
$res = $this->_tools->monitorSystemUpdate(); |
7fe908
|
432 |
|
edf806
|
433 |
//* Ensure that output is encoded so that it does not break the serialize |
615a0a
|
434 |
//$res['data']['output'] = htmlentities($res['data']['output']); |
7fe908
|
435 |
$res['data']['output'] = htmlentities($res['data']['output'], ENT_QUOTES, 'UTF-8'); |
51cf60
|
436 |
|
dead5c
|
437 |
/* |
V |
438 |
* Insert the data into the database |
|
439 |
*/ |
bfcdef
|
440 |
$sql = 'REPLACE INTO monitor_data (server_id, type, created, data, state) ' . |
7fe908
|
441 |
'VALUES (' . |
MC |
442 |
$res['server_id'] . ', ' . |
|
443 |
"'" . $app->dbmaster->quote($res['type']) . "', " . |
|
444 |
'UNIX_TIMESTAMP(), ' . |
|
445 |
"'" . $app->dbmaster->quote(serialize($res['data'])) . "', " . |
|
446 |
"'" . $res['state'] . "'" . |
|
447 |
')'; |
220bb9
|
448 |
$app->dbmaster->query($sql); |
fb4c27
|
449 |
|
220bb9
|
450 |
/* The new data is written, now we can delete the old one */ |
fd5e71
|
451 |
$this->_delOldRecords($res['type'], $res['server_id']); |
220bb9
|
452 |
} |
716255
|
453 |
|
dead5c
|
454 |
private function _monitorMailQueue() { |
220bb9
|
455 |
global $app; |
51cf60
|
456 |
|
220bb9
|
457 |
/* |
dead5c
|
458 |
* First we get the Monitoring-data from the tools |
V |
459 |
*/ |
|
460 |
$res = $this->_tools->monitorMailQueue(); |
51cf60
|
461 |
|
220bb9
|
462 |
/* |
dead5c
|
463 |
* Insert the data into the database |
V |
464 |
*/ |
bfcdef
|
465 |
$sql = 'REPLACE INTO monitor_data (server_id, type, created, data, state) ' . |
7fe908
|
466 |
'VALUES (' . |
MC |
467 |
$res['server_id'] . ', ' . |
|
468 |
"'" . $app->dbmaster->quote($res['type']) . "', " . |
|
469 |
'UNIX_TIMESTAMP(), ' . |
|
470 |
"'" . $app->dbmaster->quote(serialize($res['data'])) . "', " . |
|
471 |
"'" . $res['state'] . "'" . |
|
472 |
')'; |
220bb9
|
473 |
$app->dbmaster->query($sql); |
fb4c27
|
474 |
|
220bb9
|
475 |
/* The new data is written, now we can delete the old one */ |
fd5e71
|
476 |
$this->_delOldRecords($res['type'], $res['server_id']); |
220bb9
|
477 |
} |
716255
|
478 |
|
dead5c
|
479 |
private function _monitorRaid() { |
220bb9
|
480 |
global $app; |
51cf60
|
481 |
|
f62c63
|
482 |
/* |
dead5c
|
483 |
* First we get the Monitoring-data from the tools |
V |
484 |
*/ |
|
485 |
$res = $this->_tools->monitorRaid(); |
51cf60
|
486 |
|
f62c63
|
487 |
/* |
dead5c
|
488 |
* Insert the data into the database |
V |
489 |
*/ |
bfcdef
|
490 |
$sql = 'REPLACE INTO monitor_data (server_id, type, created, data, state) ' . |
7fe908
|
491 |
'VALUES (' . |
MC |
492 |
$res['server_id'] . ', ' . |
|
493 |
"'" . $app->dbmaster->quote($res['type']) . "', " . |
|
494 |
'UNIX_TIMESTAMP(), ' . |
|
495 |
"'" . $app->dbmaster->quote(serialize($res['data'])) . "', " . |
|
496 |
"'" . $res['state'] . "'" . |
|
497 |
')'; |
220bb9
|
498 |
$app->dbmaster->query($sql); |
fb4c27
|
499 |
|
220bb9
|
500 |
/* The new data is written, now we can delete the old one */ |
fd5e71
|
501 |
$this->_delOldRecords($res['type'], $res['server_id']); |
220bb9
|
502 |
} |
36d307
|
503 |
|
dead5c
|
504 |
private function _monitorRkHunter() { |
220bb9
|
505 |
/* |
dead5c
|
506 |
* This monitoring is expensive, so do it only once a day |
V |
507 |
*/ |
615a0a
|
508 |
$min = @date('i', $this->_run_time); |
T |
509 |
$hour = @date('H', $this->_run_time); |
dead5c
|
510 |
if (!($min == 0 && $hour == 23)) |
V |
511 |
return; |
220bb9
|
512 |
/* |
dead5c
|
513 |
* OK . here we go... |
V |
514 |
*/ |
|
515 |
global $app; |
51cf60
|
516 |
|
dead5c
|
517 |
/* |
V |
518 |
* First we get the Monitoring-data from the tools |
|
519 |
*/ |
|
520 |
$res = $this->_tools->monitorRkHunter(); |
51cf60
|
521 |
|
dead5c
|
522 |
/* |
V |
523 |
* Insert the data into the database |
|
524 |
*/ |
bfcdef
|
525 |
$sql = 'REPLACE INTO monitor_data (server_id, type, created, data, state) ' . |
7fe908
|
526 |
'VALUES (' . |
MC |
527 |
$res['server_id'] . ', ' . |
|
528 |
"'" . $app->dbmaster->quote($res['type']) . "', " . |
|
529 |
'UNIX_TIMESTAMP(), ' . |
|
530 |
"'" . $app->dbmaster->quote(serialize($res['data'])) . "', " . |
|
531 |
"'" . $res['state'] . "'" . |
|
532 |
')'; |
220bb9
|
533 |
$app->dbmaster->query($sql); |
fb4c27
|
534 |
|
220bb9
|
535 |
/* The new data is written, now we can delete the old one */ |
fd5e71
|
536 |
$this->_delOldRecords($res['type'], $res['server_id']); |
220bb9
|
537 |
} |
8793b3
|
538 |
|
dead5c
|
539 |
private function _monitorFail2ban() { |
7fe908
|
540 |
global $app; |
28548b
|
541 |
|
7fe908
|
542 |
/* |
28548b
|
543 |
* First we get the Monitoring-data from the tools |
L |
544 |
*/ |
7fe908
|
545 |
$res = $this->_tools->monitorFail2ban(); |
28548b
|
546 |
|
7fe908
|
547 |
/* |
28548b
|
548 |
* Insert the data into the database |
L |
549 |
*/ |
7fe908
|
550 |
$sql = 'REPLACE INTO monitor_data (server_id, type, created, data, state) ' . |
MC |
551 |
'VALUES (' . |
|
552 |
$res['server_id'] . ', ' . |
|
553 |
"'" . $app->dbmaster->quote($res['type']) . "', " . |
|
554 |
'UNIX_TIMESTAMP(), ' . |
|
555 |
"'" . $app->dbmaster->quote(serialize($res['data'])) . "', " . |
|
556 |
"'" . $res['state'] . "'" . |
|
557 |
')'; |
|
558 |
$app->dbmaster->query($sql); |
28548b
|
559 |
|
7fe908
|
560 |
/* The new data is written, now we can delete the old one */ |
MC |
561 |
$this->_delOldRecords($res['type'], $res['server_id']); |
|
562 |
} |
28548b
|
563 |
|
L |
564 |
|
|
565 |
private function _monitorIPTables() { |
220bb9
|
566 |
global $app; |
51cf60
|
567 |
|
220bb9
|
568 |
/* |
dead5c
|
569 |
* First we get the Monitoring-data from the tools |
V |
570 |
*/ |
28548b
|
571 |
$res = $this->_tools->monitorIPTables(); |
51cf60
|
572 |
|
dead5c
|
573 |
/* |
V |
574 |
* Insert the data into the database |
|
575 |
*/ |
bfcdef
|
576 |
$sql = 'REPLACE INTO monitor_data (server_id, type, created, data, state) ' . |
7fe908
|
577 |
'VALUES (' . |
MC |
578 |
$res['server_id'] . ', ' . |
|
579 |
"'" . $app->dbmaster->quote($res['type']) . "', " . |
|
580 |
'UNIX_TIMESTAMP(), ' . |
|
581 |
"'" . $app->dbmaster->quote(serialize($res['data'])) . "', " . |
|
582 |
"'" . $res['state'] . "'" . |
|
583 |
')'; |
220bb9
|
584 |
$app->dbmaster->query($sql); |
476a60
|
585 |
|
220bb9
|
586 |
/* The new data is written, now we can delete the old one */ |
fd5e71
|
587 |
$this->_delOldRecords($res['type'], $res['server_id']); |
220bb9
|
588 |
} |
476a60
|
589 |
|
dead5c
|
590 |
private function _monitorSysLog() { |
220bb9
|
591 |
global $app; |
51cf60
|
592 |
|
476a60
|
593 |
/* |
dead5c
|
594 |
* First we get the Monitoring-data from the tools |
V |
595 |
*/ |
|
596 |
$res = $this->_tools->monitorSysLog(); |
51cf60
|
597 |
|
220bb9
|
598 |
/* |
dead5c
|
599 |
* Insert the data into the database |
V |
600 |
*/ |
bfcdef
|
601 |
$sql = 'REPLACE INTO monitor_data (server_id, type, created, data, state) ' . |
7fe908
|
602 |
'VALUES (' . |
MC |
603 |
$res['server_id'] . ', ' . |
|
604 |
"'" . $app->dbmaster->quote($res['type']) . "', " . |
|
605 |
'UNIX_TIMESTAMP(), ' . |
|
606 |
"'" . $app->dbmaster->quote(serialize($res['data'])) . "', " . |
|
607 |
"'" . $res['state'] . "'" . |
|
608 |
')'; |
220bb9
|
609 |
$app->dbmaster->query($sql); |
671a41
|
610 |
|
220bb9
|
611 |
/* The new data is written, now we can delete the old one */ |
fd5e71
|
612 |
$this->_delOldRecords($res['type'], $res['server_id']); |
220bb9
|
613 |
} |
671a41
|
614 |
|
dead5c
|
615 |
private function _monitorMailLog() { |
220bb9
|
616 |
global $app; |
51cf60
|
617 |
|
220bb9
|
618 |
/* |
dead5c
|
619 |
* First we get the Monitoring-data from the tools |
V |
620 |
*/ |
|
621 |
$res = $this->_tools->monitorMailLog(); |
51cf60
|
622 |
|
220bb9
|
623 |
/* |
dead5c
|
624 |
* Insert the data into the database |
V |
625 |
*/ |
bfcdef
|
626 |
$sql = 'REPLACE INTO monitor_data (server_id, type, created, data, state) ' . |
7fe908
|
627 |
'VALUES (' . |
MC |
628 |
$res['server_id'] . ', ' . |
|
629 |
"'" . $app->dbmaster->quote($res['type']) . "', " . |
|
630 |
'UNIX_TIMESTAMP(), ' . |
|
631 |
"'" . $app->dbmaster->quote(serialize($res['data'])) . "', " . |
|
632 |
"'" . $res['state'] . "'" . |
|
633 |
')'; |
220bb9
|
634 |
$app->dbmaster->query($sql); |
fb4c27
|
635 |
|
220bb9
|
636 |
/* The new data is written, now we can delete the old one */ |
fd5e71
|
637 |
$this->_delOldRecords($res['type'], $res['server_id']); |
220bb9
|
638 |
} |
8793b3
|
639 |
|
dead5c
|
640 |
private function _monitorMailWarnLog() { |
220bb9
|
641 |
global $app; |
51cf60
|
642 |
|
220bb9
|
643 |
/* |
dead5c
|
644 |
* First we get the Monitoring-data from the tools |
V |
645 |
*/ |
|
646 |
$res = $this->_tools->monitorMailWarnLog(); |
51cf60
|
647 |
|
220bb9
|
648 |
/* |
dead5c
|
649 |
* Insert the data into the database |
V |
650 |
*/ |
bfcdef
|
651 |
$sql = 'REPLACE INTO monitor_data (server_id, type, created, data, state) ' . |
7fe908
|
652 |
'VALUES (' . |
MC |
653 |
$res['server_id'] . ', ' . |
|
654 |
"'" . $app->dbmaster->quote($res['type']) . "', " . |
|
655 |
'UNIX_TIMESTAMP(), ' . |
|
656 |
"'" . $app->dbmaster->quote(serialize($res['data'])) . "', " . |
|
657 |
"'" . $res['state'] . "'" . |
|
658 |
')'; |
220bb9
|
659 |
$app->dbmaster->query($sql); |
fb4c27
|
660 |
|
220bb9
|
661 |
/* The new data is written, now we can delete the old one */ |
fd5e71
|
662 |
$this->_delOldRecords($res['type'], $res['server_id']); |
220bb9
|
663 |
} |
8793b3
|
664 |
|
dead5c
|
665 |
private function _monitorMailErrLog() { |
220bb9
|
666 |
global $app; |
51cf60
|
667 |
|
220bb9
|
668 |
/* |
dead5c
|
669 |
* First we get the Monitoring-data from the tools |
V |
670 |
*/ |
|
671 |
$res = $this->_tools->monitorMailErrLog(); |
51cf60
|
672 |
|
220bb9
|
673 |
/* |
dead5c
|
674 |
* Insert the data into the database |
V |
675 |
*/ |
bfcdef
|
676 |
$sql = 'REPLACE INTO monitor_data (server_id, type, created, data, state) ' . |
7fe908
|
677 |
'VALUES (' . |
MC |
678 |
$res['server_id'] . ', ' . |
|
679 |
"'" . $app->dbmaster->quote($res['type']) . "', " . |
|
680 |
'UNIX_TIMESTAMP(), ' . |
|
681 |
"'" . $app->dbmaster->quote(serialize($res['data'])) . "', " . |
|
682 |
"'" . $res['state'] . "'" . |
|
683 |
')'; |
220bb9
|
684 |
$app->dbmaster->query($sql); |
fb4c27
|
685 |
|
220bb9
|
686 |
/* The new data is written, now we can delete the old one */ |
fd5e71
|
687 |
$this->_delOldRecords($res['type'], $res['server_id']); |
220bb9
|
688 |
} |
8793b3
|
689 |
|
dead5c
|
690 |
private function _monitorMessagesLog() { |
220bb9
|
691 |
global $app; |
51cf60
|
692 |
|
220bb9
|
693 |
/* |
dead5c
|
694 |
* First we get the Monitoring-data from the tools |
V |
695 |
*/ |
|
696 |
$res = $this->_tools->monitorMessagesLog(); |
51cf60
|
697 |
|
220bb9
|
698 |
/* |
dead5c
|
699 |
* Insert the data into the database |
V |
700 |
*/ |
bfcdef
|
701 |
$sql = 'REPLACE INTO monitor_data (server_id, type, created, data, state) ' . |
7fe908
|
702 |
'VALUES (' . |
MC |
703 |
$res['server_id'] . ', ' . |
|
704 |
"'" . $app->dbmaster->quote($res['type']) . "', " . |
|
705 |
'UNIX_TIMESTAMP(), ' . |
|
706 |
"'" . $app->dbmaster->quote(serialize($res['data'])) . "', " . |
|
707 |
"'" . $res['state'] . "'" . |
|
708 |
')'; |
220bb9
|
709 |
$app->dbmaster->query($sql); |
fb4c27
|
710 |
|
220bb9
|
711 |
/* The new data is written, now we can delete the old one */ |
fd5e71
|
712 |
$this->_delOldRecords($res['type'], $res['server_id']); |
220bb9
|
713 |
} |
8793b3
|
714 |
|
dead5c
|
715 |
private function _monitorISPCCronLog() { |
220bb9
|
716 |
global $app; |
51cf60
|
717 |
|
220bb9
|
718 |
/* |
dead5c
|
719 |
* First we get the Monitoring-data from the tools |
V |
720 |
*/ |
|
721 |
$res = $this->_tools->monitorISPCCronLog(); |
7fe908
|
722 |
|
edf806
|
723 |
//* Ensure that output is encoded so that it does not break the serialize |
bfcdef
|
724 |
if(is_array($res) && isset($res['data'])) $res['data'] = htmlentities($res['data']); |
51cf60
|
725 |
|
220bb9
|
726 |
/* |
dead5c
|
727 |
* Insert the data into the database |
V |
728 |
*/ |
bfcdef
|
729 |
$sql = 'REPLACE INTO monitor_data (server_id, type, created, data, state) ' . |
7fe908
|
730 |
'VALUES (' . |
MC |
731 |
$res['server_id'] . ', ' . |
|
732 |
"'" . $app->dbmaster->quote($res['type']) . "', " . |
|
733 |
'UNIX_TIMESTAMP(), ' . |
|
734 |
"'" . $app->dbmaster->quote(serialize($res['data'])) . "', " . |
|
735 |
"'" . $res['state'] . "'" . |
|
736 |
')'; |
220bb9
|
737 |
$app->dbmaster->query($sql); |
641cb3
|
738 |
|
220bb9
|
739 |
/* The new data is written, now we can delete the old one */ |
fd5e71
|
740 |
$this->_delOldRecords($res['type'], $res['server_id']); |
220bb9
|
741 |
} |
8793b3
|
742 |
|
dead5c
|
743 |
private function _monitorFreshClamLog() { |
220bb9
|
744 |
global $app; |
51cf60
|
745 |
|
220bb9
|
746 |
/* |
dead5c
|
747 |
* First we get the Monitoring-data from the tools |
V |
748 |
*/ |
|
749 |
$res = $this->_tools->monitorFreshClamLog(); |
51cf60
|
750 |
|
220bb9
|
751 |
/* |
dead5c
|
752 |
* Insert the data into the database |
V |
753 |
*/ |
bfcdef
|
754 |
$sql = 'REPLACE INTO monitor_data (server_id, type, created, data, state) ' . |
7fe908
|
755 |
'VALUES (' . |
MC |
756 |
$res['server_id'] . ', ' . |
|
757 |
"'" . $app->dbmaster->quote($res['type']) . "', " . |
|
758 |
'UNIX_TIMESTAMP(), ' . |
|
759 |
"'" . $app->dbmaster->quote(serialize($res['data'])) . "', " . |
|
760 |
"'" . $res['state'] . "'" . |
|
761 |
')'; |
220bb9
|
762 |
$app->dbmaster->query($sql); |
fb4c27
|
763 |
|
220bb9
|
764 |
/* The new data is written, now we can delete the old one */ |
fd5e71
|
765 |
$this->_delOldRecords($res['type'], $res['server_id']); |
220bb9
|
766 |
} |
8793b3
|
767 |
|
dead5c
|
768 |
private function _monitorClamAvLog() { |
51cf60
|
769 |
global $app; |
V |
770 |
|
220bb9
|
771 |
/* |
dead5c
|
772 |
* First we get the Monitoring-data from the tools |
V |
773 |
*/ |
|
774 |
$res = $this->_tools->monitorClamAvLog(); |
51cf60
|
775 |
|
dead5c
|
776 |
/* |
V |
777 |
* Insert the data into the database |
|
778 |
*/ |
bfcdef
|
779 |
$sql = 'REPLACE INTO monitor_data (server_id, type, created, data, state) ' . |
7fe908
|
780 |
'VALUES (' . |
MC |
781 |
$res['server_id'] . ', ' . |
|
782 |
"'" . $app->dbmaster->quote($res['type']) . "', " . |
|
783 |
'UNIX_TIMESTAMP(), ' . |
|
784 |
"'" . $app->dbmaster->quote(serialize($res['data'])) . "', " . |
|
785 |
"'" . $res['state'] . "'" . |
|
786 |
')'; |
220bb9
|
787 |
$app->dbmaster->query($sql); |
36d307
|
788 |
|
220bb9
|
789 |
/* The new data is written, now we can delete the old one */ |
fd5e71
|
790 |
$this->_delOldRecords($res['type'], $res['server_id']); |
220bb9
|
791 |
} |
8793b3
|
792 |
|
dead5c
|
793 |
private function _monitorIspConfigLog() { |
220bb9
|
794 |
global $app; |
51cf60
|
795 |
|
220bb9
|
796 |
/* |
dead5c
|
797 |
* First we get the Monitoring-data from the tools |
V |
798 |
*/ |
|
799 |
$res = $this->_tools->monitorIspConfigLog(); |
51cf60
|
800 |
|
dead5c
|
801 |
/* |
V |
802 |
* Insert the data into the database |
|
803 |
*/ |
bfcdef
|
804 |
$sql = 'REPLACE INTO monitor_data (server_id, type, created, data, state) ' . |
7fe908
|
805 |
'VALUES (' . |
MC |
806 |
$res['server_id'] . ', ' . |
|
807 |
"'" . $app->dbmaster->quote($res['type']) . "', " . |
|
808 |
'UNIX_TIMESTAMP(), ' . |
|
809 |
"'" . $app->dbmaster->quote(serialize($res['data'])) . "', " . |
|
810 |
"'" . $res['state'] . "'" . |
|
811 |
')'; |
220bb9
|
812 |
$app->dbmaster->query($sql); |
fb4c27
|
813 |
|
220bb9
|
814 |
/* The new data is written, now we can delete the old one */ |
fd5e71
|
815 |
$this->_delOldRecords($res['type'], $res['server_id']); |
220bb9
|
816 |
} |
8793b3
|
817 |
|
51cf60
|
818 |
/** |
V |
819 |
* Deletes Records older than 4 minutes. |
|
820 |
* The monitor writes new data every 5 minutes or longer (4 hour, 1 day). |
|
821 |
* So if i delete all Date older than 4 minutes i can be sure, that all old data |
|
822 |
* are deleted... |
dead5c
|
823 |
*/ |
51cf60
|
824 |
private function _delOldRecords($type, $serverId) { |
220bb9
|
825 |
global $app; |
8793b3
|
826 |
|
b67344
|
827 |
// $now = time(); |
T |
828 |
// $old = $now - (4 * 60); // 4 minutes |
|
829 |
$old = 'UNIX_TIMESTAMP() - 240'; |
7fe908
|
830 |
|
51cf60
|
831 |
/* |
V |
832 |
* ATTENTION if i do NOT pay attention of the server id, i delete all data (of the type) |
7fe908
|
833 |
* of ALL servers. This means, if i have a multiserver-environment and a server has a |
51cf60
|
834 |
* time not synced with the others (for example, all server has 11:00 and ONE server has |
V |
835 |
* 10:45) then the actual data of this server (with the time-stamp 10:45) get lost |
|
836 |
* even though it is the NEWEST data of this server. To avoid this i HAVE to include |
|
837 |
* the server-id! |
|
838 |
*/ |
e38d14
|
839 |
$sql = 'DELETE FROM monitor_data ' . |
7fe908
|
840 |
'WHERE ' . |
MC |
841 |
' type =' . "'" . $app->dbmaster->quote($type) . "' " . |
|
842 |
'AND ' . |
|
843 |
' created < ' . $old . ' ' . |
|
844 |
'AND ' . |
|
845 |
' server_id = ' . $serverId; |
220bb9
|
846 |
$app->dbmaster->query($sql); |
V |
847 |
} |
504908
|
848 |
|
TB |
849 |
private function _cleanupAPS() { |
|
850 |
global $app, $conf; |
|
851 |
|
|
852 |
// run this only on the master |
|
853 |
if($conf['server_id'] == 1) { |
|
854 |
$records = $app->db->queryAllRecords("SELECT s.instance_id, s.name, s.value FROM `aps_instances_settings` as s INNER JOIN `aps_instances` as i ON (i.id = s.instance_id) WHERE s.value != '' AND s.name IN ('main_database_password', 'admin_password') AND i.instance_status > 1"); |
|
855 |
if(is_array($records)) { |
|
856 |
foreach($records as $rec) { |
|
857 |
$tmp = $app->db->queryOneRecord("SELECT id FROM aps_instances_settings WHERE instance_id = '".$app->db->quote($rec['instance_id'])."' AND name = '".$app->db->quote($rec['name'])."'"); |
|
858 |
$app->db->datalogUpdate('aps_instances_settings', "value = ''", 'id', $tmp['id']); |
|
859 |
} |
|
860 |
} |
|
861 |
} |
|
862 |
|
|
863 |
} |
8793b3
|
864 |
|
220bb9
|
865 |
} |
dead5c
|
866 |
|
7fe908
|
867 |
?> |