Skip to content
Snippets Groups Projects
Commit 9124eeb0 authored by Stéphane Diemer's avatar Stéphane Diemer
Browse files

Fixed fail2ban test when no jails are configured | refs #33101

parent 61be8f6d
No related branches found
Tags mediaserver-9.4.0
No related merge requests found
...@@ -93,7 +93,14 @@ def get_jails() -> list: ...@@ -93,7 +93,14 @@ def get_jails() -> list:
_, output = exec_cmd( _, output = exec_cmd(
"fail2ban-client status | grep 'Jail list'", log_output=False "fail2ban-client status | grep 'Jail list'", log_output=False
) )
jails = output.split(":")[1].strip().replace(" ", "").split(",") if ":" not in output:
return list()
jails_str = output.split(":")[1].strip().replace(" ", "").strip(",")
if not jails_str:
return list()
jails = jails_str.split(",")
return jails return jails
...@@ -111,6 +118,9 @@ def check_jail_banned(name: str) -> int: ...@@ -111,6 +118,9 @@ def check_jail_banned(name: str) -> int:
"fail2ban-client status {} | grep 'Currently banned'".format(name), "fail2ban-client status {} | grep 'Currently banned'".format(name),
log_output=False, log_output=False,
) )
if ":" not in output:
return 0
banned = output.split(":")[1].strip() banned = output.split(":")[1].strip()
if banned: if banned:
...@@ -146,6 +156,8 @@ def main(): ...@@ -146,6 +156,8 @@ def main():
banned = check_jail_banned(jail) banned = check_jail_banned(jail)
if banned > 0: if banned > 0:
lg.info("there is {} banned host in {} jail".format(banned, jail)) lg.info("there is {} banned host in {} jail".format(banned, jail))
else:
lg.info("no banned host in {} jail".format(jail))
if errors: if errors:
exit(1) exit(1)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment