mirror of
https://github.com/rsyslog/loganalyzer.git
synced 2025-09-25 18:59:12 +02:00
Implemented method to update all checksum values at once in logstream classes
Enhanced Syslog logging, if socket functions are available, RFC5424 Syslog messages are generated for better debugging support.
This commit is contained in:
parent
d165136827
commit
ea7db9a839
@ -252,6 +252,12 @@ abstract class LogStream {
|
||||
public abstract function SaveMessageChecksum( $arrProperitesIn );
|
||||
|
||||
|
||||
/*
|
||||
* Helper function to set the checksum for all messages in the current logstream class
|
||||
*/
|
||||
public abstract function UpdateAllMessageChecksum( );
|
||||
|
||||
|
||||
/*
|
||||
* Helper function for logstream classes to clear filter based stuff
|
||||
*/
|
||||
@ -279,7 +285,7 @@ abstract class LogStream {
|
||||
else
|
||||
$finalfilters = $szFilters;
|
||||
|
||||
OutputDebugMessage("SetFilter combined = '" . $finalfilters . "'. ", DEBUG_DEBUG);
|
||||
OutputDebugMessage("LogStream|SetFilter: SetFilter combined = '" . $finalfilters . "'. ", DEBUG_DEBUG);
|
||||
|
||||
// Reset Filters first to make sure we do not add multiple filters!
|
||||
$this->_filters = null;
|
||||
|
@ -601,6 +601,46 @@ class LogStreamDB extends LogStream {
|
||||
return $rowcount;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Implementation of the UpdateAllMessageChecksum
|
||||
*
|
||||
* Update all missing checksum properties in the current database
|
||||
*/
|
||||
public function UpdateAllMessageChecksum( )
|
||||
{
|
||||
global $querycount, $dbmapping;
|
||||
$szTableType = $this->_logStreamConfigObj->DBTableType;
|
||||
|
||||
// UPDATE DATA NOW!
|
||||
$szSql = "UPDATE " . $this->_logStreamConfigObj->DBTableName .
|
||||
" SET " . $dbmapping[$szTableType]['DBMAPPINGS'][MISC_CHECKSUM] . " = crc32(" . $dbmapping[$szTableType]['DBMAPPINGS'][SYSLOG_MESSAGE] . ") " .
|
||||
" WHERE " . $dbmapping[$szTableType]['DBMAPPINGS'][MISC_CHECKSUM] . " IS NULL";
|
||||
|
||||
// Output Debug Informations
|
||||
OutputDebugMessage("LogStreamDB|UpdateAllMessageChecksum: Running Created SQL Query:<br>" . $szSql, DEBUG_ULTRADEBUG);
|
||||
|
||||
// Running SQL Query
|
||||
$myQuery = mysql_query($szSql, $this->_dbhandle);
|
||||
if ($myQuery)
|
||||
{
|
||||
// Debug Output
|
||||
OutputDebugMessage("LogStreamDB|UpdateAllMessageChecksum: Successfully updated Checksum of '" . mysql_affected_rows($this->_dbhandle) . "' datarecords", DEBUG_INFO);
|
||||
|
||||
// Return success
|
||||
return SUCCESS;
|
||||
}
|
||||
else
|
||||
{
|
||||
// error occured, output DEBUG message
|
||||
$this->PrintDebugError("SaveMessageChecksum failed with SQL Statement ' " . $szSql . " '");
|
||||
|
||||
// Failed
|
||||
return ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Implementation of the SaveMessageChecksum
|
||||
*
|
||||
@ -613,7 +653,7 @@ class LogStreamDB extends LogStream {
|
||||
|
||||
if ( isset($arrProperitesIn[SYSLOG_UID]) && isset($arrProperitesIn[MISC_CHECKSUM]) && isset($dbmapping[$szTableType]['DBMAPPINGS'][MISC_CHECKSUM]) )
|
||||
{
|
||||
// DELETE DATA NOW!
|
||||
// UPDATE DATA NOW!
|
||||
$szSql = "UPDATE " . $this->_logStreamConfigObj->DBTableName .
|
||||
" SET " . $dbmapping[$szTableType]['DBMAPPINGS'][MISC_CHECKSUM] . " = " . $arrProperitesIn[MISC_CHECKSUM] .
|
||||
" WHERE " . $dbmapping[$szTableType]['DBMAPPINGS'][SYSLOG_UID] . " = " . $arrProperitesIn[SYSLOG_UID];
|
||||
@ -712,6 +752,9 @@ class LogStreamDB extends LogStream {
|
||||
" ORDER BY " . $myDBSortedFieldName . " " . $szSortingOrder .
|
||||
$szLimitSql ;
|
||||
|
||||
// Output Debug Informations
|
||||
OutputDebugMessage("LogStreamDB|ConsolidateItemListByField: Running Created SQL Query:<br>" . $szSql, DEBUG_ULTRADEBUG);
|
||||
|
||||
// Perform Database Query
|
||||
$myquery = mysql_query($szSql, $this->_dbhandle);
|
||||
if ( !$myquery )
|
||||
@ -849,7 +892,7 @@ class LogStreamDB extends LogStream {
|
||||
$szLimitSql ;
|
||||
|
||||
// Output Debug Informations
|
||||
OutputDebugMessage("LogStreamDB|ConsolidateDataByField: Running Created SQL Query:<br>" . $szSql, DEBUG_DEBUG);
|
||||
OutputDebugMessage("LogStreamDB|ConsolidateDataByField: Running Created SQL Query:<br>" . $szSql, DEBUG_ULTRADEBUG);
|
||||
|
||||
// Perform Database Query
|
||||
$myquery = mysql_query($szSql, $this->_dbhandle);
|
||||
|
@ -666,6 +666,17 @@ class LogStreamDisk extends LogStream {
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Implementation of the UpdateAllMessageChecksum
|
||||
*
|
||||
* not implemented!
|
||||
*/
|
||||
public function UpdateAllMessageChecksum( )
|
||||
{
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Implementation of ConsolidateItemListByField
|
||||
*
|
||||
@ -785,6 +796,11 @@ class LogStreamDisk extends LogStream {
|
||||
{
|
||||
if ( isset($logArray[$szConsFieldId]) )
|
||||
{
|
||||
// --- Special Case for the checksum field, we need to generate the checksum ourself!
|
||||
if ( $szConsFieldId == MISC_CHECKSUM )
|
||||
$logArray[$szConsFieldId] = crc32( $logArray[SYSLOG_MESSAGE] );
|
||||
// ---
|
||||
|
||||
if ( $nConsFieldType == FILTER_TYPE_DATE )
|
||||
{
|
||||
// Convert to FULL Day Date for now!
|
||||
|
@ -690,6 +690,48 @@ class LogStreamPDO extends LogStream {
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Implementation of the UpdateAllMessageChecksum
|
||||
*
|
||||
* Update all missing checksum properties in the current database
|
||||
*/
|
||||
public function UpdateAllMessageChecksum( )
|
||||
{
|
||||
global $querycount, $dbmapping;
|
||||
$szTableType = $this->_logStreamConfigObj->DBTableType;
|
||||
|
||||
// UPDATE DATA NOW!
|
||||
$szSql = "UPDATE " . $this->_logStreamConfigObj->DBTableName .
|
||||
" SET " . $dbmapping[$szTableType]['DBMAPPINGS'][MISC_CHECKSUM] . " = crc32(" . $dbmapping[$szTableType]['DBMAPPINGS'][SYSLOG_MESSAGE] . ") " .
|
||||
" WHERE " . $dbmapping[$szTableType]['DBMAPPINGS'][MISC_CHECKSUM] . " IS NULL";
|
||||
|
||||
// Output Debug Informations
|
||||
OutputDebugMessage("LogStreamPDO|UpdateAllMessageChecksum: Running Created SQL Query:<br>" . $szSql, DEBUG_ULTRADEBUG);
|
||||
|
||||
// Running SQL Query
|
||||
$myQuery = $this->_dbhandle->query($szSql);
|
||||
if ( $myQuery )
|
||||
{
|
||||
// Output Debug Informations
|
||||
OutputDebugMessage("LogStreamPDO|UpdateAllMessageChecksum: Successfully updated Checksum of '" . $myQuery->rowCount() . "' datarecords", DEBUG_INFO);
|
||||
|
||||
// Free query now
|
||||
$myQuery->closeCursor();
|
||||
|
||||
// Return success
|
||||
return SUCCESS;
|
||||
}
|
||||
else
|
||||
{
|
||||
// error occured, output DEBUG message
|
||||
$this->PrintDebugError("UpdateAllMessageChecksum failed with SQL Statement ' " . $szSql . " '");
|
||||
|
||||
// Failed
|
||||
return ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Implementation of the SaveMessageChecksum
|
||||
*
|
||||
|
@ -298,14 +298,19 @@ class Report_syslogsummary extends Report {
|
||||
// Now open the stream for data processing
|
||||
$res = $this->_streamObj->Open( $this->_arrProperties, true );
|
||||
if ( $res == SUCCESS )
|
||||
{
|
||||
if ( true )
|
||||
{
|
||||
// --- New Method to consolidate data!
|
||||
// TimeStats
|
||||
$nowtime = microtime_float();
|
||||
$content["report_rendertime"] .= number_format($nowtime - $gl_starttime, 2, '.', '') . "s ";
|
||||
|
||||
// Update all Checksums first!
|
||||
$this->_streamObj->UpdateAllMessageChecksum();
|
||||
|
||||
// TimeStats
|
||||
$nowtime = microtime_float();
|
||||
$content["report_rendertime"] .= number_format($nowtime - $gl_starttime, 2, '.', '') . "s ";
|
||||
|
||||
foreach ( $arrHosts as $myHost )
|
||||
{
|
||||
// Set custom filters
|
||||
@ -333,9 +338,8 @@ class Report_syslogsummary extends Report {
|
||||
$nowtime = microtime_float();
|
||||
$content["report_rendertime"] .= number_format($nowtime - $gl_starttime, 2, '.', '') . "s ";
|
||||
// ---
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
/*
|
||||
// --- Old Method!
|
||||
// Init uid helper
|
||||
$uID = UID_UNKNOWN;
|
||||
@ -422,8 +426,7 @@ class Report_syslogsummary extends Report {
|
||||
}
|
||||
else
|
||||
return $ret;
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
// --- Start Postprocessing
|
||||
foreach( $content["report_consdata"] as &$tmpConsolidatedComputer )
|
||||
|
@ -570,7 +570,6 @@ function CheckAndSetRunMode()
|
||||
|
||||
// --- Check necessary PHP Extensions!
|
||||
$loadedExtensions = get_loaded_extensions();
|
||||
|
||||
// Check for GD libary
|
||||
if ( in_array("gd", $loadedExtensions) )
|
||||
$content['GD_IS_ENABLED'] = true;
|
||||
@ -581,6 +580,8 @@ function CheckAndSetRunMode()
|
||||
if ( in_array("mysql", $loadedExtensions) ) { $content['MYSQL_IS_ENABLED'] = true; } else { $content['MYSQL_IS_ENABLED'] = false; }
|
||||
// Check PDO Extension
|
||||
if ( in_array("PDO", $loadedExtensions) ) { $content['PDO_IS_ENABLED'] = true; } else { $content['PDO_IS_ENABLED'] = false; }
|
||||
// Check sockets Extension
|
||||
if ( in_array("sockets", $loadedExtensions) ) { $content['SOCKETS_IS_ENABLED'] = true; } else { $content['SOCKETS_IS_ENABLED'] = false; }
|
||||
// ---
|
||||
}
|
||||
|
||||
@ -1347,6 +1348,30 @@ function OutputDebugMessage($szDbg, $szDbgLevel = DEBUG_INFO)
|
||||
// Check if the user wants to syslog the error!
|
||||
if ( GetConfigSetting("MiscDebugToSyslog", 0, CFGLEVEL_GLOBAL) == 1 )
|
||||
{
|
||||
if ( $content['SOCKETS_IS_ENABLED'] )
|
||||
{
|
||||
// Send using UDP ourself!
|
||||
$sock = @socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
|
||||
$stprifac = (SYSLOG_LOCAL0 << 3);
|
||||
if ( $szDbgLevel == DEBUG_ERROR_WTF )
|
||||
$stprifac += SYSLOG_CRIT;
|
||||
else if ( $szDbgLevel == DEBUG_ERROR )
|
||||
$stprifac += SYSLOG_ERR;
|
||||
else if ( $szDbgLevel == DEBUG_WARN )
|
||||
$stprifac += SYSLOG_WARNING;
|
||||
else if ( $szDbgLevel == DEBUG_INFO )
|
||||
$stprifac += SYSLOG_NOTICE;
|
||||
else if ( $szDbgLevel == DEBUG_DEBUG )
|
||||
$stprifac += SYSLOG_INFO;
|
||||
else if ( $szDbgLevel == DEBUG_ULTRADEBUG )
|
||||
$stprifac += SYSLOG_DEBUG;
|
||||
|
||||
// Generate RFC5424 Syslog MSG
|
||||
$szsyslogmsg = "<" . $stprifac . ">" . date("c") . " " . php_uname ("n") . " " . "loganalyzer - - - " . $szDbg ;
|
||||
@socket_sendto($sock, $szsyslogmsg, strlen($szsyslogmsg), 0, '127.0.0.1', 514);
|
||||
@socket_close($sock);
|
||||
}
|
||||
else // Use PHP System function to send via syslog
|
||||
$syslogSend = syslog(GetPriorityFromDebugLevel($szDbgLevel), $szDbg);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user