Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
envsetup
Manage
Activity
Members
Plan
Redmine
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Model registry
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mediaserver
envsetup
Commits
d5e42ce2
Commit
d5e42ce2
authored
6 years ago
by
Nicolas KAROLAK
Browse files
Options
Downloads
Patches
Plain Diff
add(test_fail2ban): check currently banned
parent
92f57d42
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/test_fail2ban.py
+25
-4
25 additions, 4 deletions
tests/test_fail2ban.py
with
25 additions
and
4 deletions
tests/test_fail2ban.py
+
25
−
4
View file @
d5e42ce2
...
@@ -75,9 +75,23 @@ def get_jails() -> list:
...
@@ -75,9 +75,23 @@ def get_jails() -> list:
return
jails
return
jails
def
check_jail
(
name
:
str
)
->
int
:
def
check_jail_banned
(
name
:
str
)
->
int
:
_
,
output
=
u
.
exec_cmd
(
"
fail2ban-client status {} | grep
'
Jail list
'"
.
format
(
name
))
"""
Check if there is currently banned hosts.
print
(
output
)
: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
return
0
...
@@ -95,7 +109,14 @@ def main():
...
@@ -95,7 +109,14 @@ def main():
else
:
else
:
u
.
success
(
"
fail2ban is running
"
)
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
:
if
errors
:
sys
.
exit
(
1
)
sys
.
exit
(
1
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment