mirror of
https://github.com/rsyslog/loganalyzer.git
synced 2025-09-26 11:19:26 +02:00
Imnplemented GetCountSortedByField function into pdo and mysql logstream class
This commit is contained in:
parent
1f5d518d8c
commit
a450e686a6
@ -307,7 +307,7 @@ if ( !$content['error_occured'] )
|
|||||||
|
|
||||||
// Setup Y-AXIS
|
// Setup Y-AXIS
|
||||||
$graph->yaxis->SetFont(FF_ARIAL,FS_NORMAL,8);
|
$graph->yaxis->SetFont(FF_ARIAL,FS_NORMAL,8);
|
||||||
$graph->yaxis->scale->SetGrace(10); // So the value is readable
|
$graph->yaxis->scale->SetGrace(20); // So the value is readable
|
||||||
$graph->yaxis->SetLabelAlign('center','top');
|
$graph->yaxis->SetLabelAlign('center','top');
|
||||||
$graph->yaxis->SetLabelFormat('%d');
|
$graph->yaxis->SetLabelFormat('%d');
|
||||||
$graph->yaxis->SetLabelSide(SIDE_RIGHT);
|
$graph->yaxis->SetLabelSide(SIDE_RIGHT);
|
||||||
|
@ -508,6 +508,46 @@ class LogStreamDB extends LogStream {
|
|||||||
*/
|
*/
|
||||||
public function GetCountSortedByField($szFieldId, $nFieldType, $nRecordLimit)
|
public function GetCountSortedByField($szFieldId, $nFieldType, $nRecordLimit)
|
||||||
{
|
{
|
||||||
|
global $content, $dbmapping;
|
||||||
|
|
||||||
|
// Copy helper variables, this is just for better readability
|
||||||
|
$szTableType = $this->_logStreamConfigObj->DBTableType;
|
||||||
|
|
||||||
|
if ( isset($dbmapping[$szTableType][$szFieldId]) )
|
||||||
|
{
|
||||||
|
$myDBFieldName = $dbmapping[$szTableType][$szFieldId];
|
||||||
|
|
||||||
|
// Create SQL String now!
|
||||||
|
$szSql = "SELECT " .
|
||||||
|
$myDBFieldName . ", " .
|
||||||
|
"count(" . $myDBFieldName . ") as TotalCount " .
|
||||||
|
" FROM " . $this->_logStreamConfigObj->DBTableName .
|
||||||
|
" GROUP BY " . $myDBFieldName .
|
||||||
|
" 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[$myDBFieldName] ] = $myRow['TotalCount'];
|
||||||
|
//print_r ($aResult);
|
||||||
|
//exit;
|
||||||
|
// return finished array
|
||||||
|
return $aResult;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// return error code, field mapping not found
|
||||||
|
return ERROR_DB_DBFIELDNOTFOUND;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -613,17 +613,7 @@ class LogStreamDisk extends LogStream {
|
|||||||
else
|
else
|
||||||
$aResult[ $content['LN_STATS_OTHERS'] ] = 1;
|
$aResult[ $content['LN_STATS_OTHERS'] ] = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
if ( isset($aResult[ $logArray[$szFieldId] ][CHARTDATA_COUNT]) )
|
|
||||||
$aResult[ $logArray[$szFieldId] ][CHARTDATA_COUNT]++;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$aResult[ $logArray[$szFieldId] ][CHARTDATA_NAME] = $logArray[$szFieldId];
|
|
||||||
$aResult[ $logArray[$szFieldId] ][CHARTDATA_COUNT] = 1;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
} while ( ($ret = $this->ReadNext($uID, $logArray)) == SUCCESS );
|
} while ( ($ret = $this->ReadNext($uID, $logArray)) == SUCCESS );
|
||||||
|
|
||||||
|
@ -518,6 +518,54 @@ class LogStreamPDO extends LogStream {
|
|||||||
*/
|
*/
|
||||||
public function GetCountSortedByField($szFieldId, $nFieldType, $nRecordLimit)
|
public function GetCountSortedByField($szFieldId, $nFieldType, $nRecordLimit)
|
||||||
{
|
{
|
||||||
|
global $content, $dbmapping;
|
||||||
|
|
||||||
|
// Copy helper variables, this is just for better readability
|
||||||
|
$szTableType = $this->_logStreamConfigObj->DBTableType;
|
||||||
|
|
||||||
|
if ( isset($dbmapping[$szTableType][$szFieldId]) )
|
||||||
|
{
|
||||||
|
$myDBFieldName = $dbmapping[$szTableType][$szFieldId];
|
||||||
|
|
||||||
|
// Create SQL String now!
|
||||||
|
$szSql = "SELECT " .
|
||||||
|
$myDBFieldName . ", " .
|
||||||
|
"count(" . $myDBFieldName . ") as TotalCount " .
|
||||||
|
" FROM " . $this->_logStreamConfigObj->DBTableName .
|
||||||
|
" GROUP BY " . $myDBFieldName .
|
||||||
|
" 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 )
|
||||||
|
return ERROR_NOMORERECORDS;
|
||||||
|
|
||||||
|
// Initialize Array variable
|
||||||
|
$aResult = array();
|
||||||
|
|
||||||
|
// read data records
|
||||||
|
$iCount = 0;
|
||||||
|
while ( ($myRow = $this->_myDBQuery->fetch(PDO::FETCH_ASSOC)) && $iCount < $nRecordLimit)
|
||||||
|
{
|
||||||
|
$aResult[ $myRow[$myDBFieldName] ] = $myRow['TotalCount'];
|
||||||
|
$iCount++;
|
||||||
|
}
|
||||||
|
|
||||||
|
// return finished array
|
||||||
|
return $aResult;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// return error code, field mapping not found
|
||||||
|
return ERROR_DB_DBFIELDNOTFOUND;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -58,6 +58,7 @@ define('ERROR_DB_NOPROPERTIES', 13);
|
|||||||
define('ERROR_DB_INVALIDDBMAPPING', 14);
|
define('ERROR_DB_INVALIDDBMAPPING', 14);
|
||||||
define('ERROR_DB_INVALIDDBDRIVER', 16);
|
define('ERROR_DB_INVALIDDBDRIVER', 16);
|
||||||
define('ERROR_DB_TABLENOTFOUND', 17);
|
define('ERROR_DB_TABLENOTFOUND', 17);
|
||||||
|
define('ERROR_DB_DBFIELDNOTFOUND', 19);
|
||||||
|
|
||||||
define('ERROR_MSG_NOMATCH', 18);
|
define('ERROR_MSG_NOMATCH', 18);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user