From e8a29cf134f7df1a1e7637083f6d7adf64949b7c Mon Sep 17 00:00:00 2001 From: jmontoya <jmontoya@ispconfig3> Date: Wed, 04 Aug 2010 12:57:28 -0400 Subject: [PATCH] Adding new functions to the Remoting class --- server/mods-available/monitor_core_module.inc.php | 187 +++++++++++++++++++++++++++++++++++++++++++--- 1 files changed, 173 insertions(+), 14 deletions(-) diff --git a/server/mods-available/monitor_core_module.inc.php b/server/mods-available/monitor_core_module.inc.php index f0e7771..29dea26 100644 --- a/server/mods-available/monitor_core_module.inc.php +++ b/server/mods-available/monitor_core_module.inc.php @@ -195,8 +195,10 @@ // 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(); $this->monitorDiskUsage(); $this->monitorMemUsage(); $this->monitorCpu(); @@ -218,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; @@ -312,6 +391,42 @@ $this->_delOldRecords($type, 4); } + + function monitorIspcVer() { + global $app; + global $conf; + + /* the id of the server as int */ + $server_id = intval($conf["server_id"]); + + /** The type of the data */ + $type = 'ispc_info'; + + /* + Fetch the data into a array + */ + $data['name'] = ISPC_APP_TITLE; + $data['version'] = ISPC_APP_VERSION; + + /* the ISPC-Version 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 monitorDiskUsage() { global $app; @@ -666,7 +781,7 @@ foreach ($test as $item) { /* * eliminate all doubled spaces and spaces at the beginning and end - */ + */ while (strpos($item, ' ') !== false) { $item = str_replace(' ', ' ', $item); } @@ -674,7 +789,7 @@ /* * The failcounter is the LAST - */ + */ if ($item != '') { $tmp = explode(' ', $item); $failCounter = $tmp[sizeof($tmp)-1]; @@ -885,7 +1000,15 @@ /** The type of the data */ $type = 'raid_state'; - /* This monitoring is only available if mdadm is installed */ + /* + * We support some RAIDS. 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) + */ system('which mdadm', $retval); if($retval === 0) { /* @@ -935,20 +1058,56 @@ } } } - } - else { + /* + * Check, if we have mpt-status installed (LSIsoftware-raid) + */ + system('which mpt-status', $retval); + if($retval === 0) { /* - * mdadm is not installed, 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. - * - * We have to write NO DATA inside the DB, because the GUI - * could not know, if there is any dat, or not... + * Fetch the output */ - $state = 'no_state'; - $data['output']= ''; + $data['output'] = shell_exec('mpt-status --autoload -n'); + + /* + * Then calc the state. + */ + $state = 'ok'; + foreach ($data['output'] as $item) { + /* + * The output contains information for every RAID and every HDD. + * We only need the state of the RAID + */ + if (strpos($item, 'raidlevel:') !== false) { + /* + * We found a raid, process the state of it + */ + if (strpos($item, ' ONLINE ') !== false) { + $this->_setState($state, 'ok'); + } + else if (strpos($item, ' OPTIMAL ') !== false) { + $this->_setState($state, 'ok'); + } + else if (strpos($item, ' INITIAL ') !== false) { + $this->_setState($state, 'info'); + } + else if (strpos($item, ' INACTIVE ') !== false) { + $this->_setState($state, 'critical'); + } + else if (strpos($item, ' RESYNC ') !== false) { + $this->_setState($state, 'info'); + } + else if (strpos($item, ' DEGRADED ') !== false) { + $this->_setState($state, 'critical'); + } + else { + /* we don't know the state. so we set the state to critical, that the + * admin is warned, that something is wrong + */ + $this->_setState($state, 'critical'); + } + } + } } /* -- Gitblit v1.9.1