| | |
| | | global $app; |
| | | |
| | | /* |
| | | Annonce the actions that where provided by this module, so plugins |
| | | can register on them. |
| | | */ |
| | | /* none at them moment */ |
| | | //$app->plugins->announceEvents($this->module_name,$this->actions_available); |
| | | |
| | | /* |
| | | As we want to get notified of any changes on several database tables, |
| | | we register for them. |
| | | |
| | | The following function registers the function "functionname" |
| | | to be executed when a record for the table "dbtable" is |
| | | processed in the sys_datalog. "classname" is the name of the |
| | | class that contains the function functionname. |
| | | */ |
| | | /* none at them moment */ |
| | | //$app->modules->registerTableHook('mail_access','mail_module','process'); |
| | | |
| | | /* |
| | | Do the monitor every n minutes and write the result in the db |
| | | * Do the monitor every n minutes and write the result to the db |
| | | */ |
| | | $min = date('i'); |
| | | if (($min % $this->interval) == 0) { |
| | |
| | | The function then raises the events for the plugins. |
| | | */ |
| | | function process($tablename, $action, $data) { |
| | | // global $app; |
| | | // |
| | | // switch ($tablename) { |
| | | // case 'mail_access': |
| | | // if($action == 'i') $app->plugins->raiseEvent('mail_access_insert',$data); |
| | | // if($action == 'u') $app->plugins->raiseEvent('mail_access_update',$data); |
| | | // if($action == 'd') $app->plugins->raiseEvent('mail_access_delete',$data); |
| | | // break; |
| | | // } // end switch |
| | | // not needed |
| | | } // end function |
| | | |
| | | //** Get distribution identifier |
| | |
| | | $this->monitorMemUsage(); |
| | | $this->monitorCpu(); |
| | | $this->monitorServices(); |
| | | $this->monitorOpenVzHost(); |
| | | $this->monitorOpenVzUserBeancounter(); |
| | | $this->monitorMailLog(); |
| | | $this->monitorMailWarnLog(); |
| | | $this->monitorMailErrLog(); |
| | |
| | | $app->dbmaster->query($sql); |
| | | |
| | | /* The new data is written, now we can delete the old one */ |
| | | $this->_delOldRecords($type, 10); |
| | | $this->_delOldRecords($type, 4); |
| | | } |
| | | |
| | | function monitorOsVer() { |
| | |
| | | $app->dbmaster->query($sql); |
| | | |
| | | /* The new data is written, now we can delete the old one */ |
| | | $this->_delOldRecords($type, 10); |
| | | $this->_delOldRecords($type, 4); |
| | | } |
| | | |
| | | |
| | | |
| | | function monitorDiskUsage() { |
| | | global $app; |
| | | global $conf; |
| | |
| | | $app->dbmaster->query($sql); |
| | | |
| | | /* The new data is written, now we can delete the old one */ |
| | | $this->_delOldRecords($type, 10); |
| | | $this->_delOldRecords($type, 4); |
| | | } |
| | | |
| | | |
| | |
| | | $app->dbmaster->query($sql); |
| | | |
| | | /* The new data is written, now we can delete the old one */ |
| | | $this->_delOldRecords($type, 10); |
| | | $this->_delOldRecords($type, 4); |
| | | } |
| | | |
| | | |
| | |
| | | $app->dbmaster->query($sql); |
| | | |
| | | /* The new data is written, now we can delete the old one */ |
| | | $this->_delOldRecords($type, 10); |
| | | $this->_delOldRecords($type, 4); |
| | | } |
| | | |
| | | |
| | |
| | | $app->dbmaster->query($sql); |
| | | |
| | | /* The new data is written, now we can delete the old one */ |
| | | $this->_delOldRecords($type, 10); |
| | | $this->_delOldRecords($type, 4); |
| | | } |
| | | |
| | | |
| | | function monitorOpenVzHost() { |
| | | global $app; |
| | | global $conf; |
| | | |
| | | /* the id of the server as int */ |
| | | $server_id = intval($conf["server_id"]); |
| | | |
| | | /** The type of the data */ |
| | | $type = 'openvz_veinfo'; |
| | | |
| | | /* |
| | | Fetch the data into a array |
| | | */ |
| | | $app->load(openvz_tools); |
| | | $openVzTools = new openvz_tools(); |
| | | $data = $openVzTools->getOpenVzVeInfo(); |
| | | |
| | | /* the VE-Info has no state. It is, what it is */ |
| | | $state = 'no_state'; |
| | | |
| | | /* |
| | | Insert the data into the database |
| | | */ |
| | | $sql = "INSERT INTO monitor_data (server_id, type, created, data, state) " . |
| | | "VALUES (". |
| | | $server_id . ", " . |
| | | "'" . $app->dbmaster->quote($type) . "', " . |
| | | time() . ", " . |
| | | "'" . $app->dbmaster->quote(serialize($data)) . "', " . |
| | | "'" . $state . "'" . |
| | | ")"; |
| | | $app->dbmaster->query($sql); |
| | | |
| | | /* The new data is written, now we can delete the old one */ |
| | | $this->_delOldRecords($type, 4); |
| | | } |
| | | |
| | | function monitorOpenVzUserBeancounter() { |
| | | global $app; |
| | | global $conf; |
| | | |
| | | /* the id of the server as int */ |
| | | $server_id = intval($conf["server_id"]); |
| | | |
| | | /** The type of the data */ |
| | | $type = 'openvz_beancounter'; |
| | | |
| | | /* |
| | | Fetch the data into a array |
| | | */ |
| | | $app->load(openvz_tools); |
| | | $openVzTools = new openvz_tools(); |
| | | $data = $openVzTools->getOpenVzVeBeanCounter(); |
| | | |
| | | /* calculate the state of the beancounter */ |
| | | if ($data == '') { |
| | | $state = 'no_state'; |
| | | } |
| | | else { |
| | | $state = 'ok'; |
| | | |
| | | /* transfer this output-string into a array */ |
| | | $test = explode("\n", $data); |
| | | |
| | | /* the first list of the output is not needed */ |
| | | array_shift($test); |
| | | |
| | | /* now process all items of the rest */ |
| | | foreach ($test as $item) { |
| | | /* |
| | | * eliminate all doubled spaces and spaces at the beginning and end |
| | | */ |
| | | while (strpos($item, ' ') !== false) { |
| | | $item = str_replace(' ', ' ', $item); |
| | | } |
| | | $item = trim($item); |
| | | |
| | | /* |
| | | * The failcounter is the LAST |
| | | */ |
| | | if ($item != '') { |
| | | $tmp = explode(' ', $item); |
| | | $failCounter = $tmp[sizeof($tmp)-1]; |
| | | if ($failCounter > 0 ) $state = 'info'; |
| | | if ($failCounter > 50 ) $state = 'warning'; |
| | | if ($failCounter > 200 ) $state = 'critical'; |
| | | if ($failCounter > 10000 ) $state = 'error'; |
| | | } |
| | | } |
| | | } |
| | | |
| | | /* |
| | | Insert the data into the database |
| | | */ |
| | | $sql = "INSERT INTO monitor_data (server_id, type, created, data, state) " . |
| | | "VALUES (". |
| | | $server_id . ", " . |
| | | "'" . $app->dbmaster->quote($type) . "', " . |
| | | time() . ", " . |
| | | "'" . $app->dbmaster->quote(serialize($data)) . "', " . |
| | | "'" . $state . "'" . |
| | | ")"; |
| | | $app->dbmaster->query($sql); |
| | | |
| | | /* The new data is written, now we can delete the old one */ |
| | | $this->_delOldRecords($type, 4); |
| | | } |
| | | |
| | | |
| | |
| | | $state = 'ok'; |
| | | } |
| | | else { |
| | | /* There is something to update! */ |
| | | $state = 'warning'; |
| | | /* |
| | | * There is something to update! this is in most cases not critical, so we can |
| | | * do a system-update once a month or so... |
| | | */ |
| | | $state = 'info'; |
| | | } |
| | | |
| | | /* |
| | |
| | | $app->dbmaster->query($sql); |
| | | |
| | | /* The new data is written, now we can delete the old one */ |
| | | $this->_delOldRecords($type, 0, 2); |
| | | $this->_delOldRecords($type, 4); |
| | | } |
| | | |
| | | function monitorMailQueue() { |
| | |
| | | $app->dbmaster->query($sql); |
| | | |
| | | /* The new data is written, now we can delete the old one */ |
| | | $this->_delOldRecords($type, 10); |
| | | $this->_delOldRecords($type, 4); |
| | | } |
| | | |
| | | |
| | |
| | | $type = 'raid_state'; |
| | | |
| | | /* This monitoring is only available if mdadm is installed */ |
| | | $location = system('which mdadm', $retval); |
| | | system('which mdadm', $retval); |
| | | if($retval === 0) { |
| | | /* |
| | | * Fetch the output |
| | |
| | | $app->dbmaster->query($sql); |
| | | |
| | | /* The new data is written, now we can delete the old one */ |
| | | $this->_delOldRecords($type, 10); |
| | | $this->_delOldRecords($type, 4); |
| | | } |
| | | |
| | | function monitorRkHunter() { |
| | |
| | | $type = 'rkhunter'; |
| | | |
| | | /* This monitoring is only available if rkhunter is installed */ |
| | | $location = system('which rkhunter', $retval); |
| | | system('which rkhunter', $retval); |
| | | if($retval === 0) { |
| | | /* |
| | | * Fetch the output |
| | |
| | | $app->dbmaster->query($sql); |
| | | |
| | | /* The new data is written, now we can delete the old one */ |
| | | $this->_delOldRecords($type, 0, 2); |
| | | $this->_delOldRecords($type, 4); |
| | | } |
| | | |
| | | function monitorFail2ban() { |
| | |
| | | $type = 'log_fail2ban'; |
| | | |
| | | /* This monitoring is only available if fail2ban is installed */ |
| | | $location = system('which fail2ban-client', $retval); // Debian, Ubuntu, Fedora |
| | | if($retval !== 0) $location = system('which fail2ban', $retval); // CentOS |
| | | system('which fail2ban-client', $retval); // Debian, Ubuntu, Fedora |
| | | if($retval !== 0) system('which fail2ban', $retval); // CentOS |
| | | if($retval === 0) { |
| | | /* Get the data of the log */ |
| | | $data = $this->_getLogData($type); |
| | |
| | | $app->dbmaster->query($sql); |
| | | |
| | | /* The new data is written, now we can delete the old one */ |
| | | $this->_delOldRecords($type, 10); |
| | | $this->_delOldRecords($type, 4); |
| | | } |
| | | |
| | | function monitorSysLog() { |
| | |
| | | $app->dbmaster->query($sql); |
| | | |
| | | /* The new data is written, now we can delete the old one */ |
| | | $this->_delOldRecords($type, 10); |
| | | $this->_delOldRecords($type, 4); |
| | | } |
| | | |
| | | function monitorMailLog() { |
| | |
| | | $app->dbmaster->query($sql); |
| | | |
| | | /* The new data is written, now we can delete the old one */ |
| | | $this->_delOldRecords($type, 10); |
| | | $this->_delOldRecords($type, 4); |
| | | } |
| | | |
| | | function monitorMailWarnLog() { |
| | |
| | | $app->dbmaster->query($sql); |
| | | |
| | | /* The new data is written, now we can delete the old one */ |
| | | $this->_delOldRecords($type, 10); |
| | | $this->_delOldRecords($type, 4); |
| | | } |
| | | |
| | | function monitorMailErrLog() { |
| | |
| | | $app->dbmaster->query($sql); |
| | | |
| | | /* The new data is written, now we can delete the old one */ |
| | | $this->_delOldRecords($type, 10); |
| | | $this->_delOldRecords($type, 4); |
| | | } |
| | | |
| | | |
| | |
| | | $app->dbmaster->query($sql); |
| | | |
| | | /* The new data is written, now we can delete the old one */ |
| | | $this->_delOldRecords($type, 10); |
| | | $this->_delOldRecords($type, 4); |
| | | } |
| | | |
| | | function monitorISPCCronLog() { |
| | |
| | | $app->dbmaster->query($sql); |
| | | |
| | | /* The new data is written, now we can delete the old one */ |
| | | $this->_delOldRecords($type, 10); |
| | | $this->_delOldRecords($type, 4); |
| | | } |
| | | |
| | | function monitorFreshClamLog() { |
| | |
| | | */ |
| | | foreach($lastLog as $line) { |
| | | if (strpos(strtolower($line), "outdated") !== false) { |
| | | $state = $this->_setState($state, 'warning'); |
| | | /* |
| | | * Outdatet is only info, because if we set this to warning, the server is |
| | | * as long in state warning, as there is a new version of ClamAv which takes |
| | | * sometimes weeks! |
| | | */ |
| | | $state = $this->_setState($state, 'info'); |
| | | } |
| | | } |
| | | |
| | |
| | | $app->dbmaster->query($sql); |
| | | |
| | | /* The new data is written, now we can delete the old one */ |
| | | $this->_delOldRecords($type, 10); |
| | | $this->_delOldRecords($type, 4); |
| | | } |
| | | |
| | | function monitorClamAvLog() { |
| | |
| | | $app->dbmaster->query($sql); |
| | | |
| | | /* The new data is written, now we can delete the old one */ |
| | | $this->_delOldRecords($type, 10); |
| | | $this->_delOldRecords($type, 4); |
| | | } |
| | | |
| | | function monitorIspConfigLog() { |
| | |
| | | $app->dbmaster->query($sql); |
| | | |
| | | /* The new data is written, now we can delete the old one */ |
| | | $this->_delOldRecords($type, 10); |
| | | $this->_delOldRecords($type, 4); |
| | | } |
| | | |
| | | |