From 882202e4e5546c327663bbcdb6d61b098458d033 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20MOHIER?= Date: Sun, 6 May 2018 07:22:43 +0200 Subject: [PATCH 1/7] Make the module python3 compatible Set version as 0.5.0 --- .idea/alignak-module-example.iml | 2 +- alignak_module_example/example.py | 32 +++++++++++++++---------------- setup.py | 6 +++--- version.py | 20 +++++++++---------- 4 files changed, 30 insertions(+), 30 deletions(-) diff --git a/.idea/alignak-module-example.iml b/.idea/alignak-module-example.iml index e98082a..5d551f9 100644 --- a/.idea/alignak-module-example.iml +++ b/.idea/alignak-module-example.iml @@ -2,7 +2,7 @@ - + diff --git a/alignak_module_example/example.py b/alignak_module_example/example.py index 74d98ea..8447bf2 100755 --- a/alignak_module_example/example.py +++ b/alignak_module_example/example.py @@ -25,7 +25,7 @@ import time import logging -import Queue +import queue import inspect from alignak.basemodule import BaseModule @@ -141,20 +141,20 @@ def get_alignak_configuration(self): logger.info("Test - Example in %s", inspect.stack()[0][3]) configuration = { - u'process_performance_data': True, - u'passive_service_checks_enabled': True, - u'event_handlers_enabled': True, - u'global_host_event_handler': None, - u'global_service_event_handler': None, - u'interval_length': 60, - u'check_external_commands': True, - u'passive_host_checks_enabled': True, - u'check_host_freshness': True, - u'check_service_freshness': True, - u'notifications_enabled': True, - u'flap_detection_enabled': True, - u'active_service_checks_enabled': True, - u'active_host_checks_enabled': True + 'process_performance_data': True, + 'passive_service_checks_enabled': True, + 'event_handlers_enabled': True, + 'global_host_event_handler': None, + 'global_service_event_handler': None, + 'interval_length': 60, + 'check_external_commands': True, + 'passive_host_checks_enabled': True, + 'check_host_freshness': True, + 'check_service_freshness': True, + 'notifications_enabled': True, + 'flap_detection_enabled': True, + 'active_service_checks_enabled': True, + 'active_host_checks_enabled': True } logger.info("Returning Alignak configuration to the Arbiter: %s", str(configuration)) @@ -401,7 +401,7 @@ def main(self): self.manage_brok(brok) logger.debug("time to manage %s broks (%d secs)", len(message), time.time() - start) - except Queue.Empty: + except queue.Empty: # logger.debug("No message in the module queue") time.sleep(0.1) diff --git a/setup.py b/setup.py index 8d89d93..9a90ecf 100755 --- a/setup.py +++ b/setup.py @@ -49,7 +49,7 @@ "", subdir)) if target is None: - print("Ignoring directory: %s" % (subdir)) + print(("Ignoring directory: %s" % (subdir))) continue package_files = [] @@ -64,9 +64,9 @@ data_files.append((target, package_files)) for (target, origin) in data_files: - print("Target directory: %s:" % (target)) + print(("Target directory: %s:" % (target))) for file in origin: - print(" - %s" % (file)) + print((" - %s" % (file))) print("====================================================\n") setup( diff --git a/version.py b/version.py index 3342b1a..1e94c20 100755 --- a/version.py +++ b/version.py @@ -9,22 +9,22 @@ Alignak - Daemon module as an example to build other modules """ # Package name -__pkg_name__ = u"alignak_module_EXAMPLE" +__pkg_name__ = "alignak_module_EXAMPLE" # Module type for PyPI keywords # Used for: # - PyPI keywords -__module_types__ = u"example" +__module_types__ = "example" # Application manifest -__version__ = u"0.4.1" -__author__ = u"Frédéric Mohier" -__author_email__ = u"frederic.mohier@alignak.net" -__copyright__ = u"(c) 2015-2017 - %s" % __author__ -__license__ = u"GNU Affero General Public License, version 3" -__git_url__ = u"https://github.com/Alignak-monitoring/alignak-module-example" -__doc_url__ = u"http://alignak-doc.readthedocs.io/en/latest" -__description__ = u"Alignak - Daemon module as an example to build other modules" +__version__ = "0.5.0" +__author__ = "Frédéric Mohier" +__author_email__ = "frederic.mohier@alignak.net" +__copyright__ = "(c) 2015-2017 - %s" % __author__ +__license__ = "GNU Affero General Public License, version 3" +__git_url__ = "https://github.com/Alignak-monitoring/alignak-module-example" +__doc_url__ = "http://alignak-doc.readthedocs.io/en/latest" +__description__ = "Alignak - Daemon module as an example to build other modules" __classifiers__ = [ 'Development Status :: 5 - Production/Stable', From 2c89c5d3a889eb10e7d145a592ae7194a9046b42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20MOHIER?= Date: Sun, 6 May 2018 07:31:03 +0200 Subject: [PATCH 2/7] Update travis.yml --- .travis.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 49354f8..da06aae 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,7 +2,9 @@ language: python sudo: true python: - "2.7" - # - "3.4" + - "3.4" + - "3.5" + - "3.6" # command to install dependencies # some are only used for travis/coveralls so we are installing them here only From a69dbadf84e97e8f255b39af2afd020a0ec56552 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20MOHIER?= Date: Tue, 8 May 2018 09:34:54 +0200 Subject: [PATCH 3/7] Update travis.yml --- alignak_module_example/example.py | 2 +- test/requirements.py27.txt | 2 ++ test/requirements.py34.txt | 2 ++ test/requirements.txt | 8 +++----- 4 files changed, 8 insertions(+), 6 deletions(-) create mode 100644 test/requirements.py27.txt create mode 100644 test/requirements.py34.txt diff --git a/alignak_module_example/example.py b/alignak_module_example/example.py index 8447bf2..2f48c51 100755 --- a/alignak_module_example/example.py +++ b/alignak_module_example/example.py @@ -25,7 +25,7 @@ import time import logging -import queue +from queue import Queue import inspect from alignak.basemodule import BaseModule diff --git a/test/requirements.py27.txt b/test/requirements.py27.txt new file mode 100644 index 0000000..50cd3d5 --- /dev/null +++ b/test/requirements.py27.txt @@ -0,0 +1,2 @@ +# alignak +-e git+https://github.com/Alignak-monitoring/alignak.git@develop#egg=alignak diff --git a/test/requirements.py34.txt b/test/requirements.py34.txt new file mode 100644 index 0000000..510b4bc --- /dev/null +++ b/test/requirements.py34.txt @@ -0,0 +1,2 @@ +# alignak +-e git+https://github.com/Alignak-monitoring/alignak.git@python3#egg=alignak diff --git a/test/requirements.txt b/test/requirements.txt index 77788b3..89b84b4 100644 --- a/test/requirements.txt +++ b/test/requirements.txt @@ -1,7 +1,5 @@ # Python requirements for unit tests -r ../requirements.txt -# alignak --e git+https://github.com/Alignak-monitoring/alignak.git@develop#egg=alignak unittest2 # Use py.test as test-runner @@ -12,8 +10,8 @@ coverage # Report coverage results to coveralls.io coveralls # Static code analysis libraries -pylint -pep8 -pep257 +# pylint +# pycodestyle +# pep257 # Tests time freeze freezegun From 26c9cb745c6fe486c8dfd73d832105bdd41942e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20MOHIER?= Date: Tue, 8 May 2018 10:15:19 +0200 Subject: [PATCH 4/7] Update travis.yml --- alignak_module_example/example.py | 2 +- version.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/alignak_module_example/example.py b/alignak_module_example/example.py index 2f48c51..6374386 100755 --- a/alignak_module_example/example.py +++ b/alignak_module_example/example.py @@ -25,7 +25,7 @@ import time import logging -from queue import Queue +from queue import Queue as queue import inspect from alignak.basemodule import BaseModule diff --git a/version.py b/version.py index 1e94c20..247fe0c 100755 --- a/version.py +++ b/version.py @@ -17,7 +17,7 @@ __module_types__ = "example" # Application manifest -__version__ = "0.5.0" +__version__ = "0.5.1" __author__ = "Frédéric Mohier" __author_email__ = "frederic.mohier@alignak.net" __copyright__ = "(c) 2015-2017 - %s" % __author__ From 5d83190050a7827f6786a173b2583117509ec797 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20MOHIER?= Date: Tue, 8 May 2018 10:48:55 +0200 Subject: [PATCH 5/7] Fix a bad import for Queue Empty exception --- alignak_module_example/example.py | 31 +++++++++++++++++++++++++++++-- version.py | 2 +- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/alignak_module_example/example.py b/alignak_module_example/example.py index 6374386..5b13d66 100755 --- a/alignak_module_example/example.py +++ b/alignak_module_example/example.py @@ -25,7 +25,8 @@ import time import logging -from queue import Queue as queue +from queue import Queue +from queue import Empty import inspect from alignak.basemodule import BaseModule @@ -389,6 +390,9 @@ def main(self): logger.info("starting...") + if self.to_q is None: + self.to_q = Queue() + while not self.interrupted: try: logger.debug("queue length: %s", self.to_q.qsize()) @@ -401,10 +405,33 @@ def main(self): self.manage_brok(brok) logger.debug("time to manage %s broks (%d secs)", len(message), time.time() - start) - except queue.Empty: + except Empty: # logger.debug("No message in the module queue") time.sleep(0.1) logger.info("stopping...") logger.info("stopped") + +if __name__ == '__main__': + logging.getLogger("alignak.module.example").setLevel(logging.DEBUG) + logger.setLevel(logging.DEBUG) + + # Create an Alignak module + from alignak.objects.module import Module + from alignak.modulesmanager import ModulesManager + mod = Module({ + 'module_alias': 'example', + 'module_types': 'example', + 'python_name': 'alignak_module_example', + # # Alignak backend configuration + # 'alignak_backend': 'http://127.0.0.1:5000', + # # 'token': '1489219787082-4a226588-9c8b-4e17-8e56-c1b5d31db28e', + # 'username': 'admin', 'password': 'admin', + # # Set Arbiter address as empty to not poll the Arbiter else the test will fail! + # 'alignak_host': '', + # 'alignak_port': 7770, + }) + + mod = Example(mod) + mod.main() diff --git a/version.py b/version.py index 247fe0c..5ed7f61 100755 --- a/version.py +++ b/version.py @@ -17,7 +17,7 @@ __module_types__ = "example" # Application manifest -__version__ = "0.5.1" +__version__ = "0.5.2" __author__ = "Frédéric Mohier" __author_email__ = "frederic.mohier@alignak.net" __copyright__ = "(c) 2015-2017 - %s" % __author__ From ac0c1ccac0b90633436ef1c31e87e0d86f46e43e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20MOHIER?= Date: Wed, 16 May 2018 05:35:12 +0200 Subject: [PATCH 6/7] Catch an exception for a non existing message in the queue --- alignak_module_example/example.py | 9 +++++---- version.py | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/alignak_module_example/example.py b/alignak_module_example/example.py index 5b13d66..f0af18f 100755 --- a/alignak_module_example/example.py +++ b/alignak_module_example/example.py @@ -399,10 +399,11 @@ def main(self): start = time.time() message = self.to_q.get_nowait() - for brok in message: - # Prepare and manage each brok in the queue message - brok.prepare() - self.manage_brok(brok) + if message: + for brok in message: + # Prepare and manage each brok in the queue message + brok.prepare() + self.manage_brok(brok) logger.debug("time to manage %s broks (%d secs)", len(message), time.time() - start) except Empty: diff --git a/version.py b/version.py index 5ed7f61..fbf5db0 100755 --- a/version.py +++ b/version.py @@ -17,7 +17,7 @@ __module_types__ = "example" # Application manifest -__version__ = "0.5.2" +__version__ = "0.5.3" __author__ = "Frédéric Mohier" __author_email__ = "frederic.mohier@alignak.net" __copyright__ = "(c) 2015-2017 - %s" % __author__ From 1828b7262ce98cadb691e83386dad62cb2ddc966 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20MOHIER?= Date: Wed, 16 May 2018 13:36:12 +0200 Subject: [PATCH 7/7] Catch an exception for a non existing message in the queue Set version as 0.5.4 --- alignak_module_example/example.py | 3 ++- version.py | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/alignak_module_example/example.py b/alignak_module_example/example.py index f0af18f..983b758 100755 --- a/alignak_module_example/example.py +++ b/alignak_module_example/example.py @@ -405,7 +405,8 @@ def main(self): brok.prepare() self.manage_brok(brok) - logger.debug("time to manage %s broks (%d secs)", len(message), time.time() - start) + logger.debug("time to manage %s broks (%d secs)", len(message), + time.time() - start) except Empty: # logger.debug("No message in the module queue") time.sleep(0.1) diff --git a/version.py b/version.py index fbf5db0..50f901d 100755 --- a/version.py +++ b/version.py @@ -17,7 +17,7 @@ __module_types__ = "example" # Application manifest -__version__ = "0.5.3" +__version__ = "0.5.4" __author__ = "Frédéric Mohier" __author_email__ = "frederic.mohier@alignak.net" __copyright__ = "(c) 2015-2017 - %s" % __author__