From a3e54f44f81442ee5424662c3cf66467247d9160 Mon Sep 17 00:00:00 2001 From: Jaiver Pastor Date: Tue, 5 May 2020 13:38:44 +0200 Subject: [PATCH] Fixed generate the list with all the graphs, both those configured in the configuration file and those configured in the mysql database. --- src/admin/charts.php | 8 ++++---- src/include/config.sample.php | 8 ++++---- src/include/functions_config.php | 12 ++++++++++-- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/admin/charts.php b/src/admin/charts.php index 6aa3b42..ee57907 100644 --- a/src/admin/charts.php +++ b/src/admin/charts.php @@ -432,7 +432,7 @@ if ( !isset($_POST['op']) && !isset($_GET['op']) ) // --- Process Sources $i = 0; // Help counter! - foreach ($content['CHARTS'] as &$myChart ) + foreach ($content['CHARTS'] as $chartid => &$myChart ) { // --- Set Image for Type // NonNUMERIC are config files Sources, can not be editied @@ -467,8 +467,8 @@ if ( !isset($_POST['op']) && !isset($_GET['op']) ) } else { - // define empty ID to update the template correctly. - $myChart['ID'] = ""; + // if not defined ID we use chartid how ID + if (! isset($myChart['ID']) ) { $myChart['ID'] = $chartid; } // Disallow EDIT $myChart['ActionsAllowed'] = false; @@ -508,7 +508,7 @@ if ( !isset($_POST['op']) && !isset($_GET['op']) ) $myChart['set_enabled'] = 1; } - + // --- // --- Set Chart default Filterstring diff --git a/src/include/config.sample.php b/src/include/config.sample.php index c9378ef..5426519 100644 --- a/src/include/config.sample.php +++ b/src/include/config.sample.php @@ -133,10 +133,10 @@ $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, "chart_enabled" => 1 ); -$CFG['Charts'][] = array ( "DisplayName" => "SyslogTags", "chart_type" => CHART_CAKE, "chart_width" => 400, "chart_field" => SYSLOG_SYSLOGTAG, "maxrecords" => 10, "showpercent" => 0, "chart_enabled" => 1 ); -$CFG['Charts'][] = array ( "DisplayName" => "Severity Occurences", "chart_type" => CHART_BARS_VERTICAL, "chart_width" => 400, "chart_field" => SYSLOG_SEVERITY, "maxrecords" => 10, "showpercent" => 1, "chart_enabled" => 1 ); -$CFG['Charts'][] = array ( "DisplayName" => "Usage by Day", "chart_type" => CHART_CAKE, "chart_width" => 400, "chart_field" => SYSLOG_DATE, "maxrecords" => 10, "showpercent" => 1, "chart_enabled" => 1 ); +$CFG['Charts']['Charts1'] = array ( "DisplayName" => "Top Hosts", "chart_type" => CHART_BARS_HORIZONTAL, "chart_width" => 400, "chart_field" => SYSLOG_HOST, "maxrecords" => 10, "showpercent" => 0, "chart_enabled" => 1 ); +$CFG['Charts']['Charts2'] = array ( "DisplayName" => "SyslogTags", "chart_type" => CHART_CAKE, "chart_width" => 400, "chart_field" => SYSLOG_SYSLOGTAG, "maxrecords" => 10, "showpercent" => 0, "chart_enabled" => 1 ); +$CFG['Charts']['Charts3'] = array ( "DisplayName" => "Severity Occurences", "chart_type" => CHART_BARS_VERTICAL, "chart_width" => 400, "chart_field" => SYSLOG_SEVERITY, "maxrecords" => 10, "showpercent" => 1, "chart_enabled" => 1 ); +$CFG['Charts']['Charts4'] = array ( "DisplayName" => "Usage by Day", "chart_type" => CHART_CAKE, "chart_width" => 400, "chart_field" => SYSLOG_DATE, "maxrecords" => 10, "showpercent" => 1, "chart_enabled" => 1 ); // --- // --- Configure allowed directories for File base logstream sources diff --git a/src/include/functions_config.php b/src/include/functions_config.php index 615d06b..fd8e647 100644 --- a/src/include/functions_config.php +++ b/src/include/functions_config.php @@ -952,8 +952,16 @@ function LoadChartsFromDatabase() $myrows = DB_GetAllRows($result, true); if ( isset($myrows ) && count($myrows) > 0 ) { - // Overwrite existing Charts array - unset($CFG['Charts']); + // Overwrite the existing graphics matrix but only the records of + // the database, those of the configuration file we keep. + $not_remove = array(); + foreach($CFG['Charts'] as $chartid => $myChart) + { + if (! is_numeric($chartid) ) { + $not_remove[$chartid] = $myChart; + } + } + $CFG['Charts'] = $not_remove; // Loop through all data rows foreach ($myrows as &$myChart )