Added special date handling for mysql and pdo logstream class as well

This commit is contained in:
unknown 2008-09-11 17:37:17 +02:00
parent efc27aed5f
commit e3e640aba9
3 changed files with 39 additions and 11 deletions

View File

@ -515,17 +515,27 @@ class LogStreamDB extends LogStream {
if ( isset($dbmapping[$szTableType][$szFieldId]) )
{
// Set DB Field name first!
$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!
$szSql = "SELECT " .
$myDBFieldName . ", " .
$myDBQueryFieldName . ", " .
"count(" . $myDBFieldName . ") as TotalCount " .
" FROM " . $this->_logStreamConfigObj->DBTableName .
" GROUP BY " . $myDBFieldName .
" GROUP BY " . $mySelectFieldName .
" ORDER BY TotalCount DESC" .
" LIMIT " . $nRecordLimit;
// Perform Database Query
$myquery = mysql_query($szSql, $this->_dbhandle);
@ -537,9 +547,8 @@ class LogStreamDB extends LogStream {
// read data records
while ($myRow = mysql_fetch_array($myquery, MYSQL_ASSOC))
$aResult[ $myRow[$myDBFieldName] ] = $myRow['TotalCount'];
//print_r ($aResult);
//exit;
$aResult[ $myRow[$mySelectFieldName] ] = $myRow['TotalCount'];
// return finished array
return $aResult;
}

View File

@ -525,14 +525,33 @@ class LogStreamPDO extends LogStream {
if ( isset($dbmapping[$szTableType][$szFieldId]) )
{
// Set DB Field name first!
$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!
$szSql = "SELECT " .
$myDBFieldName . ", " .
$myDBQueryFieldName . ", " .
"count(" . $myDBFieldName . ") as TotalCount " .
" FROM " . $this->_logStreamConfigObj->DBTableName .
" GROUP BY " . $myDBFieldName .
" GROUP BY " . $mySelectFieldName .
" ORDER BY TotalCount DESC";
// Append LIMIT in this case!
if ( $this->_logStreamConfigObj->DBType == DB_MYSQL ||
@ -554,7 +573,7 @@ class LogStreamPDO extends LogStream {
$iCount = 0;
while ( ($myRow = $this->_myDBQuery->fetch(PDO::FETCH_ASSOC)) && $iCount < $nRecordLimit)
{
$aResult[ $myRow[$myDBFieldName] ] = $myRow['TotalCount'];
$aResult[ $myRow[$mySelectFieldName] ] = $myRow['TotalCount'];
$iCount++;
}

View File

@ -101,8 +101,8 @@ $CFG['Search'][] = array ( "DisplayName" => "All messages from last 31 days", "S
// --- 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" => "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" => "Date", "chart_type" => CHART_CAKE, "chart_width" => 400, "chart_field" => SYSLOG_DATE, "maxrecords" => 10, "showpercent" => 0 );
$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" => "Usage by Day", "chart_type" => CHART_CAKE, "chart_width" => 400, "chart_field" => SYSLOG_DATE, "maxrecords" => 10, "showpercent" => 1 );
// ---
// --- Source Options