bug fix about send message via ahenkd command

This commit is contained in:
Volkan Şahin 2016-07-27 16:03:32 +03:00
parent 57862558d5
commit e14a1a4523
2 changed files with 21 additions and 16 deletions

View file

@ -254,9 +254,6 @@ class AhenkDeamon(BaseDaemon):
def run_command_from_fifo(self, num, stack):
json_data = json.loads(Commander().get_event())
if json_data is not None:
scope = Scope().getInstance()
plugin_manager = scope.getPluginManager()
message_manager = scope.getMessageManager()
@ -265,6 +262,14 @@ class AhenkDeamon(BaseDaemon):
db_service = scope.getDbService()
execute_manager = scope.getExecutionManager()
try:
json_data = json.loads(Commander().get_event())
except Exception as e:
self.logger.error('[AhenkDeamon] A problem occurred while loading json. Check json format! Error Message: {0}'.format(str(e)))
return
if json_data is not None:
self.logger.debug('[AhenkDeamon] Signal handled')
self.logger.debug('[AhenkDeamon] Signal is :{}'.format(str(json_data['event'])))
@ -347,8 +352,8 @@ class AhenkDeamon(BaseDaemon):
plugin_manager.process_mode('safe', username)
elif 'send' == str(json_data['event']):
self.logger.info('[AhenkDeamon] Sending message over ahenkd command. Response Message: {}'.format(str(json_data['message'])))
message = str(json.dumps(json_data['message']))
self.logger.info('[AhenkDeamon] Sending message over ahenkd command. Response Message: {}'.format(json.dumps(json_data['message'])))
message = json.dumps(json_data['message'])
messenger.send_direct_message(message)
elif 'load' == str(json_data['event']):

View file

@ -4,6 +4,7 @@ import json
import os
import queue as Queue
import threading
import ast
from base.command.fifo import Fifo
from base.model.enum.ContentType import ContentType
@ -71,7 +72,7 @@ class Commander(object):
response['type'] = MessageType.TASK_STATUS.value
response['taskId'] = params[3]
if params[4] == '-m':
response['contentType'] = ContentType.TEXT_PLAIN.value
response['contentType'] = ContentType.APPLICATION_JSON.value
response['responseData'] = params[5]
elif params[4] == '-f':
if os.path.exists(str(params[5])):
@ -101,7 +102,7 @@ class Commander(object):
response['commandExecutionId'] = params[5]
if params[6] == '-m':
response['contentType'] = ContentType.TEXT_PLAIN.value
response['contentType'] = ContentType.APPLICATION_JSON.value
response['responseData'] = params[7]
elif params[6] == '-f':
if os.path.exists(str(params[7])):
@ -125,13 +126,12 @@ class Commander(object):
else:
print('Wrong or missing parameter. Usage: send -p <policy_version> -c <command_execution_id> -m|-f <message_content>|<file_path> -e|-s|-w')
return None
print('RESPONSE=' + str(response).replace("'", '"'))
data['message'] = json.loads(str(response).replace("'", '"'))
data['message'] = ast.literal_eval(str(response))
else:
print('Wrong or missing parameter. Usage : %s start|stop|restart|status|clean|send')
return None
else:
if params[1] == 'clean':