From 84b7e93a4786e89921739e61d4c97dc87eba9cab Mon Sep 17 00:00:00 2001 From: Sean DuBois Date: Fri, 11 Jul 2014 05:08:36 +0000 Subject: [PATCH] ENH: Add version command to protocol TST: Add test for version server command --- ChangeLog | 1 + THANKS | 1 + fail2ban/client/beautifier.py | 2 ++ fail2ban/protocol.py | 1 + fail2ban/server/transmitter.py | 5 ++++- fail2ban/tests/servertestcase.py | 4 ++++ man/fail2ban-client.1 | 3 +++ 7 files changed, 16 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index bdae885c..d453e67b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -39,6 +39,7 @@ ver. 0.9.1 (2014/xx/xx) - better, faster, stronger - New features: - Added monit filter thanks Jason H Martin. + - fail2ban-client can fetch the running server version - Enhancements * Fail2ban-regex - add print-all-matched option. Closes gh-652 diff --git a/THANKS b/THANKS index 5752c475..656a4ad4 100644 --- a/THANKS +++ b/THANKS @@ -88,6 +88,7 @@ Rolf Fokkens Roman Gelfand Russell Odom SATO Kentaro +Sean DuBois Sebastian Arcus Serg G. Brester Sireyessire diff --git a/fail2ban/client/beautifier.py b/fail2ban/client/beautifier.py index cf17e54f..d94216c8 100644 --- a/fail2ban/client/beautifier.py +++ b/fail2ban/client/beautifier.py @@ -51,6 +51,8 @@ class Beautifier: try: if inC[0] == "ping": msg = "Server replied: " + response + elif inC[0] == "version": + msg = response elif inC[0] == "start": msg = "Jail started" elif inC[0] == "stop": diff --git a/fail2ban/protocol.py b/fail2ban/protocol.py index 8d053501..9a6ee675 100644 --- a/fail2ban/protocol.py +++ b/fail2ban/protocol.py @@ -38,6 +38,7 @@ protocol = [ ["status", "gets the current status of the server"], ["ping", "tests if the server is alive"], ["help", "return this output"], +["version", "return the server version"], ['', "LOGGING", ""], ["set loglevel ", "sets logging level to . Levels: CRITICAL, ERROR, WARNING, NOTICE, INFO, DEBUG"], ["get loglevel", "gets the logging level"], diff --git a/fail2ban/server/transmitter.py b/fail2ban/server/transmitter.py index 0cd30515..39157128 100644 --- a/fail2ban/server/transmitter.py +++ b/fail2ban/server/transmitter.py @@ -28,6 +28,7 @@ import time import json from ..helpers import getLogger +from .. import version # Gets the instance of the logger. logSys = getLogger(__name__) @@ -102,7 +103,9 @@ class Transmitter: elif command[0] == "get": return self.__commandGet(command[1:]) elif command[0] == "status": - return self.status(command[1:]) + return self.status(command[1:]) + elif command[0] == "version": + return version.version raise Exception("Invalid command") def __commandSet(self, command): diff --git a/fail2ban/tests/servertestcase.py b/fail2ban/tests/servertestcase.py index 9b78fda8..fd2a22cc 100644 --- a/fail2ban/tests/servertestcase.py +++ b/fail2ban/tests/servertestcase.py @@ -37,6 +37,7 @@ from ..server.jail import Jail from ..server.jailthread import JailThread from .utils import LogCaptureTestCase from ..helpers import getLogger +from .. import version try: from ..server import filtersystemd @@ -148,6 +149,9 @@ class Transmitter(TransmitterBase): def testPing(self): self.assertEqual(self.transm.proceed(["ping"]), (0, "pong")) + def testVersion(self): + self.assertEqual(self.transm.proceed(["version"]), (0, version.version)) + def testSleep(self): t0 = time.time() self.assertEqual(self.transm.proceed(["sleep", "1"]), (0, None)) diff --git a/man/fail2ban-client.1 b/man/fail2ban-client.1 index 32580e20..e2df68ed 100644 --- a/man/fail2ban-client.1 +++ b/man/fail2ban-client.1 @@ -71,6 +71,9 @@ tests if the server is alive .TP \fBhelp\fR return this output +.TP +\fBversion\fR +return the server version .IP LOGGING .TP