From 358b6c360d496d61ab9453bcfd2e31d38038eeee Mon Sep 17 00:00:00 2001 From: Matthieu Estrada Date: Wed, 28 Feb 2018 10:40:13 +0100 Subject: [PATCH] Add realm in requests and qthreads Ref #245 --- alignak_app/backend/backend.py | 30 +++++++++++++++++++++++++++ alignak_app/qthreads/thread.py | 2 ++ alignak_app/qthreads/threadmanager.py | 2 +- 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/alignak_app/backend/backend.py b/alignak_app/backend/backend.py index 38a9afe..6b5330c 100644 --- a/alignak_app/backend/backend.py +++ b/alignak_app/backend/backend.py @@ -40,6 +40,7 @@ from alignak_app.items.livesynthesis import LiveSynthesis from alignak_app.items.service import Service from alignak_app.items.user import User +from alignak_app.items.realm import Realm from alignak_app.utils.config import settings @@ -286,6 +287,35 @@ def get_period_name(self, endpoint_id): return 'n/a' + def query_realms_data(self): + """ + Launch a request on ``realm`` endpoint + + """ + + request_data = Realm.get_request_model() + + request = self.get( + request_data['endpoint'], + request_data['params'], + request_data['projection'] + ) + + if request: + realms_list = [] + for item in request['_items']: + realm = Realm() + + realm.create( + item['_id'], + item, + item['name'], + ) + realms_list.append(realm) + + if realms_list: + data_manager.update_database('realm', realms_list) + def query_user_data(self): """ Launch request for "user" endpoint diff --git a/alignak_app/qthreads/thread.py b/alignak_app/qthreads/thread.py index d4fcbb3..fe66009 100644 --- a/alignak_app/qthreads/thread.py +++ b/alignak_app/qthreads/thread.py @@ -62,6 +62,8 @@ def run(self): # pragma: no cover app_backend.query_daemons_data() elif 'livesynthesis' in self.thread_name: app_backend.query_livesynthesis_data() + elif 'realm' in self.thread_name: + app_backend.query_realms_data() elif self.thread_name == 'history': if self.data: app_backend.query_history_data(self.data['hostname'], self.data['host_id']) diff --git a/alignak_app/qthreads/threadmanager.py b/alignak_app/qthreads/threadmanager.py index 785b781..6dbfa0a 100644 --- a/alignak_app/qthreads/threadmanager.py +++ b/alignak_app/qthreads/threadmanager.py @@ -56,7 +56,7 @@ def get_threads_to_launch(self): threads_to_launch = [] # Add BackendQThread only if they are not already running - for cur_thread in ['livesynthesis', 'host', 'service', 'user', + for cur_thread in ['livesynthesis', 'host', 'service', 'user', 'realm', 'alignakdaemon', 'notifications', 'history']: if self.current_thread: if cur_thread != self.current_thread.thread_name: