charts orderby config; see readme for more details

This commit is contained in:
Vitaly X 2023-01-03 23:39:16 +02:00
parent 27bb2db6d6
commit 0e1114846d
12 changed files with 87 additions and 46 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
src/config.php

View File

@ -3,6 +3,10 @@
Adiscon LogAnalyzer, a web frontend to log data from the same folks the created rsyslog
# changes
- Maximize view by default
- fix chart double adding same key into search
- allow to configure ORDER BY clause
- add custom filter to chart value redirection link if such exists
- support number ranges in filter, i.e. severity:3-6 -> where severity in (3,4,5,6)
- support quoted filters, i.e. syslogtag:-="dhcp,info",-="wireless,info",-"system%,account" -> where (syslogtag <> 'dhcp,info' AND syslogtag <> 'wireless,info' AND syslogtag NOT LIKE '%system%,account%' )
- support TRACE syslog level;

View File

@ -154,7 +154,8 @@ if ( isset($_GET['op']) )
$content['CHECKED_ISSHOWPERCENT'] = "";
$content['chart_defaultfilter'] = "";
// Chart Field
$content['chart_field'] = SYSLOG_HOST;
$content['chart_field'] = SYSLOG_HOST;
$content['chart_orderby'] = '';
CreateChartFields($content['chart_field']);
// COMMON Fields
@ -194,7 +195,6 @@ if ( isset($_GET['op']) )
{
// Get Source reference
$myChart = $content['Charts'][ $content['CHARTID'] ];
// Copy basic properties
$content['Name'] = $myChart['DisplayName'];
$content['chart_type'] = $myChart['chart_type'];
@ -216,7 +216,8 @@ if ( isset($_GET['op']) )
// Chart Field
$content['chart_field'] = $myChart['chart_field'];
CreateChartFields($content['chart_field']);
$content['chart_orderby'] = $myChart['chart_orderby'];
// COMMON Fields
$content['userid'] = $myChart['userid'];
if ( $content['userid'] != null )
@ -317,6 +318,7 @@ if ( isset($_POST['op']) )
if ( isset($_POST['chart_type']) ) { $content['chart_type'] = intval(DB_RemoveBadChars($_POST['chart_type'])); }
if ( isset($_POST['chart_width']) ) { $content['chart_width'] = intval(DB_RemoveBadChars($_POST['chart_width'])); } else {$content['chart_width'] = 400; }
if ( isset($_POST['chart_field']) ) { $content['chart_field'] = DB_RemoveBadChars($_POST['chart_field']); }
if ( isset($_POST['chart_orderby']) ) { $content['chart_orderby'] = DB_RemoveBadChars($_POST['chart_orderby']); }
if ( isset($_POST['maxrecords']) ) { $content['maxrecords'] = intval(DB_RemoveBadChars($_POST['maxrecords'])); }
if ( isset($_POST['showpercent']) ) { $content['showpercent'] = intval(DB_RemoveBadChars($_POST['showpercent'])); } else {$content['showpercent'] = 0; }
if ( isset($_POST['chart_defaultfilter']) ) { $content['chart_defaultfilter'] = DB_RemoveBadChars($_POST['chart_defaultfilter']); }
@ -369,12 +371,13 @@ if ( isset($_POST['op']) )
if ( $_POST['op'] == "addnewchart" )
{
// Add custom search now!
$sqlquery = "INSERT INTO " . DB_CHARTS . " (DisplayName, chart_enabled, chart_type, chart_width, chart_field, chart_defaultfilter, maxrecords, showpercent, userid, groupid)
$sqlquery = "INSERT INTO " . DB_CHARTS . " (DisplayName, chart_enabled, chart_type, chart_width, chart_field, chart_orderby, chart_defaultfilter, maxrecords, showpercent, userid, groupid)
VALUES ('" . $content['Name'] . "',
" . $content['chart_enabled'] . ",
" . $content['chart_type'] . ",
" . $content['chart_width'] . ",
'" . $content['chart_field'] . "',
'" . $content['chart_orderby'] . "',
'" . $content['chart_defaultfilter'] . "',
" . $content['maxrecords'] . ",
" . $content['showpercent'] . ",
@ -405,6 +408,7 @@ if ( isset($_POST['op']) )
chart_type = " . $content['chart_type'] . ",
chart_width = " . $content['chart_width'] . ",
chart_field = '" . $content['chart_field'] . "',
chart_orderby = '" . $content['chart_orderby'] . "',
chart_defaultfilter = '" . $content['chart_defaultfilter'] . "',
maxrecords = " . $content['maxrecords'] . ",
showpercent = " . $content['showpercent'] . ",
@ -514,6 +518,12 @@ if ( !isset($_POST['op']) && !isset($_GET['op']) )
$myChart['chart_defaultfilter_urldecoded'] = urlencode($myChart['chart_defaultfilter']);
else
$myChart['chart_defaultfilter_urldecoded'] = "";
if ( ( isset($myChart['chart_orderby']) ) && ( strlen($myChart['chart_orderby']) > 0 ) )
$myChart['chart_orderby_urldecoded'] = urlencode($myChart['chart_orderby']);
else
$myChart['chart_orderby_urldecoded'] = "";
// ---
// --- Set CSS Class
@ -544,4 +554,4 @@ $page -> parser($content, "admin/admin_charts.html");
$page -> output();
// ---
?>
?>

View File

@ -98,6 +98,11 @@ else
$content['error_details'] = $content['LN_GEN_ERROR_MISSINGCHARTFIELD'];
}
if ( isset($_GET['orderby']) )
{
$content['chart_orderby'] = $_GET['orderby'];
}else { $content['chart_orderby'] = NULL; }
if ( isset($_GET['maxrecords']) )
{
// read and verify value
@ -148,7 +153,7 @@ if ( !$content['error_occured'] )
{
// Obtain and get the Config Object
$stream_config = $content['Sources'][$currentSourceID]['ObjRef'];
//echo "filter:".$content['chart_defaultfilter']."<br>";
// Create LogStream Object
$stream = $stream_config->LogStreamFactory($stream_config);
$stream->SetFilter($content['chart_defaultfilter']);
@ -160,7 +165,7 @@ if ( !$content['error_occured'] )
if ( $aFilterFields != null )
$content['ChartColumns'] = $aFilterFields;
// Append mandetory fields
// Append mandatory fields
if ( !in_array(SYSLOG_UID, $content['ChartColumns']) )
$content['ChartColumns'][] = SYSLOG_UID;
if ( !in_array($content['chart_field'], $content['ChartColumns']) )
@ -182,9 +187,9 @@ if ( !$content['error_occured'] )
// Split key and value
$tmpArray = explode(":", $myFilter, 2);
// Check if keyfield is valid and add to our Columns array if available
// Check if keyfield is valid and add to our Columns array only if it's not there yet
$newField = $stream->ReturnFilterKeyBySearchField($tmpArray[FILTER_TMP_KEY]);
if ( $newField )
if ( $newField && !in_array($newField,$content['ChartColumns']))
$content['ChartColumns'][] = $newField;
}
}
@ -195,8 +200,8 @@ if ( !$content['error_occured'] )
if ( $res == SUCCESS )
{
// Obtain data from the logstream!
$chartData = $stream->GetCountSortedByField($content['chart_field'], $content['chart_fieldtype'], $content['maxrecords']);
$chartData = $stream->GetCountSortedByField($content['chart_field'], $content['chart_fieldtype'], $content['maxrecords'], $content['chart_orderby']);
//echo "<pre>";echo print_r($chartData); echo "</pre><br>";
// If data is valid, we have an array!
if ( is_array($chartData) && count($chartData) > 0 )
{
@ -210,7 +215,7 @@ if ( !$content['error_occured'] )
$YchartData[] = intval($myData);
$XchartData[] = strlen($myKey) > 0 ? $myKey : "Unknown";
if ( isset($fields[$content['chart_field']]['SearchField']) && strlen($myKey) > 0 )
$chartImageMapLinks[] = $content['custombasepath'] . "index.php?filter=" . $fields[$content['chart_field']]['SearchField'] . "%3A%3D" . urlencode($szEncodedKeyStr) . "&search=Search";
$chartImageMapLinks[] = $content['custombasepath'] . "index.php?filter=" . $fields[$content['chart_field']]['SearchField'] . "%3A%3D" . urlencode($szEncodedKeyStr) .(empty($content['chart_defaultfilter'])?"":urlencode(" ".$content['chart_defaultfilter'])). "&search=Search";
else
$chartImageMapLinks[] = "";
@ -552,4 +557,4 @@ function OutpuCustomErrorMessage() {
// Exit in any case
exit;
}
?>
?>

View File

@ -1270,8 +1270,11 @@ class LogStreamDB extends LogStream {
*
* @return integer Error stat
*/
public function GetCountSortedByField($szFieldId, $nFieldType, $nRecordLimit)
public function GetCountSortedByField($szFieldId, $nFieldType, $nRecordLimit, $orderBy='')
{
if(empty($orderBy)){
$orderBy = 'totalcount DESC';
}
global $content, $dbmapping;
// Copy helper variables, this is just for better readability
@ -1283,13 +1286,14 @@ class LogStreamDB extends LogStream {
$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 ;
//$orderBy = $mySelectFieldName." DESC";
}
// Create SQL Where Clause!
@ -1307,7 +1311,7 @@ class LogStreamDB extends LogStream {
" FROM `" . $this->_logStreamConfigObj->DBTableName . "`" .
$this->_SQLwhereClause .
" GROUP BY " . $mySelectFieldName .
" ORDER BY totalcount DESC" .
" ORDER BY ".$orderBy.
" LIMIT " . $nRecordLimit;
// Perform Database Query
@ -1365,6 +1369,7 @@ class LogStreamDB extends LogStream {
// --- Build Query Array
$arrayQueryProperties = $this->_arrProperties;
//"<pre>".$arrayQueryProperties."</pre><br>"
if ( isset($this->_arrFilterProperties) && $this->_arrFilterProperties != null)
{
foreach ( $this->_arrFilterProperties as $filterproperty )
@ -1373,8 +1378,9 @@ class LogStreamDB extends LogStream {
$arrayQueryProperties[] = $filterproperty;
}
}
// ---
// ---
//echo 'DEBUG <pre>'; print_r($arrayQueryProperties); echo '</pre>';
//echo 'DEBUG <pre>'; print_r($this->_filters); echo '</pre>';
// Loop through all available properties
foreach( $arrayQueryProperties as $propertyname )
{
@ -1496,26 +1502,8 @@ class LogStreamDB extends LogStream {
if ( $myfilter[FILTER_DATEMODE] == DATEMODE_LASTX )
{
// Get current timestamp
$nNowTimeStamp = time() - (60 * 60 * intval($myfilter[FILTER_VALUE]));
/*if ( $myfilter[FILTER_VALUE] == DATE_LASTX_HOUR )
$nNowTimeStamp -= 60 * 60; // One Hour!
else if ( $myfilter[FILTER_VALUE] == DATE_LASTX_12HOURS )
$nNowTimeStamp -= 60 * 60 * 12; // 12 Hours!
else if ( $myfilter[FILTER_VALUE] == DATE_LASTX_24HOURS )
$nNowTimeStamp -= 60 * 60 * 24; // 24 Hours!
else if ( $myfilter[FILTER_VALUE] == DATE_LASTX_7DAYS )
$nNowTimeStamp -= 60 * 60 * 24 * 7; // 7 days
else if ( $myfilter[FILTER_VALUE] == DATE_LASTX_31DAYS )
$nNowTimeStamp -= 60 * 60 * 24 * 31; // 31 days
else
{
// Set filter to unknown and Abort in this case!
$tmpfilters[$propertyname][FILTER_TYPE] = FILTER_TYPE_UNKNOWN;
break;
}*/
// Append filter
$tmpfilters[$propertyname][FILTER_VALUE] .= $dbmapping[$szTableType]['DBMAPPINGS'][$propertyname] . " > '" . date("Y-m-d H:i:s", $nNowTimeStamp) . "'";
}
@ -1554,7 +1542,6 @@ class LogStreamDB extends LogStream {
}
}
}
// Check and combine all filters now!
if ( isset($tmpfilters) )
{
@ -1587,7 +1574,7 @@ class LogStreamDB extends LogStream {
}
}
// echo $this->_SQLwhereClause;
//echo $this->_SQLwhereClause."<br>";
//$dbmapping[$szTableType][SYSLOG_UID]
}
else // No filters means nothing to do!

View File

@ -0,0 +1,7 @@
-- New Database Structure Updates
ALTER TABLE `logcon_charts` ADD `chart_orderby` VARCHAR( 255 ) NULL AFTER `chart_defaultfilter` ;
-- Insert data
-- Updated Data

View File

@ -510,6 +510,8 @@ function CreateReloadTimesList()
$tmpReloadSeconds = GetConfigSetting("ViewEnableAutoReloadSeconds", "", CFGLEVEL_USER);
if ( $tmpReloadSeconds > 0 )
{
//by default select predefined value
$_SESSION['AUTORELOAD_ID'] = 1;
$content['reloadtimes'][$iCounter] = array( "ID" => $iCounter, "Selected" => "", "DisplayName" => $content['LN_AUTORELOAD_PRECONFIGURED'] . " (" . $tmpReloadSeconds . " " . $content['LN_AUTORELOAD_SECONDS'] . ") ", "Value" => $tmpReloadSeconds ); $iCounter++;
}
$content['reloadtimes'][$iCounter] = array( "ID" => $iCounter, "Selected" => "", "DisplayName" => " 5 " . $content['LN_AUTORELOAD_SECONDS'], "Value" => 5 ); $iCounter++;

View File

@ -930,7 +930,8 @@ function LoadChartsFromDatabase()
DB_CHARTS . ".chart_enabled, " .
DB_CHARTS . ".chart_type, " .
DB_CHARTS . ".chart_width, " .
DB_CHARTS . ".chart_field, " .
DB_CHARTS . ".chart_field, " .
DB_CHARTS . ".chart_orderby, " .
DB_CHARTS . ".chart_defaultfilter, " .
DB_CHARTS . ".maxrecords, " .
DB_CHARTS . ".showpercent, " .

View File

@ -122,11 +122,14 @@ $content['main_pager_last_found'] = false;
// Init Sorting variables
$content['sorting'] = "";
$content['searchstr'] = "";
$content['searchstr_htmlform'] = "datelastx:6";
$content['searchstr_htmlform'] = "datelastx:6 severity:-8";
$content['highlightstr'] = "";
$content['highlightstr_htmlform'] = "";
$content['EXPAND_HIGHLIGHT'] = "false";
// hide header by default
$_SESSION['SESSION_MAXIMIZED'] = true;
// --- Read and process filters from search dialog!
if ( (isset($_POST['search']) || isset($_GET['search'])) || (isset($_POST['filter']) || isset($_GET['filter'])) )
{

View File

@ -110,6 +110,12 @@ if ( isset($content['Charts']) )
$myChart['chart_defaultfilter_urldecoded'] = urlencode($myChart['chart_defaultfilter']);
else
$myChart['chart_defaultfilter_urldecoded'] = "";
if ( isset($myChart['chart_orderby']) && strlen($myChart['chart_orderby']) > 0 )
$myChart['chart_orderby_urldecoded'] = urlencode($myChart['chart_orderby']);
else
$myChart['chart_orderby_urldecoded'] = "";
// ---
// --- Set CSS Class
@ -159,4 +165,4 @@ $page -> output();
//include($gl_root_path . 'include/functions_installhelpers.php');
//ConvertCustomCharts();
?>
?>

View File

@ -68,7 +68,7 @@
&nbsp;<a href="#" id="dialog-chart_{ID}"><img src="{MENU_CHART_PREVIEW}" width="16" title="{LN_CHARTS_PREVIEW}"></a>
<script> $( "#dialog-chart_{ID}" ).click(function( event ) {
$( "#dialog").html('<center></br><img src="{BASEPATH}images/ajax-loader.gif"></br></br></center>');
$( "#dialog").load('{BASEPATH}chartgenerator.php?type={chart_type}&byfield={chart_field}&width={chart_width}&maxrecords={maxrecords}&showpercent={showpercent}&defaultfilter={chart_defaultfilter_urldecoded}&basepath={BASEPATH}');
$( "#dialog").load('{BASEPATH}chartgenerator.php?type={chart_type}&byfield={chart_field}&orderby={chart_orderby_urldecoded}&width={chart_width}&maxrecords={maxrecords}&showpercent={showpercent}&defaultfilter={chart_defaultfilter_urldecoded}&basepath={BASEPATH}');
$( "#dialog").dialog("option","position",$("#dialog").dialog("option","position"));
$( "#dialog").dialog( {title: "Chartgenerator"});
$( "#dialog").dialog( "open" );
@ -119,6 +119,11 @@
</select>
</td>
</tr>
<tr>
<td align="left" class="cellmenu2" nowrap><b>{LN_CHART_ORDERBY}</b></td>
<td align="left" class="line1"><input type="text" name="chart_orderby" size="55" maxlength="255" value='{chart_orderby}' class="maxwidth"></td>
</tr>
<tr>
<td align="left" class="cellmenu2" nowrap><b>{LN_CHART_WIDTH}</b></td>
<td align="left" class="line1"><input type="text" name="chart_width" size="55" maxlength="255" value="{chart_width}" class="maxwidth"></td>
@ -133,7 +138,7 @@
</tr>
<tr>
<td align="left" class="cellmenu2_naked" valign="top" nowrap><b>{LN_CHARTS_FILTERSTRING}</b></td>
<td align="left" class="line1"><font class="ErrorMsg">{LN_CHARTS_FILTERSTRING_HELP}</font></br><input type="text" name="chart_defaultfilter" size="100" maxlength="1024" value="{chart_defaultfilter}" class="maxwidth"></td>
<td align="left" class="line1"><font class="ErrorMsg">{LN_CHARTS_FILTERSTRING_HELP}</font></br><input type="text" name="chart_defaultfilter" size="100" maxlength="1024" value='{chart_defaultfilter}' class="maxwidth"></td>
</tr>
<tr>
@ -201,4 +206,4 @@ $(window).resize(function() {
*/
</script>
<!-- INCLUDE include_footer.html -->
<!-- INCLUDE include_footer.html -->

View File

@ -43,6 +43,15 @@
<td class="cellmenu2" nowrap><B>{LN_CHART_FIELD}</B></td>
<td class="line2">&nbsp;{CHART_FIELD_DISPLAYNAME}</td>
</tr>
<tr>
<td class="cellmenu2" nowrap><B>{LN_CHART_ORDERBY}</B></td>
<td class="line2">&nbsp;{chart_orderby}</td>
</tr>
<tr>
<td class="cellmenu2" nowrap><B>{LN_CHART_FILTER}</B></td>
<td class="line2">&nbsp;{chart_defaultfilter}</td>
</tr>
<tr>
<td class="cellmenu2" nowrap><B>{LN_CHART_WIDTH}</B></td>
<td class="line1">&nbsp;{chart_width}</td>
@ -59,7 +68,7 @@
<div id="Chart{CHART_ID}"></div>
<script>
$( "#Chart{CHART_ID}").html('<center></br><img src="images/ajax-loader.gif"></br></br></center>');
$( "#Chart{CHART_ID}").load('{BASEPATH}chartgenerator.php?type={chart_type}&byfield={chart_field}&width={chart_width}&maxrecords={maxrecords}&showpercent={showpercent}&defaultfilter={chart_defaultfilter_urldecoded}');
$( "#Chart{CHART_ID}").load('{BASEPATH}chartgenerator.php?type={chart_type}&byfield={chart_field}&orderby={chart_orderby_urldecoded}&width={chart_width}&maxrecords={maxrecords}&showpercent={showpercent}&defaultfilter={chart_defaultfilter_urldecoded}');
</script>
</td></tr>
</table>
@ -70,4 +79,4 @@
</table>
<!-- ENDIF statsenabled="true" -->
<!-- INCLUDE include_footer.html -->
<!-- INCLUDE include_footer.html -->