Skip to content

Commit

Permalink
Closes #488: notify Alignak arbiter for some configuration modificati…
Browse files Browse the repository at this point in the history
…ons (new host, new realm)
  • Loading branch information
mohierf committed Feb 23, 2018
1 parent 4a1212b commit c44a67c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
28 changes: 27 additions & 1 deletion alignak_backend/app.py
Expand Up @@ -25,6 +25,9 @@

import logging
from logging.config import dictConfig as logger_dictConfig

import requests

from dateutil import parser

from future.utils import iteritems
Expand Down Expand Up @@ -205,6 +208,21 @@ def _validate_schema_version(self, schema_version, field, value):
return


def notify_alignak(notification='reload_configuration'):
"""Send a notification to the Alignak arbiter if configured"""
if not settings['ALIGNAK_URL'] or not notification:
return

headers = None
try:
current_app.logger.info("Notifying Alignak for: %s..." % notification)
response = requests.get(settings['ALIGNAK_URL'] + notification, headers=headers, timeout=10)
resp = response.json()
current_app.logger.info("Notified, response: %s..." % resp)
except Exception as exp:
current_app.logger.error("Alignak notification exception: %s..." % str(exp))


# Hooks used to check user's rights
def pre_get(resource, user_request, lookup):
"""Hook before get data. Add filter depend on roles of user
Expand Down Expand Up @@ -1235,6 +1253,9 @@ def after_insert_realm(items):
}, False, False, **lookup)
g.updateRealm = False

# Notify Alignak
notify_alignak(notification='reload_configuration')


def after_update_realm(updated, original):
"""
Expand Down Expand Up @@ -1536,6 +1557,9 @@ def after_insert_host(items):
if etags:
g.replace_etags = etags

# Notify Alignak
notify_alignak(notification='reload_configuration')


def pre_service_patch(updates, original):
"""
Expand Down Expand Up @@ -2027,6 +2051,8 @@ def get_settings(prev_settings):
settings['SCHEDULER_TIMEZONE'] = 'Etc/GMT'
settings['JOBS'] = []

settings['ALIGNAK_URL'] = ''

# Read configuration file to update/complete the configuration
configuration_file = get_settings(settings)
print("Application configuration file: %s" % configuration_file)
Expand Down Expand Up @@ -2079,7 +2105,7 @@ def get_settings(prev_settings):
settings['DOMAIN'] = register_models()

base_path = os.path.dirname(os.path.abspath(alignak_backend.__file__))
print("Application base path: %s" % base_path)
# print("Application base path: %s" % base_path)

app = Eve(
settings=settings,
Expand Down
6 changes: 6 additions & 0 deletions etc/settings.json
Expand Up @@ -27,6 +27,12 @@

"LOGGER": "alignak-backend-logger.json", /* Python logger configuration file */

/* Address of Alignak arbiter
The Alignak backend will use this adress to notify Alignak about backend newly created items
Set to an empty value to disable this feature
*/
"ALIGNAK_URL": "http://127.0.0.1:7770",

/* As soon as a Graphite or Influx is existing in the backend, the received metrics are sent
to the corresponding TSDB. If the TSDB is not available, metrics are stored internally
in the backend.
Expand Down

0 comments on commit c44a67c

Please sign in to comment.