Skip to content
monitor_core_module.inc.php 43.8 KiB
Newer Older
Copyright (c) 2007-2010, Till Brehm, projektfarm Gmbh and Oliver Vogel www.muv.com
All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

    * Redistributions of source code must retain the above copyright notice,
      this list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
    * Neither the name of ISPConfig nor the names of its contributors
      may be used to endorse or promote products derived from this software without
      specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
	var $interval = 5; // do the monitoring every 5 minutes
	var $module_name = 'monitor_core_module';
	var $class_name = 'monitor_core_module';
	/* No actions at this time. maybe later... */
	var $actions_available = array();
	//* This function is called during ispconfig installation to determine
	//  if a symlink shall be created for this plugin.
	function onInstall() {
		global $conf;
        This function is called when the module is loaded
	*/
	function onLoad() {
		global $app;
         * Do the monitor every n minutes and write the result to the db
		*/
		$min = date('i');
		if (($min % $this->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.
	*/
	function process($tablename, $action, $data) {
	} // end function

	//** 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!
	//   Please do not forget to remove the swriteln(); - lines here at this file
	function get_distname() {

		$distname = '';
		$distver = '';
		$distid = '';
		$distbaseid = '';

		//** Debian or Ubuntu
		if(file_exists('/etc/debian_version')) {

			if(trim(file_get_contents('/etc/debian_version')) == '4.0') {
				$distname = 'Debian';
				$distver = '4.0';
				$distid = 'debian40';
				$distbaseid = 'debian';
			} elseif(strstr(trim(file_get_contents('/etc/debian_version')),'5.0')) {
				$distname = 'Debian';
				$distver = 'Lenny';
				$distid = 'debian40';
				$distbaseid = 'debian';
			} elseif(strstr(trim(file_get_contents('/etc/debian_version')),'6.0') || trim(file_get_contents('/etc/debian_version')) == 'squeeze/sid') {
				$distname = 'Debian';
				$distver = 'Squeeze/Sid';
				$distid = 'debian40';
				$distbaseid = 'debian';
			}  else {
				$distname = 'Debian';
				$distver = 'Unknown';
				$distid = 'debian40';
				$distbaseid = 'debian';
			}
		}

		//** OpenSuSE
		elseif(file_exists("/etc/SuSE-release")) {
			if(stristr(file_get_contents('/etc/SuSE-release'),'11.0')) {
				$distname = 'openSUSE';
				$distver = '11.0';
				$distid = 'opensuse110';
				$distbaseid = 'opensuse';
			} elseif(stristr(file_get_contents('/etc/SuSE-release'),'11.1')) {
				$distname = 'openSUSE';
				$distver = '11.1';
				$distid = 'opensuse110';
				$distbaseid = 'opensuse';
			} elseif(stristr(file_get_contents('/etc/SuSE-release'),'11.2')) {
				$distname = 'openSUSE';
				$distver = '11.1';
				$distid = 'opensuse110';
				$distbaseid = 'opensuse';
			}  else {
				$distname = 'openSUSE';
				$distver = 'Unknown';
				$distid = 'opensuse110';
				$distbaseid = 'opensuse';
			}
		}


		//** Redhat
		elseif(file_exists("/etc/redhat-release")) {

			$content = file_get_contents('/etc/redhat-release');

			if(stristr($content,'Fedora release 9 (Sulphur)')) {
				$distname = 'Fedora';
				$distver = '9';
				$distid = 'fedora9';
				$distbaseid = 'fedora';
			} elseif(stristr($content,'Fedora release 10 (Cambridge)')) {
				$distname = 'Fedora';
				$distver = '10';
				$distid = 'fedora9';
				$distbaseid = 'fedora';
			} elseif(stristr($content,'Fedora release 10')) {
				$distname = 'Fedora';
				$distver = '11';
				$distid = 'fedora9';
				$distbaseid = 'fedora';
			} elseif(stristr($content,'CentOS release 5.2 (Final)')) {
				$distname = 'CentOS';
				$distver = '5.2';
				$distid = 'centos52';
				$distbaseid = 'fedora';
			} elseif(stristr($content,'CentOS release 5.3 (Final)')) {
				$distname = 'CentOS';
				$distver = '5.3';
				$distid = 'centos53';
				$distbaseid = 'fedora';
			} else {
				$distname = 'Redhat';
				$distver = 'Unknown';
				$distid = 'fedora9';
				$distbaseid = 'fedora';
			}
		}

		//** Gentoo
		elseif(file_exists("/etc/gentoo-release")) {

			$content = file_get_contents('/etc/gentoo-release');

			preg_match_all('/([0-9]{1,2})/', $content, $version);
			$distname = 'Gentoo';
			$distver = $version[0][0].$version[0][1];
			$distid = 'gentoo';
			$distbaseid = 'gentoo';

		} else {
			die('unrecognized linux distribution');
		}

		return array('name' => $distname, 'version' => $distver, 'id' => $distid, 'baseid' => $distbaseid);
	}


	/*
    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
	function doMonitor() {
		/* Calls the single Monitoring steps */
		$this->monitorServer();
		$this->monitorOSVer();
		$this->monitorDiskUsage();
Loading full blame...