Added feature #16337: System health status self monitoring
authorIngo Renner <ingo.renner@typo3.org>
Fri, 12 Nov 2010 22:35:06 +0000 (22:35 +0000)
committerIngo Renner <ingo.renner@typo3.org>
Fri, 12 Nov 2010 22:35:06 +0000 (22:35 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Core/trunk@9356 709f56b5-9817-0410-a4d7-c38de5d9e867

ChangeLog
typo3/sysext/reports/ChangeLog
typo3/sysext/reports/ext_localconf.php [new file with mode: 0644]
typo3/sysext/reports/reports/class.tx_reports_reports_status.php
typo3/sysext/reports/reports/locallang.xml
typo3/sysext/reports/reports/status/class.tx_reports_reports_status_warningmessagepostprocessor.php [new file with mode: 0644]

index 7700eea..f6f0092 100755 (executable)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2010-11-12  Ingo Renner  <ingo@typo3.org>
+
+       * Added feature #16337: System health status self monitoring
+
 2010-11-12  Steffen Gebert  <steffen@steffen-gebert.de>
 
        * Added feature #16357: visualize beeing in an workspace by coloring the topbar (Thanks to Lars Zimmermann)
index 8eb69e7..38a9dd7 100644 (file)
@@ -1,3 +1,7 @@
-2009-09-18 Ingo Renner  <ingo@typo3.org>
+2010-11-12  Ingo Renner  <ingo@typo3.org>
+
+       * Added feature #16337: System health status self monitoring
+
+2009-09-18  Ingo Renner  <ingo@typo3.org>
 
        * Integration of the reports module as a system extension
diff --git a/typo3/sysext/reports/ext_localconf.php b/typo3/sysext/reports/ext_localconf.php
new file mode 100644 (file)
index 0000000..22dd57f
--- /dev/null
@@ -0,0 +1,10 @@
+<?php
+/* $Id$ */
+
+if (!defined ('TYPO3_MODE')) {
+       die ('Access denied.');
+}
+
+$TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_befunc.php']['displayWarningMessages']['tx_reports_WarningMessagePostProcessor'] = 'EXT:reports/reports/status/class.tx_reports_reports_status_warningmessagepostprocessor.php:tx_reports_reports_status_WarningMessagePostProcessor';
+
+?>
\ No newline at end of file
index 2744950..a76587f 100644 (file)
@@ -51,7 +51,6 @@ class tx_reports_reports_Status implements tx_reports_Report {
         * @return      string  The status report as HTML
         */
        public function getReport() {
-               $status  = array();
                $content = '';
 
                foreach ($this->statusProviders as $statusProviderId => $statusProvidersList) {
@@ -62,6 +61,13 @@ class tx_reports_reports_Status implements tx_reports_Report {
                        }
                }
 
+               $status = $this->getSystemStatus();
+               $highestSeverity = $this->getHighestSeverity($status);
+
+                       // updating the registry
+               $registry = t3lib_div::makeInstance('t3lib_Registry');
+               $registry->set('tx_reports', 'status.highestSeverity', $highestSeverity);
+
                $content .= '<p class="help">'
                        . $GLOBALS['LANG']->getLL('status_report_explanation')
                        . '</p>';
@@ -77,8 +83,10 @@ class tx_reports_reports_Status implements tx_reports_Report {
        protected function getStatusProviders() {
                foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['reports']['tx_reports']['status']['providers'] as $key => $statusProvidersList) {
                        $this->statusProviders[$key] = array();
+
                        foreach ($statusProvidersList as $statusProvider) {
                                $statusProviderInstance = t3lib_div::makeInstance($statusProvider);
+
                                if ($statusProviderInstance instanceof tx_reports_StatusProvider) {
                                        $this->statusProviders[$key][] = $statusProviderInstance;
                                }
@@ -87,12 +95,60 @@ class tx_reports_reports_Status implements tx_reports_Report {
        }
 
        /**
+        * Runs through all status providers and returns all statuses collected.
+        *
+        * @return      array   An array of tx_reports_reports_status_Status objects
+        */
+       public function getSystemStatus() {
+               $status = array();
+
+               foreach ($this->statusProviders as $statusProviderId => $statusProviderList) {
+                       $status[$statusProviderId] = array();
+
+                       foreach ($statusProviderList as $statusProvider) {
+                               $statuses = $statusProvider->getStatus();
+                               $status[$statusProviderId] = array_merge($status[$statusProviderId], $statuses);
+                       }
+               }
+
+               return $status;
+       }
+
+       /**
+        * Determines the highest severity from the given statuses.
+        *
+        * @param       array   An array of tx_reports_reports_status_Status objects.
+        * @return      integer The highest severity found from the statuses.
+        */
+       public function getHighestSeverity(array $statusCollection) {
+               $highestSeverity = tx_reports_reports_status_Status::NOTICE;
+
+               foreach ($statusCollection as $statusProvider => $providerStatuses) {
+                       foreach ($providerStatuses as $status) {
+                               if ($status->getSeverity() > $highestSeverity) {
+                                       $highestSeverity = $status->getSeverity();
+                               }
+
+                                       // reached the highest severity level, no need to go on
+                               if ($highestSeverity == tx_reports_reports_status_Status::ERROR) {
+                                       break;
+                               }
+                       }
+               }
+
+               return $highestSeverity;
+       }
+
+       /**
         * Renders the system's status
         *
         * @param       array   An array of statuses as returned by the available status providers
         * @return      string  The system status as an HTML table
         */
        protected function renderStatus(array $statusCollection) {
+
+               // TODO refactor into separate methods, status list and single status
+
                $content = '';
                $template = '
                <div class="typo3-message message-###CLASS###">
index 33be669..fdd6544 100644 (file)
@@ -19,6 +19,7 @@
                        <label index="status_connectionFailed">Connection Failed</label>
                        <label index="status_updateComplete">Update Complete</label>
                        <label index="status_updateIncomplete">Update Incomplete</label>
+                       <label index="status_problemNotification">One or more problems were detected with your TYPO3 installation. Please check the %sstatus report%s for more information.</label>
                        <label index="status_typo3">TYPO3 System</label>
                        <label index="status_system">System</label>
                        <label index="status_security">Security</label>
diff --git a/typo3/sysext/reports/reports/status/class.tx_reports_reports_status_warningmessagepostprocessor.php b/typo3/sysext/reports/reports/status/class.tx_reports_reports_status_warningmessagepostprocessor.php
new file mode 100644 (file)
index 0000000..c185fd3
--- /dev/null
@@ -0,0 +1,88 @@
+<?php
+/***************************************************************
+*  Copyright notice
+*
+*  (c) 2010 Ingo Renner <ingo@typo3.org>
+*  All rights reserved
+*
+*  This script is part of the TYPO3 project. The TYPO3 project is
+*  free software; you can redistribute it and/or modify
+*  it under the terms of the GNU General Public License as published by
+*  the Free Software Foundation; either version 2 of the License, or
+*  (at your option) any later version.
+*
+*  The GNU General Public License can be found at
+*  http://www.gnu.org/copyleft/gpl.html.
+*
+*  This script is distributed in the hope that it will be useful,
+*  but WITHOUT ANY WARRANTY; without even the implied warranty of
+*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+*  GNU General Public License for more details.
+*
+*  This copyright notice MUST APPEAR in all copies of the script!
+***************************************************************/
+
+
+/**
+ * Post processes the warning messages found in about modules.
+ *
+ * @author     Ingo Renner <ingo@typo3.org>
+ * @package TYPO3
+ * @subpackage reports
+ */
+class tx_reports_reports_status_WarningMessagePostProcessor {
+
+       /**
+        * Tries to get the highest severity of the system's status first, if
+        * something is found it is asumed that the status update task is set up
+        * properly or the status report has been checked manually and we take over
+        * control over the system warning messages.
+        *
+        * @param       array   An array of messages related to already found issues.
+        * @return      void
+        */
+       public function displayWarningMessages_postProcess(array &$warningMesasges) {
+
+                       // get highest severity
+               $registry = t3lib_div::makeInstance('t3lib_Registry');
+               $highestSeverity = $registry->get(
+                       'tx_reports',
+                       'status.highestSeverity',
+                       null
+               );
+
+               if (!is_null($highestSeverity)) {
+                               // status update has run, so taking over control over the core messages
+                       unset(
+                               $warningMesasges['install_password'],
+                               $warningMesasges['backend_admin'],
+                               $warningMesasges['install_enabled'],
+                               $warningMesasges['install_encryption'],
+                               $warningMesasges['file_deny_pattern'],
+                               $warningMesasges['file_deny_htaccess'],
+                               $warningMesasges['install_update'],
+                               $warningMesasges['backend_reference'],
+                               $warningMesasges['memcached']
+                       );
+
+                       if ($highestSeverity > tx_reports_reports_status_Status::OK) {
+                                       // display a message that there's something wrong and that
+                                       // the admin should take a look at the detailed status report
+                               $GLOBALS['LANG']->includeLLFile('EXT:reports/reports/locallang.xml');
+
+                               $warningMesasges['tx_reports_status_notification'] = sprintf(
+                                       $GLOBALS['LANG']->getLL('status_problemNotification'),
+                                       '<a href="mod.php?M=tools_txreportsM1&SET[function]=tx_reports.status">',
+                                       '</a>'
+                               );
+                       }
+               }
+       }
+}
+
+
+if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/reports/reports/status/class.tx_reports_reports_status_warningmessagepostprocessor.php'])     {
+       include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/reports/reports/status/class.tx_reports_reports_status_warningmessagepostprocessor.php']);
+}
+
+?>
\ No newline at end of file