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,16 +254,21 @@ class AhenkDeamon(BaseDaemon):
def run_command_from_fifo(self, num, stack): def run_command_from_fifo(self, num, stack):
json_data = json.loads(Commander().get_event()) scope = Scope().getInstance()
plugin_manager = scope.getPluginManager()
message_manager = scope.getMessageManager()
messenger = scope.getMessenger()
conf_manager = scope.getConfigurationManager()
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: if json_data is not None:
scope = Scope().getInstance()
plugin_manager = scope.getPluginManager()
message_manager = scope.getMessageManager()
messenger = scope.getMessenger()
conf_manager = scope.getConfigurationManager()
db_service = scope.getDbService()
execute_manager = scope.getExecutionManager()
self.logger.debug('[AhenkDeamon] Signal handled') self.logger.debug('[AhenkDeamon] Signal handled')
self.logger.debug('[AhenkDeamon] Signal is :{}'.format(str(json_data['event']))) self.logger.debug('[AhenkDeamon] Signal is :{}'.format(str(json_data['event'])))
@ -347,8 +352,8 @@ class AhenkDeamon(BaseDaemon):
plugin_manager.process_mode('safe', username) plugin_manager.process_mode('safe', username)
elif 'send' == str(json_data['event']): elif 'send' == str(json_data['event']):
self.logger.info('[AhenkDeamon] Sending message over ahenkd command. Response Message: {}'.format(str(json_data['message']))) self.logger.info('[AhenkDeamon] Sending message over ahenkd command. Response Message: {}'.format(json.dumps(json_data['message'])))
message = str(json.dumps(json_data['message'])) message = json.dumps(json_data['message'])
messenger.send_direct_message(message) messenger.send_direct_message(message)
elif 'load' == str(json_data['event']): elif 'load' == str(json_data['event']):

View file

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