mirror of
https://github.com/Pardus-LiderAhenk/ahenk
synced 2024-11-13 01:02:16 +03:00
message formats were fixed
This commit is contained in:
parent
7a5271876c
commit
d3ee9ff739
4 changed files with 50 additions and 5 deletions
|
@ -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"))
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue