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