Merge branch 'master' of git+ssh://mm@git.adiscon.com/git/phplogcon

This commit is contained in:
Michael Meckelein 2008-04-02 17:09:40 +02:00
commit 27af0e10f2
6 changed files with 111 additions and 33 deletions

Binary file not shown.

View File

@ -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();
}
}
?>

View File

@ -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 );

View File

@ -0,0 +1,43 @@
<?php
/*
*********************************************************************
* Copyright by Adiscon GmbH | 2008! *
* -> 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);
}
?>

View File

@ -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;
}

View File

@ -1,14 +1,31 @@
<?php
/*
*********************************************************************
* Copyright by Adiscon GmbH | 2008! *
* -> 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 <http://www.gnu.org/licenses/>.
*
* 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";
// ---
?>
?>