-
-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fail2ban: Improve output, add unit-test
- Loading branch information
Showing
10 changed files
with
166 additions
and
57 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
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
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,47 @@ | ||
#!/usr/bin/env python3 | ||
# -*- coding: utf-8; py-indent-offset: 4 -*- | ||
# | ||
# Author: Linuxfabrik GmbH, Zurich, Switzerland | ||
# Contact: info (at) linuxfabrik (dot) ch | ||
# https://www.linuxfabrik.ch/ | ||
# License: The Unlicense, see LICENSE file. | ||
|
||
# https://github.com/Linuxfabrik/monitoring-plugins/blob/main/CONTRIBUTING.rst | ||
|
||
import sys | ||
sys.path.append("..") # Adds higher directory to python modules path. | ||
|
||
|
||
|
||
import unittest | ||
|
||
from lib.globals import * | ||
import lib.base | ||
import lib.shell | ||
|
||
|
||
class TestCheck(unittest.TestCase): | ||
|
||
check = '../fail2ban' | ||
|
||
def test_if_check_runs_EXAMPLE01_ping_nok(self): | ||
stdout, stderr, retc = lib.base.coe(lib.shell.shell_exec(self.check + ' --test=stdout/EXAMPLE01,,1')) | ||
self.assertRegex(stdout, r'Problem while testing if the fail2ban server is alive.') | ||
self.assertEqual(stderr, '') | ||
self.assertEqual(retc, STATE_UNKNOWN) | ||
|
||
def test_if_check_runs_EXAMPLE01(self): | ||
stdout, stderr, retc = lib.base.coe(lib.shell.shell_exec(self.check + ' --test=stdout/EXAMPLE01,,0')) | ||
self.assertRegex(stdout, r'IPs banned - apache-dos: 2, portscan: 0, sshd: 5432 \[WARNING\]') | ||
self.assertEqual(stderr, '') | ||
self.assertEqual(retc, STATE_WARN) | ||
|
||
def test_if_check_runs_EXAMPLE99(self): | ||
stdout, stderr, retc = lib.base.coe(lib.shell.shell_exec(self.check + ' --test=stdout/EXAMPLE99,,0')) | ||
self.assertRegex(stdout, r'No jails found.') | ||
self.assertEqual(stderr, '') | ||
self.assertEqual(retc, STATE_UNKNOWN) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |
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 @@ | ||
Server replied: pong |
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,3 @@ | ||
Status | ||
|- Number of jail: 3 | ||
`- Jail list: apache-dos, portscan, sshd |
9 changes: 9 additions & 0 deletions
9
check-plugins/fail2ban/unit-test/stdout/EXAMPLE01-status-apache-dos
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,9 @@ | ||
Status for the jail: apache-dos | ||
|- Filter | ||
| |- Currently failed: 287 | ||
| |- Total failed: 169079 | ||
| `- File list: /var/log/httpd/192.0.2.74-access.log /var/log/httpd/www.example.com-access.log /var/log/httpd/reports.example.com-access.log /var/log/httpd/test.example.com-access.log /var/log/httpd/ssl_access_log /var/log/httpd/www.example.com-access.log /var/log/httpd/cloud.example.com-access.log /var/log/httpd/access_log /var/log/httpd/time.example.com-access.log | ||
`- Actions | ||
|- Currently banned: 2 | ||
|- Total banned: 34 | ||
`- Banned IP list: |
9 changes: 9 additions & 0 deletions
9
check-plugins/fail2ban/unit-test/stdout/EXAMPLE01-status-portscan
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,9 @@ | ||
Status for the jail: portscan | ||
|- Filter | ||
| |- Currently failed: 0 | ||
| |- Total failed: 0 | ||
| `- Journal matches: _TRANSPORT=kernel | ||
`- Actions | ||
|- Currently banned: 0 | ||
|- Total banned: 0 | ||
`- Banned IP list: |
9 changes: 9 additions & 0 deletions
9
check-plugins/fail2ban/unit-test/stdout/EXAMPLE01-status-sshd
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,9 @@ | ||
Status for the jail: sshd | ||
|- Filter | ||
| |- Currently failed: 0 | ||
| |- Total failed: 0 | ||
| `- Journal matches: _SYSTEMD_UNIT=sshd.service + _COMM=sshd | ||
`- Actions | ||
|- Currently banned: 5432 | ||
|- Total banned: 0 | ||
`- Banned IP list: |