mirror of
https://github.com/rsyslog/loganalyzer.git
synced 2025-09-26 11:19:26 +02:00
Added special date handling for mysql and pdo logstream class as well
This commit is contained in:
parent
efc27aed5f
commit
e3e640aba9
@ -515,17 +515,27 @@ class LogStreamDB extends LogStream {
|
|||||||
|
|
||||||
if ( isset($dbmapping[$szTableType][$szFieldId]) )
|
if ( isset($dbmapping[$szTableType][$szFieldId]) )
|
||||||
{
|
{
|
||||||
|
// Set DB Field name first!
|
||||||
$myDBFieldName = $dbmapping[$szTableType][$szFieldId];
|
$myDBFieldName = $dbmapping[$szTableType][$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!
|
// Create SQL String now!
|
||||||
$szSql = "SELECT " .
|
$szSql = "SELECT " .
|
||||||
$myDBFieldName . ", " .
|
$myDBQueryFieldName . ", " .
|
||||||
"count(" . $myDBFieldName . ") as TotalCount " .
|
"count(" . $myDBFieldName . ") as TotalCount " .
|
||||||
" FROM " . $this->_logStreamConfigObj->DBTableName .
|
" FROM " . $this->_logStreamConfigObj->DBTableName .
|
||||||
" GROUP BY " . $myDBFieldName .
|
" GROUP BY " . $mySelectFieldName .
|
||||||
" ORDER BY TotalCount DESC" .
|
" ORDER BY TotalCount DESC" .
|
||||||
" LIMIT " . $nRecordLimit;
|
" LIMIT " . $nRecordLimit;
|
||||||
|
|
||||||
|
|
||||||
// Perform Database Query
|
// Perform Database Query
|
||||||
$myquery = mysql_query($szSql, $this->_dbhandle);
|
$myquery = mysql_query($szSql, $this->_dbhandle);
|
||||||
@ -537,9 +547,8 @@ class LogStreamDB extends LogStream {
|
|||||||
|
|
||||||
// read data records
|
// read data records
|
||||||
while ($myRow = mysql_fetch_array($myquery, MYSQL_ASSOC))
|
while ($myRow = mysql_fetch_array($myquery, MYSQL_ASSOC))
|
||||||
$aResult[ $myRow[$myDBFieldName] ] = $myRow['TotalCount'];
|
$aResult[ $myRow[$mySelectFieldName] ] = $myRow['TotalCount'];
|
||||||
//print_r ($aResult);
|
|
||||||
//exit;
|
|
||||||
// return finished array
|
// return finished array
|
||||||
return $aResult;
|
return $aResult;
|
||||||
}
|
}
|
||||||
|
@ -525,14 +525,33 @@ class LogStreamPDO extends LogStream {
|
|||||||
|
|
||||||
if ( isset($dbmapping[$szTableType][$szFieldId]) )
|
if ( isset($dbmapping[$szTableType][$szFieldId]) )
|
||||||
{
|
{
|
||||||
|
// Set DB Field name first!
|
||||||
$myDBFieldName = $dbmapping[$szTableType][$szFieldId];
|
$myDBFieldName = $dbmapping[$szTableType][$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!
|
// Create SQL String now!
|
||||||
$szSql = "SELECT " .
|
$szSql = "SELECT " .
|
||||||
$myDBFieldName . ", " .
|
$myDBQueryFieldName . ", " .
|
||||||
"count(" . $myDBFieldName . ") as TotalCount " .
|
"count(" . $myDBFieldName . ") as TotalCount " .
|
||||||
" FROM " . $this->_logStreamConfigObj->DBTableName .
|
" FROM " . $this->_logStreamConfigObj->DBTableName .
|
||||||
" GROUP BY " . $myDBFieldName .
|
" GROUP BY " . $mySelectFieldName .
|
||||||
" ORDER BY TotalCount DESC";
|
" ORDER BY TotalCount DESC";
|
||||||
// Append LIMIT in this case!
|
// Append LIMIT in this case!
|
||||||
if ( $this->_logStreamConfigObj->DBType == DB_MYSQL ||
|
if ( $this->_logStreamConfigObj->DBType == DB_MYSQL ||
|
||||||
@ -554,7 +573,7 @@ class LogStreamPDO extends LogStream {
|
|||||||
$iCount = 0;
|
$iCount = 0;
|
||||||
while ( ($myRow = $this->_myDBQuery->fetch(PDO::FETCH_ASSOC)) && $iCount < $nRecordLimit)
|
while ( ($myRow = $this->_myDBQuery->fetch(PDO::FETCH_ASSOC)) && $iCount < $nRecordLimit)
|
||||||
{
|
{
|
||||||
$aResult[ $myRow[$myDBFieldName] ] = $myRow['TotalCount'];
|
$aResult[ $myRow[$mySelectFieldName] ] = $myRow['TotalCount'];
|
||||||
$iCount++;
|
$iCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -101,8 +101,8 @@ $CFG['Search'][] = array ( "DisplayName" => "All messages from last 31 days", "S
|
|||||||
// --- Predefined Charts!
|
// --- Predefined Charts!
|
||||||
$CFG['Charts'][] = array ( "DisplayName" => "Top Hosts", "chart_type" => CHART_BARS_HORIZONTAL, "chart_width" => 400, "chart_field" => SYSLOG_HOST, "maxrecords" => 10, "showpercent" => 0 );
|
$CFG['Charts'][] = array ( "DisplayName" => "Top Hosts", "chart_type" => CHART_BARS_HORIZONTAL, "chart_width" => 400, "chart_field" => SYSLOG_HOST, "maxrecords" => 10, "showpercent" => 0 );
|
||||||
$CFG['Charts'][] = array ( "DisplayName" => "SyslogTags", "chart_type" => CHART_CAKE, "chart_width" => 400, "chart_field" => SYSLOG_SYSLOGTAG, "maxrecords" => 10, "showpercent" => 0 );
|
$CFG['Charts'][] = array ( "DisplayName" => "SyslogTags", "chart_type" => CHART_CAKE, "chart_width" => 400, "chart_field" => SYSLOG_SYSLOGTAG, "maxrecords" => 10, "showpercent" => 0 );
|
||||||
$CFG['Charts'][] = array ( "DisplayName" => "Severities", "chart_type" => CHART_BARS_VERTICAL, "chart_width" => 400, "chart_field" => SYSLOG_SEVERITY, "maxrecords" => 10, "showpercent" => 1 );
|
$CFG['Charts'][] = array ( "DisplayName" => "Severity Occurences", "chart_type" => CHART_BARS_VERTICAL, "chart_width" => 400, "chart_field" => SYSLOG_SEVERITY, "maxrecords" => 10, "showpercent" => 1 );
|
||||||
$CFG['Charts'][] = array ( "DisplayName" => "Date", "chart_type" => CHART_CAKE, "chart_width" => 400, "chart_field" => SYSLOG_DATE, "maxrecords" => 10, "showpercent" => 0 );
|
$CFG['Charts'][] = array ( "DisplayName" => "Usage by Day", "chart_type" => CHART_CAKE, "chart_width" => 400, "chart_field" => SYSLOG_DATE, "maxrecords" => 10, "showpercent" => 1 );
|
||||||
// ---
|
// ---
|
||||||
|
|
||||||
// --- Source Options
|
// --- Source Options
|
||||||
|
Loading…
x
Reference in New Issue
Block a user