#49764 Ticket 49745 - UI add filter options for error log severity levels
Closed 3 years ago by spichugi. Opened 5 years ago by mreynolds.
mreynolds/389-ds-base ticket49745  into  master

@@ -1,7 +1,29 @@ 

+ 

  var accesslog_cont_refresh;

  var auditlog_cont_refresh;

  var auditfaillog_cont_refresh;

- var erorrslog_cont_refresh;

+ var errorslog_cont_refresh;

+ 

+ var sev_emerg =  " - EMERG - ";

+ var sev_crit =   " - CRIT - ";

+ var sev_alert =  " - ALERT - ";

+ var sev_err =    " - ERR - ";

+ var sev_warn =   " - WARN - ";

+ var sev_notice = " - NOTICE - ";

+ var sev_info =   " - INFO - ";

+ var sev_debug =  " - DEBUG - ";

+ var sev_levels = {"Emergency": sev_emerg,

+                   "Critical": sev_crit,

+                   "Alert": sev_alert,

+                   "Error": sev_err,

+                   "Warning": sev_warn,

+                   "Notice": sev_notice,

+                   "Info": sev_info,

+                   "Debug": sev_debug

+                  };

+ var sev_all_errs = [sev_emerg, sev_crit, sev_alert, sev_err];

+ var sev_all_info = [sev_warn, sev_notice, sev_info, sev_debug];

+ 

  

  function gen_ratio_chart(ratio, chart ) {

    var c3ChartDefaults = patternfly.c3ChartDefaults();
@@ -68,18 +90,18 @@ 

  function refresh_access_log () {

    var access_log = "/var/log/dirsrv/" + server_id + "/access";  // TODO - get actual log location from config

    var lines = $("#accesslog-lines").val();

-   var logging = cockpit.spawn(["tail", "-" + lines, access_log], 

+   var logging = cockpit.spawn(["tail", "-" + lines, access_log],

                                { "superuser": "try" }).done(function(data) {

-     $("#accesslog-area").text(data); 

+     $("#accesslog-area").text(data);

    });

  }

  

  function refresh_audit_log () {

    var audit_log = "/var/log/dirsrv/" + server_id + "/audit";  // TODO - get actual log location from config

    var lines = $("#auditlog-lines").val();

-   var logging = cockpit.spawn(["tail", "-" + lines, audit_log], 

+   var logging = cockpit.spawn(["tail", "-" + lines, audit_log],

                                { "superuser": "try" }).done(function(data) {

-     $("#auditlog-area").text(data); 

+     $("#auditlog-area").text(data);

    });

  }

  
@@ -95,10 +117,36 @@ 

  function refresh_errors_log () {

    var errors_log = "/var/log/dirsrv/" + server_id + "/errors";  // TODO - get actual log location from config

    var lines = $("#errorslog-lines").val();

-   var logging = cockpit.spawn(["tail", "-" + lines, errors_log], 

+   var sev_level = $("#errorslog-sev-level").val();

+   var logging = cockpit.spawn(["tail", "-" + lines, errors_log],

                                { "superuser": "try" }).done(function(data) {

+     if (sev_level != "Everything"){

+       // Filter Data

+       var lines = data.split('\n');

+       var new_data = "";

+       for (var i = 0; i < lines.length; i++){

+         var line = "";

+         if (sev_level == "Error Messages"){

+           for (var lev = 0; lev < sev_all_errs.length; lev++) {

+             if (lines[i].indexOf(sev_all_errs[lev]) != -1){

+               line = lines[i] + "\n";

+             }

+           }

+         } else if (sev_level == "Info Messages"){

+           for (var lev = 0; lev < sev_all_info.length; lev++) {

+             if (lines[i].indexOf(sev_all_info[lev]) != -1){

+               line = lines[i] + "\n";

+             }

+           }

+         } else if (lines[i].indexOf(sev_levels[sev_level]) != -1){

+           line = lines[i] + "\n";

+         }

+         // Add the filtered line to new data

+         new_data += line;

+       }

+       data = new_data;

+     }

      $("#errorslog-area").text(data);

-     

    });

  }

  
@@ -171,7 +219,6 @@ 

        $("#monitor-log-errors-page").show();

      });

  

- 

      $("#accesslog-refresh-btn").on('click', function () {

        refresh_access_log();

      });
@@ -306,6 +353,11 @@ 

        }

      });

  

+     // Refresh page after changing severity level

+     $("#errorslog-sev-level").on("change", function() {

+        refresh_errors_log();

+     });

+ 

      $(document).on('click', '.repl-detail-btn', function(e) {

        e.preventDefault();

        var data = monitor_repl_table.row( $(this).parents('tr') ).data();

@@ -589,7 +589,7 @@ 

      <h3>Errors Log</h3>

      <hr>

      <label for="errorslog-lines"> Log Lines To Show</label><select

-       class="btn btn-default dropdown ds-log-dropdown" id="errorslog-lines">

+       class="btn btn-default dropdown ds-left-margin" id="errorslog-lines">

        <option>50</option>

        <option>100</option>

        <option>200</option>
@@ -601,7 +601,24 @@ 

        <option>5000</option>

        <option>10000</option>

      </select><button id="errorslog-refresh-btn" class="ds-adj-btn">Refresh</button><label

-       class="ds-left-margin">Continuously Refresh<input type="checkbox" class="ds-sm-left-margin" id="errorslog-cont-refresh"></label>

+       class="ds-left-margin">Continuously Refresh<input type="checkbox" class="ds-sm-left-margin" id="errorslog-cont-refresh"></label><div 

+       class="dropdown ds-float-right"><label 

+       for="errorslog-sev-level">Filter Logging By Severity Level</label><select

+         class="btn btn-default dropdown ds-left-margin" id="errorslog-sev-level">

+           <option>Everything</option>

+           <option>Error Messages</option>

+           <option>Info Messages</option>

+           <option disabled>──────────</option>

+           <option>Emergency</option>

+           <option>Alert</option>

+           <option>Critical</option>

+           <option>Error</option>

+           <option>Warning</option>

+           <option>Notice</option>

+           <option>Info</option>

+           <option>Debug</option>

+         </select>

+       </div>

      <textarea id="errorslog-area" class="ds-logarea"></textarea>

      <p></p>

    </div>

Description: Add a filtering option for error logging that allows
for filtering log content by severity levels. This includes
a generic option for all "errors" and all "info messages"

https://pagure.io/389-ds-base/issue/49745

Reviewed by: ?

You have sev_emerg for "Critical". Probably, it's a mistake

I think you can avoid the repetition if you'll use some dictionary.
For instance like this:

var sev_level_dict = { "Info": " - INFO - ",
                                      "Error": " - ERR - "};

And then you can add one 'else if' here:

} else if (lines[i].indexOf(sev_level_dict[sev_level]) != -1){
        line = lines[i] + "\n";

Probably, you also can group the levels in the dict for "Error Messages" and "Info Messages" but I am not sure which way will be more efficient here, I need to think more.

rebased onto c4e353c630064ab4680e20147bb7cdca2dc0b712

5 years ago

Looks good to me! Ack.

rebased onto dec5195

5 years ago

Pull-Request has been merged by mreynolds

5 years ago

389-ds-base is moving from Pagure to Github. This means that new issues and pull requests
will be accepted only in 389-ds-base's github repository.

This pull request has been cloned to Github as issue and is available here:
- https://github.com/389ds/389-ds-base/issues/2823

If you want to continue to work on the PR, please navigate to the github issue,
download the patch from the attachments and file a new pull request.

Thank you for understanding. We apologize for all inconvenience.

Pull-Request has been closed by spichugi

3 years ago