Skip to content

Commit

Permalink
Error Analyzer - Print error msg
Browse files Browse the repository at this point in the history
Explanation

This will enhance the capability of sssctl analyze tool. The new tool sssctl analyze error list will print if there is any error in sssd_domain.log.

Removing unused functions and libraries.

Resolves: #6679
  • Loading branch information
roy214 authored and Roy214 committed Apr 20, 2023
1 parent 255c01a commit aad5573
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/tools/analyzer/sss_analyze.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import argparse

from sssd.modules import request
from sssd.modules import error
from sssd.parser import SubparsersAction


Expand Down Expand Up @@ -55,9 +56,11 @@ def load_modules(self, parser, parser_grp):
"""
# Currently only the 'request' module exists
req = request.RequestAnalyzer()
err = error.ErrorAnalyzer()
cli = Analyzer()

req.setup_args(parser_grp, cli)
err.setup_args(parser_grp, cli)

def setup_args(self):
"""
Expand Down
88 changes: 88 additions & 0 deletions src/tools/analyzer/util.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import re
import logging

from sssd.source_files import Files
from sssd.source_journald import Journald
from sssd.parser import SubparsersAction
from sssd.parser import Option

logger = logging.getLogger()


class Utils:
"""
A request analyzer module, handles request tracking logic
and analysis. Parses input generated from a source Reader.
"""

def print_module_help(self, args):
"""
Print the module parser help output
Args:
args (Namespace): argparse parsed arguments
"""
self.module_parser.print_help()

def setup_args(self, parser_grp, cli):
"""
Setup module parser, subcommands, and options
Args:
parser_grp (argparse.Action): Parser group to nest
module and subcommands under
"""
desc = "Analyze request tracking module"
self.module_parser = parser_grp.add_parser('request',
description=desc,
help='Request tracking')

subparser = self.module_parser.add_subparsers(title=None,
dest='subparser',
action=SubparsersAction,
metavar='COMMANDS')

subcmd_grp = subparser.add_parser_group('Operation Modes')
cli.add_subcommand(subcmd_grp, 'list', 'List recent requests',
self.list_requests, self.list_opts)
cli.add_subcommand(subcmd_grp, 'show', 'Track individual request ID',
self.track_request, self.show_opts)

self.module_parser.set_defaults(func=self.print_module_help)

return self.module_parser

def load(self, args):
"""
Load the appropriate source reader.
Args:
args (Namespace): argparse parsed arguments
Returns:
Instantiated source object
"""
if args.source == "journald":
source = Journald()
else:
source = Files(args.logdir)
return source

def matched_line(self, source, patterns):
"""
Yield lines which match any number of patterns (OR) in
provided patterns list.
Args:
source (Reader): source Reader object
Yields:
lines matching the provided pattern(s)
"""
for line in source:
for pattern in patterns:
re_obj = re.compile(pattern)
if re_obj.search(line):
if line.startswith(' * '):
continue
yield line

0 comments on commit aad5573

Please sign in to comment.