diff options
author | Ilya <ilyamaschenko@gmail.com> | 2017-09-10 00:26:07 +0900 |
---|---|---|
committer | Ilya <ilyamaschenko@gmail.com> | 2017-09-10 00:26:07 +0900 |
commit | 7a7df059267bd1013b1b8787cb49c223b1887e0c (patch) | |
tree | faabcd63bc3a2805c05d57f8518fc373695033ff | |
parent | 488c9ab42ad01cb3ced008d762c62183d4d8fde9 (diff) |
fail2ban: jails search function bugfix
-rw-r--r-- | python.d/fail2ban.chart.py | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/python.d/fail2ban.chart.py b/python.d/fail2ban.chart.py index 35761e8941..5238fa16e3 100644 --- a/python.d/fail2ban.chart.py +++ b/python.d/fail2ban.chart.py @@ -11,8 +11,8 @@ from base import LogService priority = 60000 retries = 60 -REGEX_JAILS = r_compile(r'\[([A-Za-z-_0-9]+)][^\[\]]*?(?<!# )enabled = (?:(true|false))') -REGEX_DATA = r_compile(r'\[(?P<jail>[A-Za-z-_0-9]+)\] (?P<action>(?:(U|B)))[a-z]+ (?P<ipaddr>\d{1,3}(?:\.\d{1,3}){3})') +REGEX_JAILS = r_compile(r'\[([a-zA-Z0-9_-]+)\][^\[\]]+?enabled\s+= (true|false)') +REGEX_DATA = r_compile(r'\[(?P<jail>[A-Za-z-_0-9]+)\] (?P<action>U|B)[a-z]+ (?P<ipaddr>\d{1,3}(?:\.\d{1,3}){3})') ORDER = ['jails_bans', 'jails_in_jail'] @@ -98,7 +98,6 @@ class Service(LogService): jails_list.append(jail) elif status == 'false' and jail in jails_list: jails_list.remove(jail) - # If for some reason parse failed we still can START with default jails_list. jails_list = list(set(jails_list) - set(self.exclude.split() if isinstance(self.exclude, str) else list())) or ['ssh'] @@ -182,8 +181,8 @@ def find_jails_in_files(list_of_files, print_error): for conf in list_of_files: if is_accessible(conf, R_OK): with open(conf, 'rt') as conf: - raw_data = conf.read() - data = ' '.join(raw_data.split()) + raw_data = conf.readlines() + data = ' '.join(line for line in raw_data if line.startswith(('[', 'enabled'))) jails_list.extend(REGEX_JAILS.findall(data)) else: print_error('%s is not readable or not exist' % conf) |