message formats were fixed

This commit is contained in:
Volkan Şahin 2016-04-03 00:58:33 +03:00
parent 7a5271876c
commit d3ee9ff739
4 changed files with 50 additions and 5 deletions

View file

@ -33,6 +33,35 @@ class Messaging(object):
self.logger.debug('[Messaging] Response message was created') self.logger.debug('[Messaging] Response message was created')
return str(json_data) 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): def login_msg(self, username):
data = {} data = {}
@ -60,7 +89,7 @@ class Messaging(object):
machine_policy_number = self.db_service.select_one_result('policy', 'version', 'type = \'A\'') machine_policy_number = self.db_service.select_one_result('policy', 'version', 'type = \'A\'')
data['userPolicyVersion'] = user_policy_number data['userPolicyVersion'] = user_policy_number
data['machinePolicyVersion'] = machine_policy_number data['agentPolicyVersion'] = machine_policy_number
data['username'] = str(username) data['username'] = str(username)
data['timestamp'] = str(datetime.datetime.now().strftime("%d-%m-%Y %I:%M")) data['timestamp'] = str(datetime.datetime.now().strftime("%d-%m-%Y %I:%M"))

View file

@ -15,12 +15,12 @@ class Policy(object):
@property @property
def ahenk_policy_version(self): def ahenk_policy_version(self):
return self.policy['machinePolicyVersion'] return self.policy['agentPolicyVersion']
@property @property
def ahenk_profiles(self): def ahenk_profiles(self):
profiles = [] profiles = []
for p in self.policy['machinePolicyProfiles']: for p in self.policy['agentPolicyProfiles']:
profiles.append(Profile(p)) profiles.append(Profile(p))
return profiles return profiles
@ -42,6 +42,15 @@ class Policy(object):
except Exception as e: except Exception as e:
return None 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): def to_string(self):
return str(self.policy) return str(self.policy)

View file

@ -8,13 +8,14 @@ import datetime
class Response(object): class Response(object):
"""docstring for Plugin""" """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.type = type
self.id = id self.id = id
self.code = code self.code = code
self.message = message self.message = message
self.data = data self.data = data
self.content_type = content_type self.content_type = content_type
self.execution_id = execution_id
self.timestamp = str(datetime.datetime.now().strftime("%d-%m-%Y %I:%M")) self.timestamp = str(datetime.datetime.now().strftime("%d-%m-%Y %I:%M"))
def get_type(self): def get_type(self):
@ -56,3 +57,9 @@ class Response(object):
def get_timestamp(self): def get_timestamp(self):
return self.timestamp 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

View file

@ -73,7 +73,7 @@ class Plugin(threading.Thread):
policy_module.handle_policy(profile_data, self.context) policy_module.handle_policy(profile_data, self.context)
#TODO Message Code keep #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 #self.response_queue.put(self.messaging.response_msg(response)) #TODO DEBUG
Scope.getInstance().getMessager().send_direct_message(self.messaging.response_msg(response))#TODO REMOVE Scope.getInstance().getMessager().send_direct_message(self.messaging.response_msg(response))#TODO REMOVE