From d3ee9ff7390ce83453268b3b4f7523a539d70bb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Volkan=20=C5=9Eahin?= Date: Sun, 3 Apr 2016 00:58:33 +0300 Subject: [PATCH] message formats were fixed --- opt/ahenk/base/messaging/Messaging.py | 31 ++++++++++++++++++++++++++- opt/ahenk/base/model/Policy.py | 13 +++++++++-- opt/ahenk/base/model/Response.py | 9 +++++++- opt/ahenk/base/plugin/Plugin.py | 2 +- 4 files changed, 50 insertions(+), 5 deletions(-) diff --git a/opt/ahenk/base/messaging/Messaging.py b/opt/ahenk/base/messaging/Messaging.py index 7b70677..4f7dfd7 100644 --- a/opt/ahenk/base/messaging/Messaging.py +++ b/opt/ahenk/base/messaging/Messaging.py @@ -33,6 +33,35 @@ class Messaging(object): self.logger.debug('[Messaging] Response message was created') return str(json_data) + def task_status_msg(self, response): + data = {} + data['type'] = response.get_type() + data['taskId'] = response.get_id() + data['responseCode'] = response.get_code() + data['responseMessage'] = response.get_message() + data['responseData'] = response.get_data() + data['contentType'] = response.get_content_type() + data['timestamp'] = response.get_timestamp() + + json_data = json.dumps(data) + self.logger.debug('[Messaging] Task status message was created') + return str(json_data) + + def policy_status_msg(self, response): + data = {} + data['type'] = response.get_type() + data['policyVersion'] = response.get_id() + data['commandExecutionId'] = response.get_id() + data['responseCode'] = response.get_code() + data['responseMessage'] = response.get_message() + data['responseData'] = response.get_data() + data['contentType'] = response.get_content_type() + data['timestamp'] = response.get_timestamp() + + json_data = json.dumps(data) + self.logger.debug('[Messaging] Policy status message was created') + return str(json_data) + def login_msg(self, username): data = {} @@ -60,7 +89,7 @@ class Messaging(object): machine_policy_number = self.db_service.select_one_result('policy', 'version', 'type = \'A\'') data['userPolicyVersion'] = user_policy_number - data['machinePolicyVersion'] = machine_policy_number + data['agentPolicyVersion'] = machine_policy_number data['username'] = str(username) data['timestamp'] = str(datetime.datetime.now().strftime("%d-%m-%Y %I:%M")) diff --git a/opt/ahenk/base/model/Policy.py b/opt/ahenk/base/model/Policy.py index 5091db5..d3dd247 100644 --- a/opt/ahenk/base/model/Policy.py +++ b/opt/ahenk/base/model/Policy.py @@ -15,12 +15,12 @@ class Policy(object): @property def ahenk_policy_version(self): - return self.policy['machinePolicyVersion'] + return self.policy['agentPolicyVersion'] @property def ahenk_profiles(self): profiles = [] - for p in self.policy['machinePolicyProfiles']: + for p in self.policy['agentPolicyProfiles']: profiles.append(Profile(p)) return profiles @@ -42,6 +42,15 @@ class Policy(object): except Exception as e: return None + @property + def ahenk_execution_id(self): + return self.policy['agentCommandExecutionId'] + + @property + def user_execution_id(self): + return self.policy['userCommandExecutionId'] + + def to_string(self): return str(self.policy) diff --git a/opt/ahenk/base/model/Response.py b/opt/ahenk/base/model/Response.py index 6b35c4b..ac16f87 100644 --- a/opt/ahenk/base/model/Response.py +++ b/opt/ahenk/base/model/Response.py @@ -8,13 +8,14 @@ import datetime class Response(object): """docstring for Plugin""" - def __init__(self, type, id, code=None, message=None, data=None, content_type=None): + def __init__(self, type, id, code=None, message=None, data=None, content_type=None, execution_id=None): self.type = type self.id = id self.code = code self.message = message self.data = data self.content_type = content_type + self.execution_id = execution_id self.timestamp = str(datetime.datetime.now().strftime("%d-%m-%Y %I:%M")) def get_type(self): @@ -56,3 +57,9 @@ class Response(object): def get_timestamp(self): return self.timestamp + def get_execution_id(self): + return str(self.execution_id) + + def set_execution_id(self, execution_id): + self.execution_id = execution_id + diff --git a/opt/ahenk/base/plugin/Plugin.py b/opt/ahenk/base/plugin/Plugin.py index 197f48a..c34b8ef 100644 --- a/opt/ahenk/base/plugin/Plugin.py +++ b/opt/ahenk/base/plugin/Plugin.py @@ -73,7 +73,7 @@ class Plugin(threading.Thread): policy_module.handle_policy(profile_data, self.context) #TODO Message Code keep - response = Response(type=MessageType.POLICY_STATUS, id=item_obj.id, code=MessageCode.POLICY_PROCESSED, message='__message__', data=self.context.get('data'), content_type=self.context.get('content_type')) + response = Response(type=MessageType.POLICY_STATUS, id=item_obj.id, code=MessageCode.POLICY_PROCESSED, message='__message__', data=self.context.get('data'), content_type=self.context.get('content_type'), execution_id='get_execution_id') #self.response_queue.put(self.messaging.response_msg(response)) #TODO DEBUG Scope.getInstance().getMessager().send_direct_message(self.messaging.response_msg(response))#TODO REMOVE