diff --git a/doc/objectmodel.dia b/doc/objectmodel.dia index d670203..1479082 100644 Binary files a/doc/objectmodel.dia and b/doc/objectmodel.dia differ diff --git a/src/classes/logstreamconfigdisk.class.php b/src/classes/logstreamconfigdisk.class.php index 023e84a..2375a4d 100644 --- a/src/classes/logstreamconfigdisk.class.php +++ b/src/classes/logstreamconfigdisk.class.php @@ -23,16 +23,31 @@ if ( !defined('IN_PHPLOGCON') ) class LogStreamConfigDisk extends LogStreamConfig { public $FileName = ''; + public $_lineParser = null; public function LogStreamFactory($o) { // An instance is created, then include the logstreamdisk class as well! global $gl_root_path; require_once($gl_root_path . 'classes/logstreamdisk.class.php'); + + // Create and set LineParser Instance + $this->_lineParser = $this->CreateLineParser(); // return LogStreamDisk instance return new LogStreamDisk($o); } + private function CreateLineParser() + { + // We need to include Line Parser on demand! + global $gl_root_path; + require_once($gl_root_path . 'classes/logstreamlineparser.class.php'); + require_once($gl_root_path . 'classes/logstreamlineparsersyslog.class.php'); + + //return LineParser Instance + return new LogStreamLineParserSyslog(); + } + } ?> \ No newline at end of file diff --git a/src/classes/logstreamdisk.class.php b/src/classes/logstreamdisk.class.php index eebf67e..37f982a 100644 --- a/src/classes/logstreamdisk.class.php +++ b/src/classes/logstreamdisk.class.php @@ -29,7 +29,6 @@ if ( !defined('IN_PHPLOGCON') ) // --- Required Includes! require_once($gl_root_path . 'include/constants_errors.php'); -require_once($gl_root_path . 'classes/logstreamparser.class.php'); // --- class LogStreamDisk extends LogStream { @@ -43,12 +42,9 @@ class LogStreamDisk extends LogStream { private $_buffer_length = 0; private $_p_buffer = -1; - private $_msgParser = null; - // Constructor public function LogStreamDisk($streamConfigObj) { $this->_logStreamConfigObj = $streamConfigObj; - $this->_msgParser = new LogStreamParser(); } /** @@ -187,7 +183,7 @@ class LogStreamDisk extends LogStream { else $ret = $this->ReadNextBackwards($uID, $arrProperitesOut); -$this->_msgParser->ParseSyslogMessage($arrProperitesOut); +$this->_logStreamConfigObj->_lineParser->ParseLine($arrProperitesOut); // Loop until the filter applies, or another error occurs. } while ( $this->ApplyFilters($ret, $arrProperitesOut) != SUCCESS && $ret == SUCCESS ); diff --git a/src/classes/logstreamlineparser.class.php b/src/classes/logstreamlineparser.class.php new file mode 100644 index 0000000..beb28d2 --- /dev/null +++ b/src/classes/logstreamlineparser.class.php @@ -0,0 +1,43 @@ + www.phplogcon.org <- * + * * + * Use this script at your own risk! * + * ----------------------------------------------------------------- * + * LogStream LineParser abstract basic class * + * * + * All directives are explained within this file * + ********************************************************************* +*/ + +// --- Avoid directly accessing this file! +if ( !defined('IN_PHPLOGCON') ) +{ + die('Hacking attempt'); + exit; +} +// --- + +// --- Basic Includes +require_once($gl_root_path . 'classes/enums.class.php'); +require_once($gl_root_path . 'include/constants_errors.php'); +require_once($gl_root_path . 'include/constants_logstream.php'); +// --- + + +abstract class LogStreamLineParser { +// protected $_arrProperties = null; + + /** + * ParseLine + * + * @param arrArguments array in&out: properties of interest. There can be no guarantee the logstream can actually deliver them. + * @return integer Error stat + */ + public abstract function ParseLine(&$arrArguments); + +} + +?> \ No newline at end of file diff --git a/src/classes/logstreamparser.class.php b/src/classes/logstreamlineparsersyslog.class.php similarity index 58% rename from src/classes/logstreamparser.class.php rename to src/classes/logstreamlineparsersyslog.class.php index 73af73d..cd74b30 100644 --- a/src/classes/logstreamparser.class.php +++ b/src/classes/logstreamlineparsersyslog.class.php @@ -27,34 +27,24 @@ require_once($gl_root_path . 'include/constants_logstream.php'); // --- -class LogStreamParser { -// protected $_readDirection = EnumReadDirection::Forward; -// protected $_filters = null; -// protected $_current_uId = -1; -// protected $_logStreamConfigObj = null; +class LogStreamLineParserSyslog extends LogStreamLineParser { // protected $_arrProperties = null; // Constructor - public function LogStreamParser() { + public function LogStreamLineParserSyslog() { return; // Nothing } /** - * ParseSyslogMessage + * ParseLine * - * @param arrProperties string in: properties of interest. There can be no guarantee the logstream can actually deliver them. + * @param arrArguments array in&out: properties of interest. There can be no guarantee the logstream can actually deliver them. * @return integer Error stat */ - public function ParseSyslogMessage(&$arrArguments) + public function ParseLine(&$arrArguments) { - /* Sample: - * Mar 10 14:45:39 debandre syslogd 1.4.1#18: restart. - * Mar 10 14:45:44 debandre anacron[3226]: Job `cron.daily' terminated (mailing output) - * - */ - - // Typical Syslog Message - if ( preg_match("/(... [0-9]{1,2} [0-9]{1,2}:[0-9]{1,2}:[0-9]{1,2}) (.*?) (.*?)\[(.*?)\]: (.*?)$/", $arrArguments[SYSLOG_MESSAGE], $out ) ) + // Sample (Syslog): Mar 10 14:45:44 debandre anacron[3226]: Job `cron.daily' terminated (mailing output) + if ( preg_match("/(... [0-9]{1,2} [0-9]{1,2}:[0-9]{1,2}:[0-9]{1,2}) (.*?) (.*?)\[(.*?)\]:(.*?)$/", $arrArguments[SYSLOG_MESSAGE], $out ) ) { // Copy parsed properties! $arrArguments[SYSLOG_DATE] = $out[1]; @@ -63,7 +53,17 @@ class LogStreamParser { $arrArguments[SYSLOG_PROCESSID] = $out[4]; $arrArguments[SYSLOG_MESSAGE] = $out[5]; } - else if ( preg_match("/(... [0-9]{1,2} [0-9]{1,2}:[0-9]{1,2}:[0-9]{1,2}) (.*?) (.*?): (.*?)$/", $arrArguments[SYSLOG_MESSAGE], $out ) ) + // Sample (Syslog): Mar 10 14:45:39 debandre syslogd 1.4.1#18: restart. + else if ( preg_match("/(... [0-9]{1,2} [0-9]{1,2}:[0-9]{1,2}:[0-9]{1,2}) (.*?) (.*?):(.*?)$/", $arrArguments[SYSLOG_MESSAGE], $out ) ) + { + // Copy parsed properties! + $arrArguments[SYSLOG_DATE] = $out[1]; + $arrArguments[SYSLOG_HOST] = $out[2]; + $arrArguments[SYSLOG_SYSLOGTAG] = $out[3]; + $arrArguments[SYSLOG_MESSAGE] = $out[4]; + } + // Sample (RSyslog): 2008-03-28T11:07:40.591633+01:00 localhost rger: test 1 + else if ( preg_match("/([0-9]{4,4}-[0-9]{1,2}-[0-9]{1,2}T[0-9]{1,2}:[0-9]{1,2}:[0-9]{1,2}\.[0-9]{1,6}\+[0-9]{1,2}:[0-9]{1,2}) (.*?) (.*?):(.*?)$/", $arrArguments[SYSLOG_MESSAGE], $out ) ) { // Copy parsed properties! $arrArguments[SYSLOG_DATE] = $out[1]; @@ -73,9 +73,12 @@ class LogStreamParser { } else { - // Cannot Parse Syslog message with this pattern! + // TODO: Cannot Parse Syslog message with this pattern! die ("wtf - " . $arrArguments[SYSLOG_MESSAGE] ); } + + // Return success! + return SUCCESS; } diff --git a/src/config.php b/src/config.php index 196964f..d1f3909 100644 --- a/src/config.php +++ b/src/config.php @@ -1,14 +1,31 @@ www.phplogcon.org <- * - * * - * Use this script at your own risk! * - * ----------------------------------------------------------------- * - * Main Configuration File * - * * - * -> Configuration need variables for the Database connection * + * phpLogCon - http://www.phplogcon.org + * ----------------------------------------------------------------- + * Main Configuration File + * + * -> Configuration need variables for the Database connection + * + * Copyright (C) 2008 Adiscon GmbH. + * + * This file is part of phpLogCon. + * + * PhpLogCon 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 3 of the License, or + * (at your option) any later version. + * + * PhpLogCon 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. + * + * You should have received a copy of the GNU General Public License + * along with phpLogCon. If not, see . + * + * A copy of the GPL can be found in the file "COPYING" in this + * distribution. ********************************************************************* */ @@ -44,5 +61,9 @@ $CFG['Sources'][1]['Name'] = "Old Syslog Disk File"; $CFG['Sources'][1]['SourceType'] = SOURCE_DISK; $CFG['Sources'][1]['DiskFile'] = $gl_root_path . "samplelogs/syslog.0"; + $CFG['Sources'][2]['ID'] = "Source3"; + $CFG['Sources'][2]['Name'] = "RSyslog Disk File"; + $CFG['Sources'][2]['SourceType'] = SOURCE_DISK; + $CFG['Sources'][2]['DiskFile'] = $gl_root_path . "samplelogs/rsyslog"; // --- -?> \ No newline at end of file +?>