-
Notifications
You must be signed in to change notification settings - Fork 248
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Removing 'r' since in pattern matching we have text only.
- Loading branch information
Showing
6 changed files
with
123 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
from sssd import util | ||
from sssd.parser import SubparsersAction | ||
from sssd import sss_analyze | ||
|
||
class ErrorAnalyzer: | ||
""" | ||
An error analyzer module, list if there is any error reported by sssd_be | ||
""" | ||
module_parser = None | ||
print_opts = [] | ||
|
||
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 error check module" | ||
self.module_parser = parser_grp.add_parser('error', | ||
description=desc, | ||
help='Error checker') | ||
|
||
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', 'Print error messages found in backend', | ||
self.print_error, self.print_opts) | ||
|
||
self.module_parser.set_defaults(func=self.print_module_help) | ||
|
||
return self.module_parser | ||
|
||
def print_error(self, args): | ||
err = 0 | ||
utl = util.Utils() | ||
source = utl.load(args) | ||
component = source.Component.BE | ||
source.set_component(component, False) | ||
resp = "BE" | ||
patterns = ['sdap_async_sys_connect request failed', 'terminated by own WATCHDOG', | ||
'ldap_sasl_interactive_bind_s failed', 'Communication with KDC timed out', 'SSSD is offline', 'Backend is offline', | ||
'tsig verify failure', 'ldap_install_tls failed', 's2n exop request failed'] | ||
for line in utl.matched_line(source, patterns): | ||
err +=1 | ||
print(line) | ||
if err > 0: | ||
print("For possible solutions please refer to https://sssd.io/troubleshooting/errors.html") | ||
return |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
#!/usr/bin/env python | ||
#!/usr/bin/env python3 | ||
|
||
from sssd import sss_analyze | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import re | ||
import logging | ||
|
||
from sssd.source_files import Files | ||
from sssd.source_journald import Journald | ||
from sssd.parser import SubparsersAction | ||
|
||
logger = logging.getLogger() | ||
|
||
|
||
class Utils: | ||
|
||
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 |