tbrehm
2011-12-15 e589cc1dbb43111f7b7ecf21c99820baa8b7f45c
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,7 +163,7 @@
            'VALUES (' .
            $res['server_id'] . ', ' .
            "'" . $app->dbmaster->quote($res['type']) . "', " .
            time() . ', ' .
            'UNIX_TIMESTAMP(), ' .
            "'" . $app->dbmaster->quote(serialize($res['data'])) . "', " .
            "'" . $res['state'] . "'" .
            ')';
@@ -154,7 +188,7 @@
            'VALUES (' .
            $res['server_id'] . ', ' .
            "'" . $app->dbmaster->quote($res['type']) . "', " .
            time() . ', ' .
            'UNIX_TIMESTAMP(), ' .
            "'" . $app->dbmaster->quote(serialize($res['data'])) . "', " .
            "'" . $res['state'] . "'" .
            ')';
@@ -179,7 +213,7 @@
            'VALUES (' .
            $res['server_id'] . ', ' .
            "'" . $app->dbmaster->quote($res['type']) . "', " .
            time() . ', ' .
            'UNIX_TIMESTAMP(), ' .
            "'" . $app->dbmaster->quote(serialize($res['data'])) . "', " .
            "'" . $res['state'] . "'" .
            ')';
@@ -204,7 +238,7 @@
            'VALUES (' .
            $res['server_id'] . ', ' .
            "'" . $app->dbmaster->quote($res['type']) . "', " .
            time() . ', ' .
            'UNIX_TIMESTAMP(), ' .
            "'" . $app->dbmaster->quote(serialize($res['data'])) . "', " .
            "'" . $res['state'] . "'" .
            ')';
@@ -229,7 +263,7 @@
            'VALUES (' .
            $res['server_id'] . ', ' .
            "'" . $app->dbmaster->quote($res['type']) . "', " .
            time() . ', ' .
            'UNIX_TIMESTAMP(), ' .
            "'" . $app->dbmaster->quote(serialize($res['data'])) . "', " .
            "'" . $res['state'] . "'" .
            ')';
@@ -253,7 +287,7 @@
            'VALUES (' .
            $res['server_id'] . ', ' .
            "'" . $app->dbmaster->quote($res['type']) . "', " .
            time() . ', ' .
            'UNIX_TIMESTAMP(), ' .
            "'" . $app->dbmaster->quote(serialize($res['data'])) . "', " .
            "'" . $res['state'] . "'" .
            ')';
@@ -277,7 +311,7 @@
            'VALUES (' .
            $res['server_id'] . ', ' .
            "'" . $app->dbmaster->quote($res['type']) . "', " .
            time() . ', ' .
            'UNIX_TIMESTAMP(), ' .
            "'" . $app->dbmaster->quote(serialize($res['data'])) . "', " .
            "'" . $res['state'] . "'" .
            ')';
@@ -302,7 +336,7 @@
            'VALUES (' .
            $res['server_id'] . ', ' .
            "'" . $app->dbmaster->quote($res['type']) . "', " .
            time() . ', ' .
            'UNIX_TIMESTAMP(), ' .
            "'" . $app->dbmaster->quote(serialize($res['data'])) . "', " .
            "'" . $res['state'] . "'" .
            ')';
@@ -327,7 +361,7 @@
            'VALUES (' .
            $res['server_id'] . ', ' .
            "'" . $app->dbmaster->quote($res['type']) . "', " .
            time() . ', ' .
            'UNIX_TIMESTAMP(), ' .
            "'" . $app->dbmaster->quote(serialize($res['data'])) . "', " .
            "'" . $res['state'] . "'" .
            ')';
@@ -352,7 +386,7 @@
            'VALUES (' .
            $res['server_id'] . ', ' .
            "'" . $app->dbmaster->quote($res['type']) . "', " .
            time() . ', ' .
            'UNIX_TIMESTAMP(), ' .
            "'" . $app->dbmaster->quote(serialize($res['data'])) . "', " .
            "'" . $res['state'] . "'" .
            ')';
@@ -366,7 +400,7 @@
      /*
       *  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,7 +424,7 @@
            'VALUES (' .
            $res['server_id'] . ', ' .
            "'" . $app->dbmaster->quote($res['type']) . "', " .
            time() . ', ' .
            'UNIX_TIMESTAMP(), ' .
            "'" . $app->dbmaster->quote(serialize($res['data'])) . "', " .
            "'" . $res['state'] . "'" .
            ')';
@@ -412,7 +449,7 @@
            'VALUES (' .
            $res['server_id'] . ', ' .
            "'" . $app->dbmaster->quote($res['type']) . "', " .
            time() . ', ' .
            'UNIX_TIMESTAMP(), ' .
            "'" . $app->dbmaster->quote(serialize($res['data'])) . "', " .
            "'" . $res['state'] . "'" .
            ')';
@@ -437,7 +474,7 @@
            'VALUES (' .
            $res['server_id'] . ', ' .
            "'" . $app->dbmaster->quote($res['type']) . "', " .
            time() . ', ' .
            'UNIX_TIMESTAMP(), ' .
            "'" . $app->dbmaster->quote(serialize($res['data'])) . "', " .
            "'" . $res['state'] . "'" .
            ')';
@@ -451,8 +488,8 @@
      /*
       *  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,7 +509,7 @@
            'VALUES (' .
            $res['server_id'] . ', ' .
            "'" . $app->dbmaster->quote($res['type']) . "', " .
            time() . ', ' .
            'UNIX_TIMESTAMP(), ' .
            "'" . $app->dbmaster->quote(serialize($res['data'])) . "', " .
            "'" . $res['state'] . "'" .
            ')';
@@ -483,12 +520,38 @@
   }
   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,7 +560,7 @@
            'VALUES (' .
            $res['server_id'] . ', ' .
            "'" . $app->dbmaster->quote($res['type']) . "', " .
            time() . ', ' .
            'UNIX_TIMESTAMP(), ' .
            "'" . $app->dbmaster->quote(serialize($res['data'])) . "', " .
            "'" . $res['state'] . "'" .
            ')';
@@ -522,7 +585,7 @@
            'VALUES (' .
            $res['server_id'] . ', ' .
            "'" . $app->dbmaster->quote($res['type']) . "', " .
            time() . ', ' .
            'UNIX_TIMESTAMP(), ' .
            "'" . $app->dbmaster->quote(serialize($res['data'])) . "', " .
            "'" . $res['state'] . "'" .
            ')';
@@ -547,7 +610,7 @@
            'VALUES (' .
            $res['server_id'] . ', ' .
            "'" . $app->dbmaster->quote($res['type']) . "', " .
            time() . ', ' .
            'UNIX_TIMESTAMP(), ' .
            "'" . $app->dbmaster->quote(serialize($res['data'])) . "', " .
            "'" . $res['state'] . "'" .
            ')';
@@ -572,7 +635,7 @@
            'VALUES (' .
            $res['server_id'] . ', ' .
            "'" . $app->dbmaster->quote($res['type']) . "', " .
            time() . ', ' .
            'UNIX_TIMESTAMP(), ' .
            "'" . $app->dbmaster->quote(serialize($res['data'])) . "', " .
            "'" . $res['state'] . "'" .
            ')';
@@ -597,7 +660,7 @@
            'VALUES (' .
            $res['server_id'] . ', ' .
            "'" . $app->dbmaster->quote($res['type']) . "', " .
            time() . ', ' .
            'UNIX_TIMESTAMP(), ' .
            "'" . $app->dbmaster->quote(serialize($res['data'])) . "', " .
            "'" . $res['state'] . "'" .
            ')';
@@ -622,7 +685,7 @@
            'VALUES (' .
            $res['server_id'] . ', ' .
            "'" . $app->dbmaster->quote($res['type']) . "', " .
            time() . ', ' .
            'UNIX_TIMESTAMP(), ' .
            "'" . $app->dbmaster->quote(serialize($res['data'])) . "', " .
            "'" . $res['state'] . "'" .
            ')';
@@ -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,7 +713,7 @@
            'VALUES (' .
            $res['server_id'] . ', ' .
            "'" . $app->dbmaster->quote($res['type']) . "', " .
            time() . ', ' .
            'UNIX_TIMESTAMP(), ' .
            "'" . $app->dbmaster->quote(serialize($res['data'])) . "', " .
            "'" . $res['state'] . "'" .
            ')';
@@ -672,7 +738,7 @@
            'VALUES (' .
            $res['server_id'] . ', ' .
            "'" . $app->dbmaster->quote($res['type']) . "', " .
            time() . ', ' .
            'UNIX_TIMESTAMP(), ' .
            "'" . $app->dbmaster->quote(serialize($res['data'])) . "', " .
            "'" . $res['state'] . "'" .
            ')';
@@ -697,7 +763,7 @@
            'VALUES (' .
            $res['server_id'] . ', ' .
            "'" . $app->dbmaster->quote($res['type']) . "', " .
            time() . ', ' .
            'UNIX_TIMESTAMP(), ' .
            "'" . $app->dbmaster->quote(serialize($res['data'])) . "', " .
            "'" . $res['state'] . "'" .
            ')';
@@ -722,7 +788,7 @@
            'VALUES (' .
            $res['server_id'] . ', ' .
            "'" . $app->dbmaster->quote($res['type']) . "', " .
            time() . ', ' .
            'UNIX_TIMESTAMP(), ' .
            "'" . $app->dbmaster->quote(serialize($res['data'])) . "', " .
            "'" . $res['state'] . "'" .
            ')';
@@ -763,4 +829,4 @@
}
?>
?>