mirror of
https://github.com/rsyslog/loganalyzer.git
synced 2025-09-26 03:09:21 +02:00
added new classes
This commit is contained in:
parent
fbf848b2f3
commit
38c913bb1e
16
classes/enums.class.php
Normal file
16
classes/enums.class.php
Normal file
@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Since php does not support enums we emulate it
|
||||
* using a abstract class.
|
||||
*/
|
||||
|
||||
/**
|
||||
* ENUM of available ReadDirection.
|
||||
*/
|
||||
abstract class EnumReadDirection {
|
||||
const Forward = 1;
|
||||
const Backward = 2;
|
||||
}
|
||||
|
||||
?>
|
78
classes/logstream.class.php
Normal file
78
classes/logstream.class.php
Normal file
@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* LogStream provides access to the log data. Be sure to always
|
||||
* use LogStream if you want to access a text file or database.
|
||||
*/
|
||||
abstract class LogStream {
|
||||
protected $_readDirection = EnumReadDirection::Forward;
|
||||
protected $_filter = null;
|
||||
protected $_current_uId = -1;
|
||||
protected $_logStreamConfigObj = null;
|
||||
protected $_arrProperties = null;
|
||||
|
||||
/**
|
||||
* Open the stream for read access.
|
||||
*
|
||||
* @param arrProperties string in: properties of interest. There can be no guarantee the logstream can actually deliver them.
|
||||
* @return integer Error stat
|
||||
*/
|
||||
public abstract function Open($arrProperties);
|
||||
|
||||
/**
|
||||
* Close the current stream.
|
||||
*
|
||||
* @return integer Error stat
|
||||
*/
|
||||
public abstract function Close();
|
||||
|
||||
/**
|
||||
* Read the next data from the current stream. If it reads
|
||||
* forwards or backwards depends on the current read direction.
|
||||
*
|
||||
* Example for reading forward:
|
||||
* Is the current uID == 4, readDirection set to forwards
|
||||
* ReadNext will provide uID 5 or EOS if no more data exist.
|
||||
*
|
||||
* Exampe for reading backward:
|
||||
* Is the current uID == 4, readDirection set to backwards
|
||||
* ReadNext will provide uID 3.
|
||||
*
|
||||
* Hint: If the current stream becomes unavailable an error
|
||||
* stated is retuned. A typical case is if a log rotation
|
||||
* changed the original data source.
|
||||
*
|
||||
* @param uID integer out: unique id of the data row
|
||||
* @param logLine string out: data row
|
||||
* @return integer Error state
|
||||
*/
|
||||
public abstract function ReadNext(&$uID, &$logLine);
|
||||
|
||||
/**
|
||||
* Read the data from a specific uID.
|
||||
*
|
||||
* @param uID integer in: unique id of the data row
|
||||
* @param logLine string out: data row
|
||||
* @return integer Error state
|
||||
* @see ReadNext()
|
||||
*/
|
||||
public abstract function Read($uID, &$logLine);
|
||||
|
||||
/**
|
||||
* Set the filter for the current stream.
|
||||
*
|
||||
* @param filter object in: filter object
|
||||
* @return integer Error state
|
||||
*/
|
||||
public abstract function SetFilter($filter);
|
||||
|
||||
/**
|
||||
* Set the direction the stream should read data.
|
||||
*
|
||||
* @param enumReadDirectionfilter EnumReadDirection in: The new direction.
|
||||
* @return integer Error state
|
||||
*/
|
||||
public abstract function SetReadDirection($enumReadDirection);
|
||||
}
|
||||
|
||||
?>
|
12
classes/logstreamconfig.class.php
Normal file
12
classes/logstreamconfig.class.php
Normal file
@ -0,0 +1,12 @@
|
||||
<?php
|
||||
/**
|
||||
* StreamConfig has the capability to create a specific LogStream
|
||||
* object depending on a configured LogStream*Config object.
|
||||
*/
|
||||
abstract class LogStreamConfig {
|
||||
protected $_logStreamConfigObj = null;
|
||||
|
||||
public abstract function LogStreamFactory($o);
|
||||
|
||||
}
|
||||
?>
|
14
classes/logstreamconfigdisk.class.php
Normal file
14
classes/logstreamconfigdisk.class.php
Normal file
@ -0,0 +1,14 @@
|
||||
<?php
|
||||
/**
|
||||
* StreamConfig has the capability to create a specific LogStream
|
||||
* object depending on a configured LogStream*Config object.
|
||||
*/
|
||||
class LogStreamConfigDisk extends LogStreamConfig {
|
||||
public $FileName = '';
|
||||
|
||||
public function LogStreamFactory($o) {
|
||||
return new LogStreamDisk($o);
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
128
classes/logstreamdisk.class.php
Normal file
128
classes/logstreamdisk.class.php
Normal file
@ -0,0 +1,128 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* LogStreamDisk provides access to the data on disk. In the most
|
||||
* cases this will be plain text files. If we need access to e.g.
|
||||
* zipped files, this will be handled by a separate driver.
|
||||
*
|
||||
* \version 1.0.1 2nd Version
|
||||
* \version 1.0.0 Init Version
|
||||
*
|
||||
*/
|
||||
class LogStreamDisk extends LogStream {
|
||||
private $_currentOffset = -1;
|
||||
private $_fp = null;
|
||||
|
||||
// Constructor
|
||||
public function LogStreamDisk($streamConfigObj) {
|
||||
$this->_logStreamConfigObj = $streamConfigObj;
|
||||
}
|
||||
|
||||
/**
|
||||
* Open the file with read access.
|
||||
*
|
||||
* @param streamConfigObj object in: It has to be a LogSteamDiskConfig object.
|
||||
* @return integer Error stat
|
||||
*/
|
||||
public function Open($arrProperties) {
|
||||
if(!file_exists($this->_logStreamConfigObj->FileName)) {
|
||||
return ERROR_FILE_NOT_FOUND;
|
||||
}
|
||||
|
||||
$this->_fp = fopen($this->_logStreamConfigObj->FileName, 'r');
|
||||
$this->_currentOffset = 0;
|
||||
$this->_arrProperties = $arrProperties;
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Close the file.
|
||||
*
|
||||
* @return integer Error state
|
||||
*/
|
||||
public function Close() {
|
||||
|
||||
if (!fclose($this->_fp)) {
|
||||
return ERROR_FILE_CANT_CLOSE;
|
||||
}
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Read the next line from the file depending on the current
|
||||
* read direction.
|
||||
*
|
||||
* Hint: If the current stream becomes unavailable an error
|
||||
* stated is retuned. A typical case is if a log rotation
|
||||
* changed the original data source.
|
||||
*
|
||||
* @param uID integer out: uID is the offset of data row
|
||||
* @param logLine string out: data row
|
||||
* @return integer Error state
|
||||
* @see ReadNext
|
||||
*/
|
||||
public function ReadNext(&$uID, &$logLine) {
|
||||
|
||||
$uID = $this->_currentOffset;
|
||||
|
||||
if (feof($this->_fp)) {
|
||||
return ERROR_FILE_EOF;
|
||||
}
|
||||
|
||||
$logLine = fgets($this->_fp);
|
||||
if ($logLine === false) {
|
||||
// ToDo: error occurs, or EOF
|
||||
return 1;
|
||||
}
|
||||
|
||||
$this->_currentOffset = $this->_currentOffset + sizeof($logLine);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read the data from a specific uID which means in this
|
||||
* case from a given offset of the file.
|
||||
*
|
||||
* @param uID integer in/out: unique id of the data row
|
||||
* @param logLine string out: data row
|
||||
* @return integer Error state
|
||||
* @see ReadNext()
|
||||
*/
|
||||
public function Read($uID, &$logLine) {
|
||||
$this->_currentOffset = $uID;
|
||||
fseek($fp, $this->_currentOffset);
|
||||
|
||||
// with Read we can only read forwards.
|
||||
// so we have to remember the current read
|
||||
// direction
|
||||
$tmp = $this->_readDirection;
|
||||
$iRet = $this->ReadNext($uID, $logLine);
|
||||
$this->_readDirection = $tmp;
|
||||
|
||||
return $iRet;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the filter for the current stream.
|
||||
*
|
||||
* @param filter object in: filter object
|
||||
* @return integer Error state
|
||||
*/
|
||||
public function SetFilter($filter) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the direction the stream should read data.
|
||||
*
|
||||
* @param enumReadDirectionfilter EnumReadDirection in: The new direction.
|
||||
* @return integer Error state
|
||||
*/
|
||||
public function SetReadDirection($enumReadDirection) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
Loading…
x
Reference in New Issue
Block a user