From 7162553354e297f7c152144eed24aaecd28e7b43 Mon Sep 17 00:00:00 2001 From: vogelor <vogelor@ispconfig3> Date: Mon, 24 Nov 2008 16:27:37 -0500 Subject: [PATCH] The monitor now monitors the mailq and (on debian/ubuntu) the update-status --- server/mods-available/monitor_core_module.inc.php | 129 +++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 129 insertions(+), 0 deletions(-) diff --git a/server/mods-available/monitor_core_module.inc.php b/server/mods-available/monitor_core_module.inc.php index f89625b..aff1c38 100644 --- a/server/mods-available/monitor_core_module.inc.php +++ b/server/mods-available/monitor_core_module.inc.php @@ -107,6 +107,8 @@ $this->monitorFreshClamLog(); $this->monitorClamAvLog(); $this->monitorIspConfigLog(); + $this->monitorSystemUpdate(); + $this->monitorMailQueue(); } function monitorServer(){ @@ -447,6 +449,119 @@ $app->db->query($sql); } + + + function monitorSystemUpdate(){ + /* This monitoring is only available at debian or Ubuntu */ + if(!file_exists('/etc/debian_version')) return; + + /* + * This monitoring is expensive, so do it only once a hour! + */ + $min = date('i'); + if ($min != 0) return; + + /* + * OK - here we go... + */ + global $app; + global $conf; + + /* the id of the server as int */ + $server_id = intval($conf["server_id"]); + + /** The type of the data */ + $type = 'system_update'; + + /* There is only ONE Update-Data, so delete the old one */ + $this->_delOldRecords($type, 0); + + /* + * first update the "update-database" + */ + shell_exec('apt-get update'); + + /* + * Then test the upgrade. + * if there is any output, then there is a needed update + */ + $aptData = shell_exec('apt-get -s -qq dist-upgrade'); + if ($aptData == '') + { + /* There is nothing to update! */ + $state = 'ok'; + } + else + { + /* There is something to update! */ + $state = 'warning'; + } + + /* + * Fetch the output + */ + $data['output'] = shell_exec('apt-get -s -q dist-upgrade'); + + /* + * Insert the data into the database + */ + $sql = "INSERT INTO monitor_data (server_id, type, created, data, state) " . + "VALUES (". + $server_id . ", " . + "'" . $app->db->quote($type) . "', " . + time() . ", " . + "'" . $app->db->quote(serialize($data)) . "', " . + "'" . $state . "'" . + ")"; + $app->db->query($sql); + } + + function monitorMailQueue(){ + global $app; + global $conf; + + /* the id of the server as int */ + $server_id = intval($conf["server_id"]); + + /** The type of the data */ + $type = 'mailq'; + + /* There is only ONE Update-Data, so delete the old one */ + $this->_delOldRecords($type, 0); + + /* Get the data from the mailq */ + $data['output'] = shell_exec('mailq'); + + /* + * The last line has more informations + */ + $tmp = explode("\n", $data['output']); + $more = $tmp[sizeof($tmp) - 1]; + $this->_getIntArray($more); + $data['bytes'] = $res[0]; + $data['requests'] = $res[1]; + + /** The state of the mailq. */ + $state = 'ok'; + if ($data['requests'] > 2000 ) $state = 'info'; + if ($data['requests'] > 5000 ) $state = 'warning'; + if ($data['requests'] > 8000 ) $state = 'critical'; + if ($data['requests'] > 10000 ) $state = 'error'; + + /* + * Insert the data into the database + */ + $sql = "INSERT INTO monitor_data (server_id, type, created, data, state) " . + "VALUES (". + $server_id . ", " . + "'" . $app->db->quote($type) . "', " . + time() . ", " . + "'" . $app->db->quote(serialize($data)) . "', " . + "'" . $state . "'" . + ")"; + $app->db->query($sql); + } + function monitorMailLog() { @@ -872,6 +987,20 @@ } } + function _getIntArray($line){ + /** The array of float found */ + $res = array(); + /* First build a array from the line */ + $data = explode(' ', $line); + /* then check if any item is a float */ + foreach ($data as $item) { + if ($item . '' == (int)$item . ''){ + $res[] = $item; + } + } + return $res; + } + } // end class -- Gitblit v1.9.1