diff --git a/src/classes/logstreamdb.class.php b/src/classes/logstreamdb.class.php index 7d1e0c2..b16d6dc 100644 --- a/src/classes/logstreamdb.class.php +++ b/src/classes/logstreamdb.class.php @@ -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; } diff --git a/src/classes/logstreampdo.class.php b/src/classes/logstreampdo.class.php index 9dcc3fc..7ffe344 100644 --- a/src/classes/logstreampdo.class.php +++ b/src/classes/logstreampdo.class.php @@ -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++; } diff --git a/src/include/config.sample.php b/src/include/config.sample.php index 9ad76f6..7477c83 100644 --- a/src/include/config.sample.php +++ b/src/include/config.sample.php @@ -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