interval) == 0) { $this->_doMonitor(); } } /** * 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) { // not needed } /** * This method is called every n minutes, when the module ist loaded. * The method then does a system-monitoring */ // TODO: what monitoring is done should be a config-var private function _doMonitor() { /* * We need the tools in almost every method, so initialize them once... */ $app->load('monitor_tools'); $this->_tools = new monitor_tools(); /* * Calls the single Monitoring steps */ $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(); $this->_monitorSysLog(); } private function _monitorHDQuota() { global $app; /* * First we get the Monitoring-data from the tools */ $res = $this->_tools->monitorHDQuota(); /* * 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']) . "', " . time() . ', ' . "'" . $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, 4); } private function _monitorServer() { global $app; /* * First we get the Monitoring-data from the tools */ $res = $this->_tools->monitorServer(); /* * 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']) . "', " . time() . ', ' . "'" . $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, 4); } private function _monitorOsVer() { global $app; /* * First we get the Monitoring-data from the tools */ $res = $this->_tools->monitorOsVer(); /* * 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']) . "', " . time() . ', ' . "'" . $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, 4); } private function _monitorIspcVer() { global $app; /* * First we get the Monitoring-data from the tools */ $res = $this->_tools->monitorIspcVer(); /* * 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']) . "', " . time() . ', ' . "'" . $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, 4); } private function _monitorDiskUsage() { global $app; /* * First we get the Monitoring-data from the tools */ $res = $this->_tools->monitorDiskUsage(); /* * 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']) . "', " . time() . ', ' . "'" . $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, 4); } private function _monitorMemUsage() { global $app; /* * First we get the Monitoring-data from the tools */ $res = $this->_tools->monitorMemUsage(); /* * 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']) . "', " . time() . ', ' . "'" . $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, 4); } private function _monitorCpu() { global $app; /* * First we get the Monitoring-data from the tools */ $res = $this->_tools->monitorCpu(); /* * 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']) . "', " . time() . ', ' . "'" . $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, 4); } private function _monitorServices() { global $app; /* * First we get the Monitoring-data from the tools */ $res = $this->_tools->monitorServices(); /* * 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']) . "', " . time() . ', ' . "'" . $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, 4); } private function _monitorOpenVzHost() { global $app; /* * First we get the Monitoring-data from the tools */ $res = $this->_tools->monitorOpenVzHost(); /* * 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']) . "', " . time() . ', ' . "'" . $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, 4); } private function _monitorOpenVzUserBeancounter() { global $app; /* * First we get the Monitoring-data from the tools */ $res = $this->_tools->monitorOpenVzUserBeancounter(); /* * 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']) . "', " . time() . ', ' . "'" . $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, 4); } private function _monitorSystemUpdate() { /* * This monitoring is expensive, so do it only once an hour */ $min = date('i'); if ($min != 0) return; /* * OK - here we go... */ global $app; /* * First we get the Monitoring-data from the tools */ $res = $this->_tools->monitorSystemUpdate(); /* * 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']) . "', " . time() . ', ' . "'" . $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, 4); } private function _monitorMailQueue() { global $app; /* * First we get the Monitoring-data from the tools */ $res = $this->_tools->monitorMailQueue(); /* * 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']) . "', " . time() . ', ' . "'" . $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, 4); } private function _monitorRaid() { global $app; /* * First we get the Monitoring-data from the tools */ $res = $this->_tools->monitorRaid(); /* * 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']) . "', " . time() . ', ' . "'" . $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, 4); } private function _monitorRkHunter() { /* * This monitoring is expensive, so do it only once a day */ $min = date('i'); $hour = date('H'); if (!($min == 0 && $hour == 23)) return; /* * OK . here we go... */ global $app; /* * First we get the Monitoring-data from the tools */ $res = $this->_tools->monitorRkHunter(); /* * 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']) . "', " . time() . ', ' . "'" . $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, 4); } 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']) . "', " . time() . ', ' . "'" . $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, 4); } private function _monitorSysLog() { global $app; /* * First we get the Monitoring-data from the tools */ $res = $this->_tools->monitorSysLog(); /* * 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']) . "', " . time() . ', ' . "'" . $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, 4); } private function _monitorMailLog() { global $app; /* * First we get the Monitoring-data from the tools */ $res = $this->_tools->monitorMailLog(); /* * 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']) . "', " . time() . ', ' . "'" . $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, 4); } private function _monitorMailWarnLog() { global $app; /* * First we get the Monitoring-data from the tools */ $res = $this->_tools->monitorMailWarnLog(); /* * 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']) . "', " . time() . ', ' . "'" . $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, 4); } private function _monitorMailErrLog() { global $app; /* * First we get the Monitoring-data from the tools */ $res = $this->_tools->monitorMailErrLog(); /* * 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']) . "', " . time() . ', ' . "'" . $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, 4); } private function _monitorMessagesLog() { global $app; /* * First we get the Monitoring-data from the tools */ $res = $this->_tools->monitorMessagesLog(); /* * 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']) . "', " . time() . ', ' . "'" . $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, 4); } private function _monitorISPCCronLog() { global $app; /* * First we get the Monitoring-data from the tools */ $res = $this->_tools->monitorISPCCronLog(); /* * 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']) . "', " . time() . ', ' . "'" . $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, 4); } private function _monitorFreshClamLog() { global $app; /* * First we get the Monitoring-data from the tools */ $res = $this->_tools->monitorFreshClamLog(); /* * 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']) . "', " . time() . ', ' . "'" . $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, 4); } private function _monitorClamAvLog() { global $app; /* * First we get the Monitoring-data from the tools */ $res = $this->_tools->monitorClamAvLog(); /* * 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']) . "', " . time() . ', ' . "'" . $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, 4); } private function _monitorIspConfigLog() { global $app; /* * First we get the Monitoring-data from the tools */ $res = $this->_tools->monitorIspConfigLog(); /* * 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']) . "', " . time() . ', ' . "'" . $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, 4); } /* Deletes Records older than n. */ private function _delOldRecords($type, $min, $hour=0, $days=0) { global $app; $now = time(); $old = $now - ($min * 60) - ($hour * 60 * 60) - ($days * 24 * 60 * 60); $sql = 'DELETE FROM monitor_data ' . 'WHERE ' . 'type =' . "'" . $app->dbmaster->quote($type) . "' " . 'AND ' . 'created < ' . $old; $app->dbmaster->query($sql); } } ?>