tbrehm
2010-09-16 2a3cab868b81cdaca3d30e88f0550a96f298c53b
server/mods-available/monitor_core_module.inc.php
@@ -69,8 +69,8 @@
   //** Get distribution identifier
   //** IMPORTANT!
   //   This is the same code as in /install/install.php
   //   So if you change it here, you also have to change it in /install/install.php!
   //   This is the same code as in install/lib/install.lib.php
   //   So if you change it here, you also have to change it in there!
   //   Please do not forget to remove the swriteln(); - lines here at this file
   function get_distname() {
@@ -181,7 +181,7 @@
         $distbaseid = 'gentoo';
      } else {
         die('unrecognized linux distribution');
         die('unrecognized Linux distribution');
      }
      return array('name' => $distname, 'version' => $distver, 'id' => $distid, 'baseid' => $distbaseid);
@@ -195,6 +195,7 @@
   // TODO: what monitoring is done should be a config-var
   function doMonitor() {
      /* Calls the single Monitoring steps */
      $this->monitorHDQuota();
      $this->monitorServer();
      $this->monitorOSVer();
      $this->monitorIspCVer();
@@ -219,7 +220,84 @@
      $this->monitorFail2ban();
      $this->monitorSysLog();
   }
   function monitorHDQuota() {
      global $app;
      global $conf;
      /* Initialize data array */
      $data = array();
      /* the id of the server as int */
      $server_id = intval($conf["server_id"]);
      /** The type of the data */
      $type = 'harddisk_quota';
      /** The state of the harddisk_quota. */
      $state = 'ok';
      /** Fetch the data for all users*/
      $dfData = shell_exec("repquota -asu");
      // split into array
      $df = explode("\n", $dfData);
      /*
         * ignore the first 5 lines, process the rest
      */
      for($i=5; $i <= sizeof($df); $i++) {
         if ($df[$i] != '') {
            /*
                 * Make a array of the data
            */
            $s = preg_split ("/[\s]+/", $df[$i]);
            $username = $s[0];
            $data['user'][$username]['used'] = $s[2];
            $data['user'][$username]['soft'] = $s[3];
            $data['user'][$username]['hard'] = $s[4];
         }
      }
      /** Fetch the data for all users*/
      $dfData = shell_exec("repquota -asg");
      // split into array
      $df = explode("\n", $dfData);
      /*
         * ignore the first 5 lines, process the rest
      */
      for($i=5; $i <= sizeof($df); $i++) {
         if ($df[$i] != '') {
            /*
                 * Make a array of the data
            */
            $s = preg_split ("/[\s]+/", $df[$i]);
            $groupname = $s[0];
            $data['group'][$groupname]['used'] = $s[1];
            $data['group'][$groupname]['soft'] = $s[2];
            $data['group'][$groupname]['hard'] = $s[3];
         }
      }
      /*
        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 monitorServer() {
      global $app;
      global $conf;
@@ -391,7 +469,7 @@
            $usePercent = floatval($data[$i]['percent']);
            //* We dont want to check the cdrom drive as a cd / dvd is always 100% full
            if($data[$i]['type'] != 'iso9660' && $data[$i]['type'] != 'cramfs' && $data[$i]['type'] != 'udf') {
            if($data[$i]['type'] != 'iso9660' && $data[$i]['type'] != 'cramfs' && $data[$i]['type'] != 'udf' && $data[$i]['type'] != 'tmpfs' && $data[$i]['type'] != 'devtmpfs') {
               if ($usePercent > 75) $state = $this->_setState($state, 'info');
               if ($usePercent > 80) $state = $this->_setState($state, 'warning');
               if ($usePercent > 90) $state = $this->_setState($state, 'critical');
@@ -760,11 +838,11 @@
      /** The type of the data */
      $type = 'system_update';
      /* This monitoring is only available at debian or Ubuntu */
      /* This monitoring is only available on Debian or Ubuntu */
      if(file_exists('/etc/debian_version')) {
         /*
             * first update the "update-database"
             * first update the "apt database"
         */
         shell_exec('apt-get update');
@@ -836,7 +914,7 @@
      }
      else {
         /*
             * It is not debian/Ubuntu, so there is no data and no state
             * It is not Debian/Ubuntu, so there is no data and no state
             *
             * no_state, NOT unknown, because "unknown" is shown as state
             * inside the GUI. no_state is hidden.
@@ -923,16 +1001,15 @@
      $type = 'raid_state';
      /*
       * We support some RAIDS. But if we can't find any of them, we have no data
       * We support several RAID types, but if we can't find any of them, we have no data
      */
      $state = 'no_state';
      $data['output']= '';
      /*
       * Check, if we have mdadm installed (software-raid)
       * Check, if Software-RAID is enabled
      */
      system('which mdadm', $retval);
      if($retval === 0) {
      if(file_exists('/proc/mdstat')) {
         /*
             * Fetch the output
         */
@@ -1747,4 +1824,4 @@
      return $res;
   }
}
?>
?>