mirror of
https://github.com/rsyslog/loganalyzer.git
synced 2025-09-26 03:09:21 +02:00
Further changes in report area
This commit is contained in:
parent
7ee719ee8e
commit
b3d76c7de0
@ -202,6 +202,13 @@ abstract class LogStream {
|
||||
*/
|
||||
public abstract function GetCountSortedByField($szFieldId, $nFieldType, $nRecordLimit);
|
||||
|
||||
/**
|
||||
* This functions is used by reports to consolidate data
|
||||
*
|
||||
* @return integer Error stat
|
||||
*/
|
||||
public abstract function ConsolidateDataByField($szFieldId, $nRecordLimit);
|
||||
|
||||
|
||||
/**
|
||||
* Gets a property and checks if the class is able to sort the records
|
||||
|
@ -689,6 +689,78 @@ class LogStreamDB extends LogStream {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Implementation of ConsolidateDataByField
|
||||
*
|
||||
* In the native MYSQL Logstream, the database will do most of the work
|
||||
*
|
||||
* @return integer Error stat
|
||||
*/
|
||||
public function ConsolidateDataByField($szFieldId, $nRecordLimit)
|
||||
{
|
||||
global $content, $dbmapping, $fields;
|
||||
|
||||
// Copy helper variables, this is just for better readability
|
||||
$szTableType = $this->_logStreamConfigObj->DBTableType;
|
||||
|
||||
if ( isset($dbmapping[$szTableType]['DBMAPPINGS'][$szFieldId]) )
|
||||
{
|
||||
// Get FieldType
|
||||
$nFieldType = $fields[$szFieldId]['FieldType'];
|
||||
|
||||
// Set DB Field name first!
|
||||
$myDBFieldName = $dbmapping[$szTableType]['DBMAPPINGS'][$szFieldId];
|
||||
$myDBQueryFieldName = $myDBFieldName;
|
||||
$mySelectFieldName = $myDBFieldName;
|
||||
|
||||
// Special handling for date fields
|
||||
if ( $nFieldType == FILTER_TYPE_DATE )
|
||||
{
|
||||
// Helper variable for the select statement
|
||||
$mySelectFieldName = $mySelectFieldName . "Grouped";
|
||||
$myDBQueryFieldName = "DATE( " . $myDBFieldName . ") AS " . $mySelectFieldName ;
|
||||
}
|
||||
|
||||
// Create SQL String now!
|
||||
$szSql = "SELECT " .
|
||||
$myDBQueryFieldName . ", " .
|
||||
"count(" . $myDBFieldName . ") as TotalCount " .
|
||||
" FROM " . $this->_logStreamConfigObj->DBTableName .
|
||||
" GROUP BY " . $mySelectFieldName .
|
||||
" ORDER BY TotalCount DESC" .
|
||||
" LIMIT " . $nRecordLimit;
|
||||
|
||||
// Perform Database Query
|
||||
$myquery = mysql_query($szSql, $this->_dbhandle);
|
||||
if ( !$myquery )
|
||||
return ERROR_DB_QUERYFAILED;
|
||||
|
||||
// Initialize Array variable
|
||||
$aResult = array();
|
||||
|
||||
// read data records
|
||||
while ($myRow = mysql_fetch_array($myquery, MYSQL_ASSOC))
|
||||
{
|
||||
$aResult[ $myRow[$mySelectFieldName] ] = $myRow;
|
||||
}
|
||||
// $aResult[] = $myRow;
|
||||
// $aResult[ $myRow[$mySelectFieldName] ] = $myRow['TotalCount'];
|
||||
|
||||
// return finished array
|
||||
if ( count($aResult) > 0 )
|
||||
return $aResult;
|
||||
else
|
||||
return ERROR_NOMORERECORDS;
|
||||
}
|
||||
else
|
||||
{
|
||||
// return error code, field mapping not found
|
||||
return ERROR_DB_DBFIELDNOTFOUND;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Implementation of GetCountSortedByField
|
||||
*
|
||||
|
@ -681,6 +681,101 @@ class LogStreamPDO extends LogStream {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Implementation of ConsolidateDataByField
|
||||
*
|
||||
* In the PDO DB Logstream, the database will do most of the work
|
||||
*
|
||||
* @return integer Error stat
|
||||
*/
|
||||
public function ConsolidateDataByField($szFieldId, $nRecordLimit)
|
||||
{
|
||||
global $content, $dbmapping;
|
||||
|
||||
// Copy helper variables, this is just for better readability
|
||||
$szTableType = $this->_logStreamConfigObj->DBTableType;
|
||||
|
||||
if ( isset($dbmapping[$szTableType]['DBMAPPINGS'][$szFieldId]) )
|
||||
{
|
||||
// Get FieldType
|
||||
$nFieldType = $fields[$szFieldId]['FieldType'];
|
||||
|
||||
// Set DB Field name first!
|
||||
$myDBFieldName = $dbmapping[$szTableType]['DBMAPPINGS'][$szFieldId];
|
||||
$myDBQueryFieldName = $myDBFieldName;
|
||||
$mySelectFieldName = $myDBFieldName;
|
||||
|
||||
// Special handling for date fields
|
||||
if ( $nFieldType == FILTER_TYPE_DATE )
|
||||
{
|
||||
if ( $this->_logStreamConfigObj->DBType == DB_MYSQL ||
|
||||
$this->_logStreamConfigObj->DBType == DB_PGSQL )
|
||||
{
|
||||
// Helper variable for the select statement
|
||||
$mySelectFieldName = $mySelectFieldName . "grouped";
|
||||
$myDBQueryFieldName = "DATE( " . $myDBFieldName . ") AS " . $mySelectFieldName ;
|
||||
}
|
||||
else if($this->_logStreamConfigObj->DBType == DB_MSSQL )
|
||||
{
|
||||
// TODO FIND A WAY FOR MSSQL!
|
||||
}
|
||||
}
|
||||
|
||||
// Create SQL String now!
|
||||
$szSql = "SELECT " .
|
||||
$myDBQueryFieldName . ", " .
|
||||
"count(" . $myDBFieldName . ") as totalcount " .
|
||||
" FROM " . $this->_logStreamConfigObj->DBTableName .
|
||||
" GROUP BY " . $mySelectFieldName .
|
||||
" ORDER BY totalcount DESC";
|
||||
// Append LIMIT in this case!
|
||||
if ( $this->_logStreamConfigObj->DBType == DB_MYSQL ||
|
||||
$this->_logStreamConfigObj->DBType == DB_PGSQL )
|
||||
$szSql .= " LIMIT " . $nRecordLimit;
|
||||
|
||||
// Perform Database Query
|
||||
$this->_myDBQuery = $this->_dbhandle->query($szSql);
|
||||
if ( !$this->_myDBQuery )
|
||||
return ERROR_DB_QUERYFAILED;
|
||||
|
||||
if ( $this->_myDBQuery->rowCount() == 0 )
|
||||
{
|
||||
$this->_myDBQuery = null;
|
||||
return ERROR_NOMORERECORDS;
|
||||
}
|
||||
|
||||
// Initialize Array variable
|
||||
$aResult = array();
|
||||
|
||||
// read data records
|
||||
$iCount = 0;
|
||||
while ( ($myRow = $this->_myDBQuery->fetch(PDO::FETCH_ASSOC)) && $iCount < $nRecordLimit)
|
||||
{
|
||||
if ( isset($myRow[$mySelectFieldName]) )
|
||||
{
|
||||
$aResult[] = $myRow;
|
||||
// $aResult[ $myRow[$mySelectFieldName] ] = $myRow['totalcount'];
|
||||
$iCount++;
|
||||
}
|
||||
}
|
||||
|
||||
// Delete handle
|
||||
$this->_myDBQuery = null;
|
||||
|
||||
// return finished array
|
||||
if ( count($aResult) > 0 )
|
||||
return $aResult;
|
||||
else
|
||||
return ERROR_NOMORERECORDS;
|
||||
}
|
||||
else
|
||||
{
|
||||
// return error code, field mapping not found
|
||||
return ERROR_DB_DBFIELDNOTFOUND;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Implementation of GetCountSortedByField
|
||||
*
|
||||
|
@ -107,18 +107,21 @@ class Report_monilog extends Report {
|
||||
|
||||
// Step 1: Gather Summaries
|
||||
// Obtain data from the logstream!
|
||||
$reportData = $this->_streamObj->GetCountSortedByField( SYSLOG_SEVERITY, FILTER_TYPE_NUMBER, 10 );
|
||||
echo "wtf";
|
||||
|
||||
print_r ( $reportData );
|
||||
exit;
|
||||
$reportData = $this->_streamObj->ConsolidateDataByField( SYSLOG_SEVERITY, 10 );
|
||||
|
||||
// If data is valid, we have an array!
|
||||
if ( is_array($reportData) && count($reportData) > 0 )
|
||||
{
|
||||
foreach ($reportData as &$tmpReportData )
|
||||
{
|
||||
$tmpReportData['DisplayName'] = GetFacilityDisplayName( $tmpReportData[SYSLOG_SEVERITY] );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
print_r ( $reportData );
|
||||
exit;
|
||||
|
||||
// ---
|
||||
|
||||
}
|
||||
|
@ -203,7 +203,7 @@ if ( !$content['error_occured'] )
|
||||
}
|
||||
else
|
||||
{
|
||||
// Perform report output
|
||||
// Perform report output
|
||||
InitTemplateParser();
|
||||
echo $myReportObj->_baseFileName;
|
||||
exit;
|
||||
|
Loading…
x
Reference in New Issue
Block a user