tbrehm
2012-01-02 49a4ebff7c069a34fb1c9967aab06486b75735e0
server/mods-available/monitor_core_module.inc.php
@@ -86,6 +86,7 @@
      /*
       * Calls the single Monitoring steps 
       */
      $this->_monitorEmailQuota();
      $this->_monitorHDQuota();
      $this->_monitorServer();
      $this->_monitorOsVer();
@@ -111,8 +112,41 @@
      $this->_monitorRaid();
      $this->_monitorRkHunter();
      $this->_monitorFail2ban();
      $this->_monitorIPTables();
      $this->_monitorSysLog();
   }
    private function _monitorEmailQuota() {
        global $app;
        /*
       *  This monitoring is expensive, so do it only every 15 minutes
       */
      $min = @date('i');
      if ($min % 15 != 0) 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;
@@ -129,14 +163,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() {
@@ -154,14 +188,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() {
@@ -179,14 +213,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() {
@@ -204,14 +238,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() {
@@ -229,14 +263,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() {
@@ -253,14 +287,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() {
@@ -277,14 +311,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() {
@@ -302,14 +336,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() {
@@ -327,14 +361,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() {
@@ -352,21 +386,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;
@@ -379,6 +413,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
@@ -387,14 +424,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() {
@@ -412,14 +449,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() {
@@ -437,22 +474,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;
      /*
@@ -472,23 +509,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
@@ -497,14 +560,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() {
@@ -522,14 +585,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() {
@@ -547,14 +610,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() {
@@ -572,14 +635,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() {
@@ -597,14 +660,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() {
@@ -622,14 +685,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() {
@@ -639,6 +702,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
@@ -647,14 +713,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() {
@@ -672,14 +738,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() {
@@ -697,14 +763,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() {
@@ -722,14 +788,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']);
   }
   /**
@@ -763,4 +829,4 @@
}
?>
?>