From b5715fb4a82d6494e6fba5ffcc1b0af3c9d2421c Mon Sep 17 00:00:00 2001 From: cfoe <cfoe@ispconfig3> Date: Sat, 07 Jul 2012 13:12:41 -0400 Subject: [PATCH] removed hardcoded width for list search_limit select-element -> css defined --- server/mods-available/monitor_core_module.inc.php | 183 ++++++++++++++++++++++++++++++++------------- 1 files changed, 128 insertions(+), 55 deletions(-) diff --git a/server/mods-available/monitor_core_module.inc.php b/server/mods-available/monitor_core_module.inc.php index 4a6d341..2bc95d8 100644 --- a/server/mods-available/monitor_core_module.inc.php +++ b/server/mods-available/monitor_core_module.inc.php @@ -76,6 +76,7 @@ */ // TODO: what monitoring is done should be a config-var private function _doMonitor() { + global $app; /* * We need the tools in almost every method, so initialize them once... */ @@ -85,6 +86,7 @@ /* * Calls the single Monitoring steps */ + $this->_monitorEmailQuota(); $this->_monitorHDQuota(); $this->_monitorServer(); $this->_monitorOsVer(); @@ -110,8 +112,45 @@ $this->_monitorRaid(); $this->_monitorRkHunter(); $this->_monitorFail2ban(); + $this->_monitorIPTables(); $this->_monitorSysLog(); } + + private function _monitorEmailQuota() { + global $app, $conf; + + /* + * This monitoring is expensive, so do it only every 15 minutes + */ + $min = @date('i'); + if ($min % 15 != 0) return; + + $app->uses('getconf'); + $mail_config = $app->getconf->get_server_config($conf['server_id'], 'mail'); + if($mail_config['mailbox_quota_stats'] == 'n') return; + + + /* + * First we get the Monitoring-data from the tools + */ + $res = $this->_tools->monitorEmailQuota(); + + /* + * Insert the data into the database + */ + $sql = 'INSERT 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']); + } private function _monitorHDQuota() { global $app; @@ -128,14 +167,14 @@ 'VALUES (' . $res['server_id'] . ', ' . "'" . $app->dbmaster->quote($res['type']) . "', " . - time() . ', ' . + '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($type, $res['server_id']); + $this->_delOldRecords($res['type'], $res['server_id']); } private function _monitorServer() { @@ -153,14 +192,14 @@ 'VALUES (' . $res['server_id'] . ', ' . "'" . $app->dbmaster->quote($res['type']) . "', " . - time() . ', ' . + '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($type, $res['server_id']); + $this->_delOldRecords($res['type'], $res['server_id']); } private function _monitorOsVer() { @@ -178,14 +217,14 @@ 'VALUES (' . $res['server_id'] . ', ' . "'" . $app->dbmaster->quote($res['type']) . "', " . - time() . ', ' . + '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($type, $res['server_id']); + $this->_delOldRecords($res['type'], $res['server_id']); } private function _monitorIspcVer() { @@ -203,14 +242,14 @@ 'VALUES (' . $res['server_id'] . ', ' . "'" . $app->dbmaster->quote($res['type']) . "', " . - time() . ', ' . + '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($type, $res['server_id']); + $this->_delOldRecords($res['type'], $res['server_id']); } private function _monitorDiskUsage() { @@ -228,14 +267,14 @@ 'VALUES (' . $res['server_id'] . ', ' . "'" . $app->dbmaster->quote($res['type']) . "', " . - time() . ', ' . + '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($type, $res['server_id']); + $this->_delOldRecords($res['type'], $res['server_id']); } private function _monitorMemUsage() { @@ -252,14 +291,14 @@ 'VALUES (' . $res['server_id'] . ', ' . "'" . $app->dbmaster->quote($res['type']) . "', " . - time() . ', ' . + '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($type, $res['server_id']); + $this->_delOldRecords($res['type'], $res['server_id']); } private function _monitorCpu() { @@ -276,14 +315,14 @@ 'VALUES (' . $res['server_id'] . ', ' . "'" . $app->dbmaster->quote($res['type']) . "', " . - time() . ', ' . + '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($type, $res['server_id']); + $this->_delOldRecords($res['type'], $res['server_id']); } private function _monitorServices() { @@ -301,14 +340,14 @@ 'VALUES (' . $res['server_id'] . ', ' . "'" . $app->dbmaster->quote($res['type']) . "', " . - time() . ', ' . + '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($type, $res['server_id']); + $this->_delOldRecords($res['type'], $res['server_id']); } private function _monitorOpenVzHost() { @@ -326,14 +365,14 @@ 'VALUES (' . $res['server_id'] . ', ' . "'" . $app->dbmaster->quote($res['type']) . "', " . - time() . ', ' . + '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($type, $res['server_id']); + $this->_delOldRecords($res['type'], $res['server_id']); } private function _monitorOpenVzUserBeancounter() { @@ -351,21 +390,21 @@ 'VALUES (' . $res['server_id'] . ', ' . "'" . $app->dbmaster->quote($res['type']) . "', " . - time() . ', ' . + '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($type, $res['server_id']); + $this->_delOldRecords($res['type'], $res['server_id']); } private function _monitorSystemUpdate() { /* * This monitoring is expensive, so do it only once an hour */ - $min = date('i'); + $min = @date('i'); if ($min != 0) return; @@ -378,6 +417,9 @@ * First we get the Monitoring-data from the tools */ $res = $this->_tools->monitorSystemUpdate(); + + //* Ensure that output is encoded so that it does not break the serialize + $res['data']['output'] = htmlentities($res['data']['output']); /* * Insert the data into the database @@ -386,14 +428,14 @@ 'VALUES (' . $res['server_id'] . ', ' . "'" . $app->dbmaster->quote($res['type']) . "', " . - time() . ', ' . + '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($type, $res['server_id']); + $this->_delOldRecords($res['type'], $res['server_id']); } private function _monitorMailQueue() { @@ -411,14 +453,14 @@ 'VALUES (' . $res['server_id'] . ', ' . "'" . $app->dbmaster->quote($res['type']) . "', " . - time() . ', ' . + '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($type, $res['server_id']); + $this->_delOldRecords($res['type'], $res['server_id']); } private function _monitorRaid() { @@ -436,22 +478,22 @@ 'VALUES (' . $res['server_id'] . ', ' . "'" . $app->dbmaster->quote($res['type']) . "', " . - time() . ', ' . + '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($type, $res['server_id']); + $this->_delOldRecords($res['type'], $res['server_id']); } private function _monitorRkHunter() { /* * This monitoring is expensive, so do it only once a day */ - $min = date('i'); - $hour = date('H'); + $min = @date('i'); + $hour = @date('H'); if (!($min == 0 && $hour == 23)) return; /* @@ -471,23 +513,49 @@ 'VALUES (' . $res['server_id'] . ', ' . "'" . $app->dbmaster->quote($res['type']) . "', " . - time() . ', ' . + '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($type, $res['server_id']); + $this->_delOldRecords($res['type'], $res['server_id']); } private function _monitorFail2ban() { + global $app; + + /* + * First we get the Monitoring-data from the tools + */ + $res = $this->_tools->monitorFail2ban(); + + /* + * Insert the data into the database + */ + $sql = 'INSERT 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']); + } + + + private function _monitorIPTables() { global $app; /* * First we get the Monitoring-data from the tools */ - $res = $this->_tools->monitorFail2ban(); + $res = $this->_tools->monitorIPTables(); /* * Insert the data into the database @@ -496,14 +564,14 @@ 'VALUES (' . $res['server_id'] . ', ' . "'" . $app->dbmaster->quote($res['type']) . "', " . - time() . ', ' . + '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($type, $res['server_id']); + $this->_delOldRecords($res['type'], $res['server_id']); } private function _monitorSysLog() { @@ -521,14 +589,14 @@ 'VALUES (' . $res['server_id'] . ', ' . "'" . $app->dbmaster->quote($res['type']) . "', " . - time() . ', ' . + '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($type, $res['server_id']); + $this->_delOldRecords($res['type'], $res['server_id']); } private function _monitorMailLog() { @@ -546,14 +614,14 @@ 'VALUES (' . $res['server_id'] . ', ' . "'" . $app->dbmaster->quote($res['type']) . "', " . - time() . ', ' . + '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($type, $res['server_id']); + $this->_delOldRecords($res['type'], $res['server_id']); } private function _monitorMailWarnLog() { @@ -571,14 +639,14 @@ 'VALUES (' . $res['server_id'] . ', ' . "'" . $app->dbmaster->quote($res['type']) . "', " . - time() . ', ' . + '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($type, $res['server_id']); + $this->_delOldRecords($res['type'], $res['server_id']); } private function _monitorMailErrLog() { @@ -596,14 +664,14 @@ 'VALUES (' . $res['server_id'] . ', ' . "'" . $app->dbmaster->quote($res['type']) . "', " . - time() . ', ' . + '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($type, $res['server_id']); + $this->_delOldRecords($res['type'], $res['server_id']); } private function _monitorMessagesLog() { @@ -621,14 +689,14 @@ 'VALUES (' . $res['server_id'] . ', ' . "'" . $app->dbmaster->quote($res['type']) . "', " . - time() . ', ' . + '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($type, $res['server_id']); + $this->_delOldRecords($res['type'], $res['server_id']); } private function _monitorISPCCronLog() { @@ -638,6 +706,9 @@ * First we get the Monitoring-data from the tools */ $res = $this->_tools->monitorISPCCronLog(); + + //* Ensure that output is encoded so that it does not break the serialize + $res['data']['output'] = htmlentities($res['data']['output']); /* * Insert the data into the database @@ -646,14 +717,14 @@ 'VALUES (' . $res['server_id'] . ', ' . "'" . $app->dbmaster->quote($res['type']) . "', " . - time() . ', ' . + '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($type, $res['server_id']); + $this->_delOldRecords($res['type'], $res['server_id']); } private function _monitorFreshClamLog() { @@ -671,14 +742,14 @@ 'VALUES (' . $res['server_id'] . ', ' . "'" . $app->dbmaster->quote($res['type']) . "', " . - time() . ', ' . + '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($type, $res['server_id']); + $this->_delOldRecords($res['type'], $res['server_id']); } private function _monitorClamAvLog() { @@ -696,14 +767,14 @@ 'VALUES (' . $res['server_id'] . ', ' . "'" . $app->dbmaster->quote($res['type']) . "', " . - time() . ', ' . + '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($type, $res['server_id']); + $this->_delOldRecords($res['type'], $res['server_id']); } private function _monitorIspConfigLog() { @@ -721,14 +792,14 @@ 'VALUES (' . $res['server_id'] . ', ' . "'" . $app->dbmaster->quote($res['type']) . "', " . - time() . ', ' . + '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($type, $res['server_id']); + $this->_delOldRecords($res['type'], $res['server_id']); } /** @@ -740,8 +811,10 @@ private function _delOldRecords($type, $serverId) { global $app; - $now = time(); - $old = $now - (4 * 60); // 4 minutes + // $now = time(); + // $old = $now - (4 * 60); // 4 minutes + $old = 'UNIX_TIMESTAMP() - 240'; + /* * ATTENTION if i do NOT pay attention of the server id, i delete all data (of the type) * of ALL servers. This means, if i have a multiserver-environment and a server has a @@ -762,4 +835,4 @@ } -?> +?> \ No newline at end of file -- Gitblit v1.9.1