Skip to content
Snippets Groups Projects
Commit d5e42ce2 authored by Nicolas KAROLAK's avatar Nicolas KAROLAK
Browse files

add(test_fail2ban): check currently banned

parent 92f57d42
No related branches found
No related tags found
No related merge requests found
......@@ -75,9 +75,23 @@ def get_jails() -> list:
return jails
def check_jail(name: str) -> int:
_, output = u.exec_cmd("fail2ban-client status {} | grep 'Jail list'".format(name))
print(output)
def check_jail_banned(name: str) -> int:
"""Check if there is currently banned hosts.
:param name: Jail name
:type name: str
:return: Number of banned hosts
:rtype: int
"""
_, output = u.exec_cmd(
"fail2ban-client status {} | grep 'Currently banned'".format(name)
)
banned = output.split(":")[1].replace(" ", "")
if banned:
return banned
return 0
......@@ -95,7 +109,14 @@ def main():
else:
u.success("fail2ban is running")
# print("Checking fail2ban jails:")
print("Checking fail2ban jails:")
jails = get_jails()
for jail in jails:
u.info("{} jail is running".format(jail))
banned = check_jail_banned(jail)
if banned > 0:
u.warning("there is {} banned host in {} jail".format(banned, jail))
warnings += 1
if errors:
sys.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