Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .idea/alignak-module-example.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
73 changes: 51 additions & 22 deletions alignak_module_example/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@

import time
import logging
import Queue
from queue import Queue
from queue import Empty
import inspect

from alignak.basemodule import BaseModule
Expand Down Expand Up @@ -141,20 +142,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))
Expand Down Expand Up @@ -389,22 +390,50 @@ 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())
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)

logger.debug("time to manage %s broks (%d secs)", len(message), time.time() - start)
except Queue.Empty:
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:
# 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()
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"", subdir))

if target is None:
print("Ignoring directory: %s" % (subdir))
print(("Ignoring directory: %s" % (subdir)))
continue

package_files = []
Expand All @@ -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(
Expand Down
2 changes: 2 additions & 0 deletions test/requirements.py27.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# alignak
-e git+https://github.com/Alignak-monitoring/alignak.git@develop#egg=alignak
2 changes: 2 additions & 0 deletions test/requirements.py34.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# alignak
-e git+https://github.com/Alignak-monitoring/alignak.git@python3#egg=alignak
8 changes: 3 additions & 5 deletions test/requirements.txt
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
20 changes: 10 additions & 10 deletions version.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"[email protected]"
__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.4"
__author__ = "Frédéric Mohier"
__author_email__ = "[email protected]"
__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',
Expand Down