monitor_core_module.inc.php 23.7 KB
Newer Older
1
<?php
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
  Copyright (c) 2007-2011, Till Brehm, projektfarm Gmbh and Oliver Vogel www.muv.com
  All rights reserved.

  Redistribution and use in source and binary forms, with or without modification,
  are permitted provided that the following conditions are met:

 * Redistributions of source code must retain the above copyright notice,
  this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright notice,
  this list of conditions and the following disclaimer in the documentation
  and/or other materials provided with the distribution.
 * Neither the name of ISPConfig nor the names of its contributors
  may be used to endorse or promote products derived from this software without
  specific prior written permission.

  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
  INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
redray's avatar
redray committed
30

31
class monitor_core_module {
32

33
	var $interval = 5; // do the monitoring every 5 minutes
34 35 36 37
	var $module_name = 'monitor_core_module';
	var $class_name = 'monitor_core_module';
	/* No actions at this time. maybe later... */
	var $actions_available = array();
38
	/** The Tools */
39 40


41
	private $_tools = null;
42 43
	//** time the script was called
	private $_run_time = null;
44 45 46 47 48 49

	/**
	 * This function is called during ispconfig installation to determine
	 * if a symlink shall be created for this plugin.
	 */
	public function onInstall() {
50 51 52
		global $conf;
		return true;
	}
53

54 55 56 57
	/**
	 * This function is called when the module is loaded
	 */
	public function onLoad() {
58
		global $app;
59 60 61 62

		//* store the running time
		$this->_run_time = time();

63
		/*
64 65
		 * Do the monitor every n minutes and write the result to the db
		 */
66
		$min = @date('i', $this->_run_time);
67
		if (($min % $this->interval) == 0) {
68
			$this->_doMonitor();
69 70 71
		}
	}

72 73 74 75 76
	/**
	 * This function is called when a change in one of the registered tables is detected.
	 * The function then raises the events for the plugins.
	 */
	public function process($tablename, $action, $data) {
77
		// not needed
78 79
	}

80 81 82 83
	/**
	 * This method is called every n minutes, when the module ist loaded.
	 * The method then does a system-monitoring
	 */
84
	// TODO: what monitoring is done should be a config-var
85
	private function _doMonitor() {
vogelor's avatar
vogelor committed
86
		global $app;
87
		/*
88 89 90 91
		 * We need the tools in almost every method, so initialize them once...
		 */
		$app->load('monitor_tools');
		$this->_tools = new monitor_tools();
92

93
		/*
94
		 * Calls the single Monitoring steps
95
		 */
latham's avatar
latham committed
96
		$this->_monitorEmailQuota();
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
		$this->_monitorHDQuota();
		$this->_monitorServer();
		$this->_monitorOsVer();
		$this->_monitorIspcVer();
		$this->_monitorDiskUsage();
		$this->_monitorMemUsage();
		$this->_monitorCpu();
		$this->_monitorServices();
		if (@file_exists('/proc/user_beancounters')) {
			$this->_monitorOpenVzHost();
			$this->_monitorOpenVzUserBeancounter();
		}
		$this->_monitorMailLog();
		$this->_monitorMailWarnLog();
		$this->_monitorMailErrLog();
		$this->_monitorMessagesLog();
		$this->_monitorISPCCronLog();
		$this->_monitorFreshClamLog();
		$this->_monitorClamAvLog();
		$this->_monitorIspConfigLog();
		$this->_monitorSystemUpdate();
		$this->_monitorMailQueue();
		$this->_monitorRaid();
		$this->_monitorRkHunter();
		$this->_monitorFail2ban();
122
		$this->_monitorIPTables();
123 124 125
		$this->_monitorSysLog();
	}

126 127
	private function _monitorEmailQuota() {
		global $app, $conf;
128

129
		/*
130 131
		 *  This monitoring is expensive, so do it only every 15 minutes
		 */
132
		$min = @date('i', $this->_run_time);
133
		if ($min % 15 != 0) return;
134

135 136 137
		$app->uses('getconf');
		$mail_config = $app->getconf->get_server_config($conf['server_id'], 'mail');
		if($mail_config['mailbox_quota_stats'] == 'n') return;
138 139


140
		/*
141 142
         * First we get the Monitoring-data from the tools
         */
143
		$res = $this->_tools->monitorEmailQuota();
144

145
		/*
146 147
         * Insert the data into the database
         */
148 149 150 151 152 153 154 155 156 157 158 159 160
		$sql = 'REPLACE INTO monitor_data (server_id, type, created, data, state) ' .
			'VALUES (' .
			$res['server_id'] . ', ' .
			"'" . $app->dbmaster->quote($res['type']) . "', " .
			'UNIX_TIMESTAMP(), ' .
			"'" . $app->dbmaster->quote(serialize($res['data'])) . "', " .
			"'" . $res['state'] . "'" .
			')';
		$app->dbmaster->query($sql);

		/* The new data is written, now we can delete the old one */
		$this->_delOldRecords($res['type'], $res['server_id']);
	}
161

162 163
	private function _monitorHDQuota() {
		global $app;
164 165

		/*
166 167 168
		 * First we get the Monitoring-data from the tools
		 */
		$res = $this->_tools->monitorHDQuota();
169

170 171 172
		/*
		 * Insert the data into the database
		 */
173
		$sql = 'REPLACE INTO monitor_data (server_id, type, created, data, state) ' .
174 175 176 177 178 179 180
			'VALUES (' .
			$res['server_id'] . ', ' .
			"'" . $app->dbmaster->quote($res['type']) . "', " .
			'UNIX_TIMESTAMP(), ' .
			"'" . $app->dbmaster->quote(serialize($res['data'])) . "', " .
			"'" . $res['state'] . "'" .
			')';
181 182 183
		$app->dbmaster->query($sql);

		/* The new data is written, now we can delete the old one */
vogelor's avatar
vogelor committed
184
		$this->_delOldRecords($res['type'], $res['server_id']);
185
	}
186

187 188
	private function _monitorServer() {
		global $app;
189

190
		/*
191 192 193
		 * First we get the Monitoring-data from the tools
		 */
		$res = $this->_tools->monitorServer();
194

195
		/*
196 197
		 * Insert the data into the database
		 */
198
		$sql = 'REPLACE INTO monitor_data (server_id, type, created, data, state) ' .
199 200 201 202 203 204 205
			'VALUES (' .
			$res['server_id'] . ', ' .
			"'" . $app->dbmaster->quote($res['type']) . "', " .
			'UNIX_TIMESTAMP(), ' .
			"'" . $app->dbmaster->quote(serialize($res['data'])) . "', " .
			"'" . $res['state'] . "'" .
			')';
206 207 208
		$app->dbmaster->query($sql);

		/* The new data is written, now we can delete the old one */
vogelor's avatar
vogelor committed
209
		$this->_delOldRecords($res['type'], $res['server_id']);
210 211
	}

212
	private function _monitorOsVer() {
213
		global $app;
214

215
		/*
216 217 218
		 * First we get the Monitoring-data from the tools
		 */
		$res = $this->_tools->monitorOsVer();
219

220
		/*
221 222
		 * Insert the data into the database
		 */
223
		$sql = 'REPLACE INTO monitor_data (server_id, type, created, data, state) ' .
224 225 226 227 228 229 230
			'VALUES (' .
			$res['server_id'] . ', ' .
			"'" . $app->dbmaster->quote($res['type']) . "', " .
			'UNIX_TIMESTAMP(), ' .
			"'" . $app->dbmaster->quote(serialize($res['data'])) . "', " .
			"'" . $res['state'] . "'" .
			')';
231 232 233
		$app->dbmaster->query($sql);

		/* The new data is written, now we can delete the old one */
vogelor's avatar
vogelor committed
234
		$this->_delOldRecords($res['type'], $res['server_id']);
235
	}
236

237
	private function _monitorIspcVer() {
238 239 240
		global $app;

		/*
241 242 243
		 * First we get the Monitoring-data from the tools
		 */
		$res = $this->_tools->monitorIspcVer();
244

245
		/*
246 247
		 * Insert the data into the database
		 */
248
		$sql = 'REPLACE INTO monitor_data (server_id, type, created, data, state) ' .
249 250 251 252 253 254 255
			'VALUES (' .
			$res['server_id'] . ', ' .
			"'" . $app->dbmaster->quote($res['type']) . "', " .
			'UNIX_TIMESTAMP(), ' .
			"'" . $app->dbmaster->quote(serialize($res['data'])) . "', " .
			"'" . $res['state'] . "'" .
			')';
256 257 258
		$app->dbmaster->query($sql);

		/* The new data is written, now we can delete the old one */
vogelor's avatar
vogelor committed
259
		$this->_delOldRecords($res['type'], $res['server_id']);
260 261
	}

262
	private function _monitorDiskUsage() {
263
		global $app;
264

265
		/*
266 267 268
		 * First we get the Monitoring-data from the tools
		 */
		$res = $this->_tools->monitorDiskUsage();
269

270
		/*
271 272
		 * Insert the data into the database
		 */
273
		$sql = 'REPLACE INTO monitor_data (server_id, type, created, data, state) ' .
274 275 276 277 278 279 280
			'VALUES (' .
			$res['server_id'] . ', ' .
			"'" . $app->dbmaster->quote($res['type']) . "', " .
			'UNIX_TIMESTAMP(), ' .
			"'" . $app->dbmaster->quote(serialize($res['data'])) . "', " .
			"'" . $res['state'] . "'" .
			')';
281 282 283
		$app->dbmaster->query($sql);

		/* The new data is written, now we can delete the old one */
vogelor's avatar
vogelor committed
284
		$this->_delOldRecords($res['type'], $res['server_id']);
285 286
	}

287
	private function _monitorMemUsage() {
288 289
		global $app;
		/*
290 291 292
		 * First we get the Monitoring-data from the tools
		 */
		$res = $this->_tools->monitorMemUsage();
293

294
		/*
295 296
		 * Insert the data into the database
		 */
297
		$sql = 'REPLACE INTO monitor_data (server_id, type, created, data, state) ' .
298 299 300 301 302 303 304
			'VALUES (' .
			$res['server_id'] . ', ' .
			"'" . $app->dbmaster->quote($res['type']) . "', " .
			'UNIX_TIMESTAMP(), ' .
			"'" . $app->dbmaster->quote(serialize($res['data'])) . "', " .
			"'" . $res['state'] . "'" .
			')';
305 306 307
		$app->dbmaster->query($sql);

		/* The new data is written, now we can delete the old one */
vogelor's avatar
vogelor committed
308
		$this->_delOldRecords($res['type'], $res['server_id']);
309 310
	}

311
	private function _monitorCpu() {
312 313
		global $app;
		/*
314 315 316
		 * First we get the Monitoring-data from the tools
		 */
		$res = $this->_tools->monitorCpu();
317

318
		/*
319 320
		 * Insert the data into the database
		 */
321
		$sql = 'REPLACE INTO monitor_data (server_id, type, created, data, state) ' .
322 323 324 325 326 327 328
			'VALUES (' .
			$res['server_id'] . ', ' .
			"'" . $app->dbmaster->quote($res['type']) . "', " .
			'UNIX_TIMESTAMP(), ' .
			"'" . $app->dbmaster->quote(serialize($res['data'])) . "', " .
			"'" . $res['state'] . "'" .
			')';
329 330 331
		$app->dbmaster->query($sql);

		/* The new data is written, now we can delete the old one */
vogelor's avatar
vogelor committed
332
		$this->_delOldRecords($res['type'], $res['server_id']);
333 334
	}

335
	private function _monitorServices() {
336
		global $app;
337

338 339 340 341
		/*
		 * First we get the Monitoring-data from the tools
		 */
		$res = $this->_tools->monitorServices();
342

343
		/*
344 345
		 * Insert the data into the database
		 */
346
		$sql = 'REPLACE INTO monitor_data (server_id, type, created, data, state) ' .
347 348 349 350 351 352 353
			'VALUES (' .
			$res['server_id'] . ', ' .
			"'" . $app->dbmaster->quote($res['type']) . "', " .
			'UNIX_TIMESTAMP(), ' .
			"'" . $app->dbmaster->quote(serialize($res['data'])) . "', " .
			"'" . $res['state'] . "'" .
			')';
354 355 356
		$app->dbmaster->query($sql);

		/* The new data is written, now we can delete the old one */
vogelor's avatar
vogelor committed
357
		$this->_delOldRecords($res['type'], $res['server_id']);
358 359
	}

360
	private function _monitorOpenVzHost() {
361
		global $app;
362

363
		/*
364 365 366
		 * First we get the Monitoring-data from the tools
		 */
		$res = $this->_tools->monitorOpenVzHost();
367

368
		/*
369 370
		 * Insert the data into the database
		 */
371
		$sql = 'REPLACE INTO monitor_data (server_id, type, created, data, state) ' .
372 373 374 375 376 377 378
			'VALUES (' .
			$res['server_id'] . ', ' .
			"'" . $app->dbmaster->quote($res['type']) . "', " .
			'UNIX_TIMESTAMP(), ' .
			"'" . $app->dbmaster->quote(serialize($res['data'])) . "', " .
			"'" . $res['state'] . "'" .
			')';
379 380 381
		$app->dbmaster->query($sql);

		/* The new data is written, now we can delete the old one */
vogelor's avatar
vogelor committed
382
		$this->_delOldRecords($res['type'], $res['server_id']);
383 384
	}

385
	private function _monitorOpenVzUserBeancounter() {
386
		global $app;
387

388
		/*
389 390 391
		 * First we get the Monitoring-data from the tools
		 */
		$res = $this->_tools->monitorOpenVzUserBeancounter();
392

393
		/*
394 395
		 * Insert the data into the database
		 */
396
		$sql = 'REPLACE INTO monitor_data (server_id, type, created, data, state) ' .
397 398 399 400 401 402 403
			'VALUES (' .
			$res['server_id'] . ', ' .
			"'" . $app->dbmaster->quote($res['type']) . "', " .
			'UNIX_TIMESTAMP(), ' .
			"'" . $app->dbmaster->quote(serialize($res['data'])) . "', " .
			"'" . $res['state'] . "'" .
			')';
404 405 406
		$app->dbmaster->query($sql);

		/* The new data is written, now we can delete the old one */
vogelor's avatar
vogelor committed
407
		$this->_delOldRecords($res['type'], $res['server_id']);
408 409
	}

410
	private function _monitorSystemUpdate() {
411
		/*
412 413
		 *  This monitoring is expensive, so do it only once an hour
		 */
414
		$min = @date('i', $this->_run_time);
415 416
		if ($min != 0)
			return;
417

418
		/*
419 420
		 * OK - here we go...
		 */
421
		global $app;
422 423 424 425
		
		$app->uses('getconf');
		$server_config = $app->getconf->get_server_config($conf['server_id'], 'server');
		if($server_config['monitor_system_updates'] == 'n') return;
426

427 428 429 430
		/*
		 * First we get the Monitoring-data from the tools
		 */
		$res = $this->_tools->monitorSystemUpdate();
431

432
		//* Ensure that output is encoded so that it does not break the serialize
433
		//$res['data']['output'] = htmlentities($res['data']['output']);
434
		$res['data']['output'] = htmlentities($res['data']['output'], ENT_QUOTES, 'UTF-8');
435

436
		/*
437 438
		 * Insert the data into the database
		 */
439
		$sql = 'REPLACE INTO monitor_data (server_id, type, created, data, state) ' .
440 441 442 443 444 445 446
			'VALUES (' .
			$res['server_id'] . ', ' .
			"'" . $app->dbmaster->quote($res['type']) . "', " .
			'UNIX_TIMESTAMP(), ' .
			"'" . $app->dbmaster->quote(serialize($res['data'])) . "', " .
			"'" . $res['state'] . "'" .
			')';
447 448 449
		$app->dbmaster->query($sql);

		/* The new data is written, now we can delete the old one */
vogelor's avatar
vogelor committed
450
		$this->_delOldRecords($res['type'], $res['server_id']);
451 452
	}

453
	private function _monitorMailQueue() {
454
		global $app;
455

456
		/*
457 458 459
		 * First we get the Monitoring-data from the tools
		 */
		$res = $this->_tools->monitorMailQueue();
460

461
		/*
462 463
		 * Insert the data into the database
		 */
464
		$sql = 'REPLACE INTO monitor_data (server_id, type, created, data, state) ' .
465 466 467 468 469 470 471
			'VALUES (' .
			$res['server_id'] . ', ' .
			"'" . $app->dbmaster->quote($res['type']) . "', " .
			'UNIX_TIMESTAMP(), ' .
			"'" . $app->dbmaster->quote(serialize($res['data'])) . "', " .
			"'" . $res['state'] . "'" .
			')';
472 473 474
		$app->dbmaster->query($sql);

		/* The new data is written, now we can delete the old one */
vogelor's avatar
vogelor committed
475
		$this->_delOldRecords($res['type'], $res['server_id']);
476 477
	}

478
	private function _monitorRaid() {
479
		global $app;
480

481
		/*
482 483 484
		 * First we get the Monitoring-data from the tools
		 */
		$res = $this->_tools->monitorRaid();
485

486
		/*
487 488
		 * Insert the data into the database
		 */
489
		$sql = 'REPLACE INTO monitor_data (server_id, type, created, data, state) ' .
490 491 492 493 494 495 496
			'VALUES (' .
			$res['server_id'] . ', ' .
			"'" . $app->dbmaster->quote($res['type']) . "', " .
			'UNIX_TIMESTAMP(), ' .
			"'" . $app->dbmaster->quote(serialize($res['data'])) . "', " .
			"'" . $res['state'] . "'" .
			')';
497 498 499
		$app->dbmaster->query($sql);

		/* The new data is written, now we can delete the old one */
vogelor's avatar
vogelor committed
500
		$this->_delOldRecords($res['type'], $res['server_id']);
501 502
	}

503
	private function _monitorRkHunter() {
504
		/*
505 506
		 *  This monitoring is expensive, so do it only once a day
		 */
507 508
		$min = @date('i', $this->_run_time);
		$hour = @date('H', $this->_run_time);
509 510 511 512 513
		if (!($min == 0 && $hour == 23))
			return;
		/*
		 * OK . here we go...
		 */
514
		global $app;
515

516 517 518 519
		/*
		 * First we get the Monitoring-data from the tools
		 */
		$res = $this->_tools->monitorRkHunter();
520

521
		/*
522 523
		 * Insert the data into the database
		 */
524
		$sql = 'REPLACE INTO monitor_data (server_id, type, created, data, state) ' .
525 526 527 528 529 530 531
			'VALUES (' .
			$res['server_id'] . ', ' .
			"'" . $app->dbmaster->quote($res['type']) . "', " .
			'UNIX_TIMESTAMP(), ' .
			"'" . $app->dbmaster->quote(serialize($res['data'])) . "', " .
			"'" . $res['state'] . "'" .
			')';
532 533 534
		$app->dbmaster->query($sql);

		/* The new data is written, now we can delete the old one */
vogelor's avatar
vogelor committed
535
		$this->_delOldRecords($res['type'], $res['server_id']);
536 537
	}

538
	private function _monitorFail2ban() {
539
		global $app;
540

541
		/*
542 543
         * First we get the Monitoring-data from the tools
         */
544
		$res = $this->_tools->monitorFail2ban();
545

546
		/*
547 548
         * Insert the data into the database
         */
549 550 551 552 553 554 555 556 557
		$sql = 'REPLACE INTO monitor_data (server_id, type, created, data, state) ' .
			'VALUES (' .
			$res['server_id'] . ', ' .
			"'" . $app->dbmaster->quote($res['type']) . "', " .
			'UNIX_TIMESTAMP(), ' .
			"'" . $app->dbmaster->quote(serialize($res['data'])) . "', " .
			"'" . $res['state'] . "'" .
			')';
		$app->dbmaster->query($sql);
558

559 560 561
		/* The new data is written, now we can delete the old one */
		$this->_delOldRecords($res['type'], $res['server_id']);
	}
562 563 564


	private function _monitorIPTables() {
565
		global $app;
566

567
		/*
568 569
		 * First we get the Monitoring-data from the tools
		 */
570
		$res = $this->_tools->monitorIPTables();
571

572 573 574
		/*
		 * Insert the data into the database
		 */
575
		$sql = 'REPLACE INTO monitor_data (server_id, type, created, data, state) ' .
576 577 578 579 580 581 582
			'VALUES (' .
			$res['server_id'] . ', ' .
			"'" . $app->dbmaster->quote($res['type']) . "', " .
			'UNIX_TIMESTAMP(), ' .
			"'" . $app->dbmaster->quote(serialize($res['data'])) . "', " .
			"'" . $res['state'] . "'" .
			')';
583 584 585
		$app->dbmaster->query($sql);

		/* The new data is written, now we can delete the old one */
vogelor's avatar
vogelor committed
586
		$this->_delOldRecords($res['type'], $res['server_id']);
587 588
	}

589
	private function _monitorSysLog() {
590
		global $app;
591

592
		/*
593 594 595
		 * First we get the Monitoring-data from the tools
		 */
		$res = $this->_tools->monitorSysLog();
596

597
		/*
598 599
		 * Insert the data into the database
		 */
600
		$sql = 'REPLACE INTO monitor_data (server_id, type, created, data, state) ' .
601 602 603 604 605 606 607
			'VALUES (' .
			$res['server_id'] . ', ' .
			"'" . $app->dbmaster->quote($res['type']) . "', " .
			'UNIX_TIMESTAMP(), ' .
			"'" . $app->dbmaster->quote(serialize($res['data'])) . "', " .
			"'" . $res['state'] . "'" .
			')';
608 609 610
		$app->dbmaster->query($sql);

		/* The new data is written, now we can delete the old one */
vogelor's avatar
vogelor committed
611
		$this->_delOldRecords($res['type'], $res['server_id']);
612 613
	}

614
	private function _monitorMailLog() {
615
		global $app;
616

617
		/*
618 619 620
		 * First we get the Monitoring-data from the tools
		 */
		$res = $this->_tools->monitorMailLog();
621

622
		/*
623 624
		 * Insert the data into the database
		 */
625
		$sql = 'REPLACE INTO monitor_data (server_id, type, created, data, state) ' .
626 627 628 629 630 631 632
			'VALUES (' .
			$res['server_id'] . ', ' .
			"'" . $app->dbmaster->quote($res['type']) . "', " .
			'UNIX_TIMESTAMP(), ' .
			"'" . $app->dbmaster->quote(serialize($res['data'])) . "', " .
			"'" . $res['state'] . "'" .
			')';
633 634 635
		$app->dbmaster->query($sql);

		/* The new data is written, now we can delete the old one */
vogelor's avatar
vogelor committed
636
		$this->_delOldRecords($res['type'], $res['server_id']);
637 638
	}

639
	private function _monitorMailWarnLog() {
640
		global $app;
641

642
		/*
643 644 645
		 * First we get the Monitoring-data from the tools
		 */
		$res = $this->_tools->monitorMailWarnLog();
646

647
		/*
648 649
		 * Insert the data into the database
		 */
650
		$sql = 'REPLACE INTO monitor_data (server_id, type, created, data, state) ' .
651 652 653 654 655 656 657
			'VALUES (' .
			$res['server_id'] . ', ' .
			"'" . $app->dbmaster->quote($res['type']) . "', " .
			'UNIX_TIMESTAMP(), ' .
			"'" . $app->dbmaster->quote(serialize($res['data'])) . "', " .
			"'" . $res['state'] . "'" .
			')';
658 659 660
		$app->dbmaster->query($sql);

		/* The new data is written, now we can delete the old one */
vogelor's avatar
vogelor committed
661
		$this->_delOldRecords($res['type'], $res['server_id']);
662 663
	}

664
	private function _monitorMailErrLog() {
665
		global $app;
666

667
		/*
668 669 670
		 * First we get the Monitoring-data from the tools
		 */
		$res = $this->_tools->monitorMailErrLog();
671

672
		/*
673 674
		 * Insert the data into the database
		 */
675
		$sql = 'REPLACE INTO monitor_data (server_id, type, created, data, state) ' .
676 677 678 679 680 681 682
			'VALUES (' .
			$res['server_id'] . ', ' .
			"'" . $app->dbmaster->quote($res['type']) . "', " .
			'UNIX_TIMESTAMP(), ' .
			"'" . $app->dbmaster->quote(serialize($res['data'])) . "', " .
			"'" . $res['state'] . "'" .
			')';
683 684 685
		$app->dbmaster->query($sql);

		/* The new data is written, now we can delete the old one */
vogelor's avatar
vogelor committed
686
		$this->_delOldRecords($res['type'], $res['server_id']);
687
	}
688

689
	private function _monitorMessagesLog() {
690
		global $app;
691

692
		/*
693 694 695
		 * First we get the Monitoring-data from the tools
		 */
		$res = $this->_tools->monitorMessagesLog();
696

697
		/*
698 699
		 * Insert the data into the database
		 */
700
		$sql = 'REPLACE INTO monitor_data (server_id, type, created, data, state) ' .
701 702 703 704 705 706 707
			'VALUES (' .
			$res['server_id'] . ', ' .
			"'" . $app->dbmaster->quote($res['type']) . "', " .
			'UNIX_TIMESTAMP(), ' .
			"'" . $app->dbmaster->quote(serialize($res['data'])) . "', " .
			"'" . $res['state'] . "'" .
			')';
708 709 710
		$app->dbmaster->query($sql);

		/* The new data is written, now we can delete the old one */
vogelor's avatar
vogelor committed
711
		$this->_delOldRecords($res['type'], $res['server_id']);
712 713
	}

714
	private function _monitorISPCCronLog() {
715
		global $app;
716

717
		/*
718 719 720
		 * First we get the Monitoring-data from the tools
		 */
		$res = $this->_tools->monitorISPCCronLog();
721

722
		//* Ensure that output is encoded so that it does not break the serialize
723
		if(is_array($res) && isset($res['data'])) $res['data'] = htmlentities($res['data']);
724

725
		/*
726 727
		 * Insert the data into the database
		 */
728
		$sql = 'REPLACE INTO monitor_data (server_id, type, created, data, state) ' .
729 730 731 732 733 734 735
			'VALUES (' .
			$res['server_id'] . ', ' .
			"'" . $app->dbmaster->quote($res['type']) . "', " .
			'UNIX_TIMESTAMP(), ' .
			"'" . $app->dbmaster->quote(serialize($res['data'])) . "', " .
			"'" . $res['state'] . "'" .
			')';
736 737 738
		$app->dbmaster->query($sql);

		/* The new data is written, now we can delete the old one */
vogelor's avatar
vogelor committed
739
		$this->_delOldRecords($res['type'], $res['server_id']);
740 741
	}

742
	private function _monitorFreshClamLog() {
743
		global $app;
744

745
		/*
746 747 748
		 * First we get the Monitoring-data from the tools
		 */
		$res = $this->_tools->monitorFreshClamLog();
749

750
		/*
751 752
		 * Insert the data into the database
		 */
753
		$sql = 'REPLACE INTO monitor_data (server_id, type, created, data, state) ' .
754 755 756 757 758 759 760
			'VALUES (' .
			$res['server_id'] . ', ' .
			"'" . $app->dbmaster->quote($res['type']) . "', " .
			'UNIX_TIMESTAMP(), ' .
			"'" . $app->dbmaster->quote(serialize($res['data'])) . "', " .
			"'" . $res['state'] . "'" .
			')';
761 762 763
		$app->dbmaster->query($sql);

		/* The new data is written, now we can delete the old one */
vogelor's avatar
vogelor committed
764
		$this->_delOldRecords($res['type'], $res['server_id']);
765 766
	}

767
	private function _monitorClamAvLog() {
768 769
		global $app;

770
		/*
771 772 773
		 * First we get the Monitoring-data from the tools
		 */
		$res = $this->_tools->monitorClamAvLog();
774

775 776 777
		/*
		 * Insert the data into the database
		 */
778
		$sql = 'REPLACE INTO monitor_data (server_id, type, created, data, state) ' .
779 780 781 782 783 784 785
			'VALUES (' .
			$res['server_id'] . ', ' .
			"'" . $app->dbmaster->quote($res['type']) . "', " .
			'UNIX_TIMESTAMP(), ' .
			"'" . $app->dbmaster->quote(serialize($res['data'])) . "', " .
			"'" . $res['state'] . "'" .
			')';
786 787 788
		$app->dbmaster->query($sql);

		/* The new data is written, now we can delete the old one */
vogelor's avatar
vogelor committed
789
		$this->_delOldRecords($res['type'], $res['server_id']);
790 791
	}

792
	private function _monitorIspConfigLog() {
793
		global $app;
794

795
		/*
796 797 798
		 * First we get the Monitoring-data from the tools
		 */
		$res = $this->_tools->monitorIspConfigLog();
799

800 801 802
		/*
		 * Insert the data into the database
		 */
803
		$sql = 'REPLACE INTO monitor_data (server_id, type, created, data, state) ' .
804 805 806 807 808 809 810
			'VALUES (' .
			$res['server_id'] . ', ' .
			"'" . $app->dbmaster->quote($res['type']) . "', " .
			'UNIX_TIMESTAMP(), ' .
			"'" . $app->dbmaster->quote(serialize($res['data'])) . "', " .
			"'" . $res['state'] . "'" .
			')';
811 812 813
		$app->dbmaster->query($sql);

		/* The new data is written, now we can delete the old one */
vogelor's avatar
vogelor committed
814
		$this->_delOldRecords($res['type'], $res['server_id']);
815 816
	}

817 818 819 820 821
	/**
	 * Deletes Records older than 4 minutes.
	 * The monitor writes new data every 5 minutes or longer (4 hour, 1 day).
	 * So if i delete all Date older than 4 minutes i can be sure, that all old data
	 * are deleted...
822
	 */
823
	private function _delOldRecords($type, $serverId) {