mirror of
https://github.com/Pardus-LiderAhenk/ahenk
synced 2024-11-25 11:12:15 +03:00
variable names fixed and all logs formatted
This commit is contained in:
parent
52efbbb100
commit
b002763145
16 changed files with 228 additions and 221 deletions
|
@ -13,9 +13,9 @@ class AhenkDbService(object):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
scope = Scope.getInstance()
|
scope = Scope.get_instance()
|
||||||
self.logger = scope.getLogger()
|
self.logger = scope.get_logger()
|
||||||
self.configurationManager = scope.getConfigurationManager()
|
self.configurationManager = scope.get_configuration_manager()
|
||||||
self.db_path = self.configurationManager.get('BASE', 'dbPath')
|
self.db_path = self.configurationManager.get('BASE', 'dbPath')
|
||||||
self.connection = None
|
self.connection = None
|
||||||
self.cursor = None
|
self.cursor = None
|
||||||
|
@ -50,7 +50,7 @@ class AhenkDbService(object):
|
||||||
self.connection = sqlite3.connect(self.db_path, check_same_thread=False)
|
self.connection = sqlite3.connect(self.db_path, check_same_thread=False)
|
||||||
self.cursor = self.connection.cursor()
|
self.cursor = self.connection.cursor()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.logger.error('[AhenkDbService] Database connection error ' + str(e))
|
self.logger.error('Database connection error: {0}'.format(str(e)))
|
||||||
|
|
||||||
def check_and_create_table(self, table_name, cols):
|
def check_and_create_table(self, table_name, cols):
|
||||||
|
|
||||||
|
@ -60,7 +60,7 @@ class AhenkDbService(object):
|
||||||
cols = ', '.join([str(x) for x in cols])
|
cols = ', '.join([str(x) for x in cols])
|
||||||
self.cursor.execute('create table if not exists ' + table_name + ' (' + cols + ')')
|
self.cursor.execute('create table if not exists ' + table_name + ' (' + cols + ')')
|
||||||
else:
|
else:
|
||||||
self.logger.warning('[AhenkDbService] Could not create table cursor is None! Table Name : ' + str(table_name))
|
self.logger.warning('Could not create table cursor is None! Table Name : {0}'.format(str(table_name)))
|
||||||
finally:
|
finally:
|
||||||
self.lock.release()
|
self.lock.release()
|
||||||
|
|
||||||
|
@ -91,10 +91,10 @@ class AhenkDbService(object):
|
||||||
self.connection.commit()
|
self.connection.commit()
|
||||||
return self.cursor.lastrowid
|
return self.cursor.lastrowid
|
||||||
else:
|
else:
|
||||||
self.logger.warning('[AhenkDbService] Could not update table cursor is None! Table Name : ' + str(table_name))
|
self.logger.warning('Could not update table cursor is None! Table Name : {0}'.format(str(table_name)))
|
||||||
return None
|
return None
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.logger.error('[AhenkDbService] Updating table error ! Table Name : ' + str(table_name) + ' ' + str(e))
|
self.logger.error('Updating table error ! Table Name : {0} Error Mesage: {1}'.format(str(table_name),str(e)))
|
||||||
finally:
|
finally:
|
||||||
self.lock.release()
|
self.lock.release()
|
||||||
|
|
||||||
|
@ -136,7 +136,7 @@ class AhenkDbService(object):
|
||||||
finally:
|
finally:
|
||||||
self.lock.release()
|
self.lock.release()
|
||||||
else:
|
else:
|
||||||
self.logger.warning('[AhenkDbService] Could not select table cursor is None! Table Name : ' + str(table_name))
|
self.logger.warning('Could not select table cursor is None! Table Name : {0}'.format(str(table_name)))
|
||||||
|
|
||||||
def select_one_result(self, table_name, col, criteria=''):
|
def select_one_result(self, table_name, col, criteria=''):
|
||||||
if self.cursor:
|
if self.cursor:
|
||||||
|
@ -157,11 +157,11 @@ class AhenkDbService(object):
|
||||||
finally:
|
finally:
|
||||||
self.lock.release()
|
self.lock.release()
|
||||||
else:
|
else:
|
||||||
self.logger.warning('[AhenkDbService] Could not select table cursor is None! Table Name : ' + str(table_name))
|
self.logger.warning('Could not select table cursor is None! Table Name : {0}'.format(str(table_name)))
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
try:
|
try:
|
||||||
self.cursor.close()
|
self.cursor.close()
|
||||||
self.connection.close()
|
self.connection.close()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.logger.error('[AhenkDbService] Closing database connection error:' + str(e))
|
self.logger.error('Closing database connection error: {0}'.format(str(e)))
|
||||||
|
|
|
@ -25,15 +25,15 @@ class ExecutionManager(object):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super(ExecutionManager, self).__init__()
|
super(ExecutionManager, self).__init__()
|
||||||
|
|
||||||
scope = Scope.getInstance()
|
scope = Scope.get_instance()
|
||||||
self.config_manager = scope.getConfigurationManager()
|
self.config_manager = scope.get_configuration_manager()
|
||||||
self.event_manager = scope.getEventManager()
|
self.event_manager = scope.get_event_manager()
|
||||||
self.task_manager = scope.getTaskManager()
|
self.task_manager = scope.get_task_manager()
|
||||||
self.messenger = scope.getMessenger()
|
self.messenger = scope.get_messenger()
|
||||||
self.logger = scope.getLogger()
|
self.logger = scope.get_logger()
|
||||||
self.db_service = scope.getDbService()
|
self.db_service = scope.get_db_service()
|
||||||
self.message_manager = scope.getMessageManager()
|
self.message_manager = scope.get_message_manager()
|
||||||
self.plugin_manager = scope.getPluginManager()
|
self.plugin_manager = scope.get_plugin_manager()
|
||||||
self.policy_executed = dict()
|
self.policy_executed = dict()
|
||||||
|
|
||||||
self.event_manager.register_event(MessageType.EXECUTE_SCRIPT.value, self.execute_script)
|
self.event_manager.register_event(MessageType.EXECUTE_SCRIPT.value, self.execute_script)
|
||||||
|
@ -65,11 +65,11 @@ class ExecutionManager(object):
|
||||||
[agreement_content, title, json_data['timestamp']])
|
[agreement_content, title, json_data['timestamp']])
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.logger.warning(
|
self.logger.warning(
|
||||||
'[ExecutionManager] A problem occurred while updating agreement. Error Message : {0}'.format(str(e)))
|
'A problem occurred while updating agreement. Error Message : {0}'.format(str(e)))
|
||||||
|
|
||||||
def install_plugin(self, arg):
|
def install_plugin(self, arg):
|
||||||
plugin = json.loads(arg)
|
plugin = json.loads(arg)
|
||||||
self.logger.debug('[ExecutionManager] Installing missing plugin')
|
self.logger.debug('Installing missing plugin')
|
||||||
try:
|
try:
|
||||||
plugin_name = plugin['pluginName']
|
plugin_name = plugin['pluginName']
|
||||||
plugin_version = plugin['pluginVersion']
|
plugin_version = plugin['pluginVersion']
|
||||||
|
@ -82,37 +82,37 @@ class ExecutionManager(object):
|
||||||
downloaded_file = System.Ahenk.received_dir_path() + file_name
|
downloaded_file = System.Ahenk.received_dir_path() + file_name
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.logger.error(
|
self.logger.error(
|
||||||
'[ExecutionManager] Plugin package could not fetch. Error Message: {0}.'.format(str(e)))
|
'Plugin package could not fetch. Error Message: {0}.'.format(str(e)))
|
||||||
self.logger.error('[ExecutionManager] Plugin Installation is cancelling')
|
self.logger.error('Plugin Installation is cancelling')
|
||||||
self.plugin_installation_failure(plugin_name, plugin_version)
|
self.plugin_installation_failure(plugin_name, plugin_version)
|
||||||
return
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
Util.install_with_gdebi(downloaded_file)
|
Util.install_with_gdebi(downloaded_file)
|
||||||
self.logger.debug('[ExecutionManager] Plugin installed.')
|
self.logger.debug('Plugin installed.')
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.logger.error('[ExecutionManager] Could not install plugin. Error Message: {0}'.format(str(e)))
|
self.logger.error('Could not install plugin. Error Message: {0}'.format(str(e)))
|
||||||
self.plugin_installation_failure(plugin_name, plugin_version)
|
self.plugin_installation_failure(plugin_name, plugin_version)
|
||||||
return
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
Util.delete_file(downloaded_file)
|
Util.delete_file(downloaded_file)
|
||||||
self.logger.debug('[ExecutionManager] Temp files were removed.')
|
self.logger.debug('Temp files were removed.')
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.logger.error('[ExecutionManager] Could not remove temp file. Error Message: {0}'.format(str(e)))
|
self.logger.error('Could not remove temp file. Error Message: {0}'.format(str(e)))
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.logger.error(
|
self.logger.error(
|
||||||
'[ExecutionManager] A problem occurred while installing new Ahenk plugin. Error Message:{0}'.format(
|
'A problem occurred while installing new Ahenk plugin. Error Message:{0}'.format(
|
||||||
str(e)))
|
str(e)))
|
||||||
|
|
||||||
def plugin_installation_failure(self, plugin_name, plugin_version):
|
def plugin_installation_failure(self, plugin_name, plugin_version):
|
||||||
|
|
||||||
self.logger.warning('[ExecutionManager] {0} plugin installation failure '.format(plugin_name))
|
self.logger.warning('{0} plugin installation failure '.format(plugin_name))
|
||||||
|
|
||||||
if plugin_name in self.plugin_manager.delayed_profiles.keys():
|
if plugin_name in self.plugin_manager.delayed_profiles.keys():
|
||||||
profile = self.plugin_manager.delayed_profiles[plugin_name]
|
profile = self.plugin_manager.delayed_profiles[plugin_name]
|
||||||
self.logger.warning('[ExecutionManager] An error message sending with related profile properties...')
|
self.logger.warning('An error message sending with related profile properties...')
|
||||||
related_policy = self.db_service.select('policy', ['version', 'execution_id'],
|
related_policy = self.db_service.select('policy', ['version', 'execution_id'],
|
||||||
'id={0}'.format(profile.get_id()))
|
'id={0}'.format(profile.get_id()))
|
||||||
data = dict()
|
data = dict()
|
||||||
|
@ -130,14 +130,14 @@ class ExecutionManager(object):
|
||||||
"ve eksik olan eklenti kurulurken hata oluştu",
|
"ve eksik olan eklenti kurulurken hata oluştu",
|
||||||
execution_id=related_policy[0][1], policy_version=related_policy[0][0],
|
execution_id=related_policy[0][1], policy_version=related_policy[0][0],
|
||||||
data=json.dumps(data), content_type=ContentType.APPLICATION_JSON.value)
|
data=json.dumps(data), content_type=ContentType.APPLICATION_JSON.value)
|
||||||
messenger = Scope.getInstance().getMessenger()
|
messenger = Scope.get_instance().get_messenger()
|
||||||
messenger.send_direct_message(self.message_manager.policy_status_msg(response))
|
messenger.send_direct_message(self.message_manager.policy_status_msg(response))
|
||||||
self.logger.warning(
|
self.logger.warning(
|
||||||
'[ExecutionManager] Error message was sent about {0} plugin installation failure while trying to run a profile')
|
'Error message was sent about {0} plugin installation failure while trying to run a profile')
|
||||||
|
|
||||||
if plugin_name in self.plugin_manager.delayed_tasks.keys():
|
if plugin_name in self.plugin_manager.delayed_tasks.keys():
|
||||||
task = self.plugin_manager.delayed_tasks[plugin_name]
|
task = self.plugin_manager.delayed_tasks[plugin_name]
|
||||||
self.logger.warning('[ExecutionManager] An error message sending with related task properties...')
|
self.logger.warning('An error message sending with related task properties...')
|
||||||
|
|
||||||
data = dict()
|
data = dict()
|
||||||
data['message'] = "Görev işletilirken eklenti bulunamadı "
|
data['message'] = "Görev işletilirken eklenti bulunamadı "
|
||||||
|
@ -152,10 +152,10 @@ class ExecutionManager(object):
|
||||||
message="Görev işletilirken eklenti bulunamadı "
|
message="Görev işletilirken eklenti bulunamadı "
|
||||||
"ve eksik olan eklenti kurulmaya çalışırken oluştu.",
|
"ve eksik olan eklenti kurulmaya çalışırken oluştu.",
|
||||||
data=json.dumps(data), content_type=ContentType.APPLICATION_JSON.value)
|
data=json.dumps(data), content_type=ContentType.APPLICATION_JSON.value)
|
||||||
messenger = Scope.getInstance().getMessenger()
|
messenger = Scope.get_instance().get_messenger()
|
||||||
messenger.send_direct_message(self.message_manager.task_status_msg(response))
|
messenger.send_direct_message(self.message_manager.task_status_msg(response))
|
||||||
self.logger.warning(
|
self.logger.warning(
|
||||||
'[ExecutionManager] Error message was sent about {0} plugin installation failure while trying to run a task')
|
'Error message was sent about {0} plugin installation failure while trying to run a task')
|
||||||
|
|
||||||
def is_policy_executed(self, username):
|
def is_policy_executed(self, username):
|
||||||
if username in self.policy_executed:
|
if username in self.policy_executed:
|
||||||
|
@ -167,11 +167,11 @@ class ExecutionManager(object):
|
||||||
self.policy_executed[username] = False
|
self.policy_executed[username] = False
|
||||||
|
|
||||||
def execute_default_policy(self, username):
|
def execute_default_policy(self, username):
|
||||||
self.logger.debug('[ExecutionManager] Executing active policies for {0} user...'.format(username))
|
self.logger.debug('Executing active policies for {0} user...'.format(username))
|
||||||
self.task_manager.addPolicy(self.get_active_policies(username))
|
self.task_manager.addPolicy(self.get_active_policies(username))
|
||||||
|
|
||||||
def execute_policy(self, arg):
|
def execute_policy(self, arg):
|
||||||
self.logger.debug('[ExecutionManager] Updating policies...')
|
self.logger.debug('Updating policies...')
|
||||||
policy = self.json_to_PolicyBean(json.loads(arg))
|
policy = self.json_to_PolicyBean(json.loads(arg))
|
||||||
self.policy_executed[policy.get_username()] = True
|
self.policy_executed[policy.get_username()] = True
|
||||||
machine_uid = self.db_service.select_one_result('registration', 'jid', 'registered=1')
|
machine_uid = self.db_service.select_one_result('registration', 'jid', 'registered=1')
|
||||||
|
@ -213,7 +213,7 @@ class ExecutionManager(object):
|
||||||
self.db_service.update('profile', profile_columns, profile_args)
|
self.db_service.update('profile', profile_columns, profile_args)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
self.logger.debug('[ExecutionManager] Already there is ahenk policy. Command Execution Id is updating')
|
self.logger.debug('Already there is ahenk policy. Command Execution Id is updating')
|
||||||
self.db_service.update('policy', ['execution_id'], [policy.get_agent_execution_id()], 'type = \'A\'')
|
self.db_service.update('policy', ['execution_id'], [policy.get_agent_execution_id()], 'type = \'A\'')
|
||||||
|
|
||||||
if policy.get_user_policy_version() != user_policy_version:
|
if policy.get_user_policy_version() != user_policy_version:
|
||||||
|
@ -249,7 +249,7 @@ class ExecutionManager(object):
|
||||||
self.db_service.update('profile', profile_columns, profile_args)
|
self.db_service.update('profile', profile_columns, profile_args)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
self.logger.debug('[ExecutionManager] Already there is user policy. . Command Execution Id is updating')
|
self.logger.debug('Already there is user policy. . Command Execution Id is updating')
|
||||||
self.db_service.update('policy', ['execution_id'], [policy.get_user_execution_id()], 'type = \'U\'')
|
self.db_service.update('policy', ['execution_id'], [policy.get_user_execution_id()], 'type = \'U\'')
|
||||||
|
|
||||||
policy = self.get_active_policies(policy.get_username())
|
policy = self.get_active_policies(policy.get_username())
|
||||||
|
@ -314,10 +314,10 @@ class ExecutionManager(object):
|
||||||
json_server_conf = json.dumps(json.loads(arg)['fileServerConf'])
|
json_server_conf = json.dumps(json.loads(arg)['fileServerConf'])
|
||||||
|
|
||||||
task = self.json_to_task_bean(json_task, json_server_conf)
|
task = self.json_to_task_bean(json_task, json_server_conf)
|
||||||
self.logger.debug('[ExecutionManager] Adding new task...Task is:{0}'.format(task.get_command_cls_id()))
|
self.logger.debug('Adding new task...Task is:{0}'.format(task.get_command_cls_id()))
|
||||||
|
|
||||||
self.task_manager.addTask(task)
|
self.task_manager.addTask(task)
|
||||||
self.logger.debug('[ExecutionManager] Task added')
|
self.logger.debug('Task added')
|
||||||
|
|
||||||
def json_to_task_bean(self, json_data, file_server_conf=None):
|
def json_to_task_bean(self, json_data, file_server_conf=None):
|
||||||
plu = json_data['plugin']
|
plu = json_data['plugin']
|
||||||
|
@ -333,24 +333,24 @@ class ExecutionManager(object):
|
||||||
|
|
||||||
def execute_script(self, arg):
|
def execute_script(self, arg):
|
||||||
try:
|
try:
|
||||||
self.logger.debug('[ExecutionManager] Executing script...')
|
self.logger.debug('Executing script...')
|
||||||
messenger = Scope().getInstance().getMessenger()
|
messenger = Scope().get_instance().get_messenger()
|
||||||
|
|
||||||
json_data = json.loads(arg)
|
json_data = json.loads(arg)
|
||||||
result_code, p_out, p_err = Util.execute(str(json_data['command']))
|
result_code, p_out, p_err = Util.execute(str(json_data['command']))
|
||||||
|
|
||||||
self.logger.debug('[ExecutionManager] Executed script')
|
self.logger.debug('Executed script')
|
||||||
|
|
||||||
data = dict()
|
data = dict()
|
||||||
data['type'] = 'SCRIPT_RESULT'
|
data['type'] = 'SCRIPT_RESULT'
|
||||||
data['timestamp'] = str(Util.timestamp())
|
data['timestamp'] = str(Util.timestamp())
|
||||||
|
|
||||||
if result_code == 0:
|
if result_code == 0:
|
||||||
self.logger.debug('[ExecutionManager] Command execution was finished successfully')
|
self.logger.debug('Command execution was finished successfully')
|
||||||
try:
|
try:
|
||||||
temp_name = str(Util.generate_uuid())
|
temp_name = str(Util.generate_uuid())
|
||||||
temp_full_path = System.Ahenk.received_dir_path() + temp_name
|
temp_full_path = System.Ahenk.received_dir_path() + temp_name
|
||||||
self.logger.debug('[ExecutionManager] Writing result to file')
|
self.logger.debug('Writing result to file')
|
||||||
Util.write_file(temp_full_path, str(p_out))
|
Util.write_file(temp_full_path, str(p_out))
|
||||||
md5 = Util.get_md5_file(temp_full_path)
|
md5 = Util.get_md5_file(temp_full_path)
|
||||||
Util.rename_file(temp_full_path, System.Ahenk.received_dir_path() + md5)
|
Util.rename_file(temp_full_path, System.Ahenk.received_dir_path() + md5)
|
||||||
|
@ -358,14 +358,14 @@ class ExecutionManager(object):
|
||||||
file_manager = FileTransferManager(json_data['fileServerConf']['protocol'],
|
file_manager = FileTransferManager(json_data['fileServerConf']['protocol'],
|
||||||
json_data['fileServerConf']['parameterMap'])
|
json_data['fileServerConf']['parameterMap'])
|
||||||
file_manager.transporter.connect()
|
file_manager.transporter.connect()
|
||||||
self.logger.debug('[ExecutionManager] File transfer connection was created')
|
self.logger.debug('File transfer connection was created')
|
||||||
success = file_manager.transporter.send_file(System.Ahenk.received_dir_path() + md5, md5)
|
success = file_manager.transporter.send_file(System.Ahenk.received_dir_path() + md5, md5)
|
||||||
self.logger.debug('[ExecutionManager] File was transferred')
|
self.logger.debug('File was transferred')
|
||||||
file_manager.transporter.disconnect()
|
file_manager.transporter.disconnect()
|
||||||
self.logger.debug('[ExecutionManager] File transfer connection was closed')
|
self.logger.debug('File transfer connection was closed')
|
||||||
|
|
||||||
if success is False:
|
if success is False:
|
||||||
self.logger.error('[ExecutionManager] A problem occurred while file transferring')
|
self.logger.error('A problem occurred while file transferring')
|
||||||
data['resultCode'] = '-1'
|
data['resultCode'] = '-1'
|
||||||
data[
|
data[
|
||||||
'errorMessage'] = 'Command executed successfully but a problem occurred while sending result file'
|
'errorMessage'] = 'Command executed successfully but a problem occurred while sending result file'
|
||||||
|
@ -375,19 +375,19 @@ class ExecutionManager(object):
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.logger.error(
|
self.logger.error(
|
||||||
'[ExecutionManager] A problem occurred while file transferring. Error Message :{0}'.format(
|
'A problem occurred while file transferring. Error Message :{0}'.format(
|
||||||
str(e)))
|
str(e)))
|
||||||
raise
|
raise
|
||||||
else:
|
else:
|
||||||
self.logger.error(
|
self.logger.error(
|
||||||
'[ExecutionManager] Command execution was failed. Error Message :{0}'.format(str(result_code)))
|
'Command execution was failed. Error Message :{0}'.format(str(result_code)))
|
||||||
data['resultCode'] = str(result_code)
|
data['resultCode'] = str(result_code)
|
||||||
data['errorMessage'] = str(p_err)
|
data['errorMessage'] = str(p_err)
|
||||||
|
|
||||||
messenger.send_direct_message(json.dumps(data))
|
messenger.send_direct_message(json.dumps(data))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.logger.error(
|
self.logger.error(
|
||||||
'[ExecutionManager] A problem occurred while running execute script action. Error Message :{0}'.format(
|
'A problem occurred while running execute script action. Error Message :{0}'.format(
|
||||||
str(e)))
|
str(e)))
|
||||||
|
|
||||||
def json_to_PolicyBean(self, json_data):
|
def json_to_PolicyBean(self, json_data):
|
||||||
|
|
|
@ -9,9 +9,9 @@ from base.file.http_file_transfer import Http
|
||||||
|
|
||||||
class FileTransferManager(object):
|
class FileTransferManager(object):
|
||||||
def __init__(self, protocol, parameter_map):
|
def __init__(self, protocol, parameter_map):
|
||||||
scope = Scope().getInstance()
|
scope = Scope().get_instance()
|
||||||
self.logger = scope.getLogger()
|
self.logger = scope.get_logger()
|
||||||
self.configuration_manager = scope.getConfigurationManager()
|
self.configuration_manager = scope.get_configuration_manager()
|
||||||
self.transporter = self.get_instance(protocol, parameter_map)
|
self.transporter = self.get_instance(protocol, parameter_map)
|
||||||
|
|
||||||
def get_instance(self, protocol, parameter_map):
|
def get_instance(self, protocol, parameter_map):
|
||||||
|
@ -27,6 +27,6 @@ class FileTransferManager(object):
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.logger.error(
|
self.logger.error(
|
||||||
'[FileTransferManager] A problem occurred while getting instance of related protocol. Error Message: {0}'.format(
|
'A problem occurred while getting instance of related protocol. Error Message: {0}'.format(
|
||||||
str(e)))
|
str(e)))
|
||||||
return None
|
return None
|
||||||
|
|
|
@ -11,14 +11,14 @@ from base.scope import Scope
|
||||||
class Http(object):
|
class Http(object):
|
||||||
def __init__(self, parameter_map):
|
def __init__(self, parameter_map):
|
||||||
|
|
||||||
scope = Scope().getInstance()
|
scope = Scope().get_instance()
|
||||||
self.logger = scope.getLogger()
|
self.logger = scope.get_logger()
|
||||||
self.configuration_manager = scope.getConfigurationManager()
|
self.configuration_manager = scope.get_configuration_manager()
|
||||||
try:
|
try:
|
||||||
self.url = parameter_map['url']
|
self.url = parameter_map['url']
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.logger.error(
|
self.logger.error(
|
||||||
'[Http] A problem occurred while parsing parameter map. Error Message: {0}'.format(str(e)))
|
'A problem occurred while parsing parameter map. Error Message: {0}'.format(str(e)))
|
||||||
|
|
||||||
def send_file(self, local_path, md5):
|
def send_file(self, local_path, md5):
|
||||||
pass
|
pass
|
||||||
|
@ -33,10 +33,10 @@ class Http(object):
|
||||||
urllib.request.urlretrieve(self.url, local_full_path)
|
urllib.request.urlretrieve(self.url, local_full_path)
|
||||||
file_md5 = str(Util.get_md5_file(local_full_path))
|
file_md5 = str(Util.get_md5_file(local_full_path))
|
||||||
Util.rename_file(local_full_path, System.Ahenk.received_dir_path() + file_md5)
|
Util.rename_file(local_full_path, System.Ahenk.received_dir_path() + file_md5)
|
||||||
self.logger.debug('[FileTransfer] File was downloaded to {0} from {1}'.format(local_full_path, self.url))
|
self.logger.debug('File was downloaded to {0} from {1}'.format(local_full_path, self.url))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.logger.error(
|
self.logger.error(
|
||||||
'[FileTransfer] A problem occurred while downloading file. Exception message: {0}'.format(str(e)))
|
'A problem occurred while downloading file. Exception message: {0}'.format(str(e)))
|
||||||
raise
|
raise
|
||||||
return file_md5
|
return file_md5
|
||||||
|
|
||||||
|
|
|
@ -12,9 +12,9 @@ import logging
|
||||||
class Ssh(object):
|
class Ssh(object):
|
||||||
def __init__(self, parameter_map):
|
def __init__(self, parameter_map):
|
||||||
|
|
||||||
scope = Scope().getInstance()
|
scope = Scope().get_instance()
|
||||||
self.logger = scope.getLogger()
|
self.logger = scope.get_logger()
|
||||||
self.configuration_manager = scope.getConfigurationManager()
|
self.configuration_manager = scope.get_configuration_manager()
|
||||||
logging.getLogger("paramiko").setLevel(logging.INFO)
|
logging.getLogger("paramiko").setLevel(logging.INFO)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -30,14 +30,14 @@ class Ssh(object):
|
||||||
self.p_key = parameter_map['pkey']
|
self.p_key = parameter_map['pkey']
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.logger.error(
|
self.logger.error(
|
||||||
'[Ssh] A problem occurred while parsing ssh connection parameters. Error Message: {0}'.format(str(e)))
|
'A problem occurred while parsing ssh connection parameters. Error Message: {0}'.format(str(e)))
|
||||||
|
|
||||||
self.connection = None
|
self.connection = None
|
||||||
self.logger.debug('[Ssh] Parameters set up')
|
self.logger.debug('Parameters set up')
|
||||||
|
|
||||||
def send_file(self, local_path, md5):
|
def send_file(self, local_path, md5):
|
||||||
|
|
||||||
self.logger.debug('[Ssh] {0} is sending to {1}'.format(local_path, self.target_path + md5))
|
self.logger.debug(' {0} is sending to {1}'.format(local_path, self.target_path + md5))
|
||||||
try:
|
try:
|
||||||
sftp = paramiko.SFTPClient.from_transport(self.connection)
|
sftp = paramiko.SFTPClient.from_transport(self.connection)
|
||||||
try:
|
try:
|
||||||
|
@ -47,14 +47,14 @@ class Ssh(object):
|
||||||
sftp.chdir(self.target_path)
|
sftp.chdir(self.target_path)
|
||||||
|
|
||||||
sftp.put(local_path, self.target_path + md5)
|
sftp.put(local_path, self.target_path + md5)
|
||||||
self.logger.debug('[Ssh] File was sent to {0} from {1}'.format(local_path, self.target_path))
|
self.logger.debug('File was sent to {0} from {1}'.format(local_path, self.target_path))
|
||||||
return True
|
return True
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.logger.error('[Ssh] A problem occurred while sending file. Exception message: {0}'.format(str(e)))
|
self.logger.error('A problem occurred while sending file. Exception message: {0}'.format(str(e)))
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def get_file(self):
|
def get_file(self, local_path=None):
|
||||||
self.logger.debug('[Ssh] Getting file ...')
|
self.logger.debug('Getting file ...')
|
||||||
file_md5 = None
|
file_md5 = None
|
||||||
try:
|
try:
|
||||||
tmp_file_name = str(Util.generate_uuid())
|
tmp_file_name = str(Util.generate_uuid())
|
||||||
|
@ -62,28 +62,32 @@ class Ssh(object):
|
||||||
sftp = paramiko.SFTPClient.from_transport(self.connection)
|
sftp = paramiko.SFTPClient.from_transport(self.connection)
|
||||||
sftp.get(self.target_path, local_full_path)
|
sftp.get(self.target_path, local_full_path)
|
||||||
file_md5 = str(Util.get_md5_file(local_full_path))
|
file_md5 = str(Util.get_md5_file(local_full_path))
|
||||||
Util.rename_file(local_full_path, System.Ahenk.received_dir_path() + file_md5)
|
if local_path is None:
|
||||||
self.logger.debug('[Ssh] File was downloaded to {0} from {1}'.format(local_full_path, self.target_path))
|
receive_path = System.Ahenk.received_dir_path()
|
||||||
|
else:
|
||||||
|
receive_path = local_path
|
||||||
|
Util.rename_file(local_full_path, receive_path + file_md5)
|
||||||
|
self.logger.debug('File was downloaded to {0} from {1}'.format(local_full_path, self.target_path))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.logger.error('[Ssh] A problem occurred while downloading file. Exception message: {0}'.format(str(e)))
|
self.logger.warning('A problem occurred while downloading file. Exception message: {0}'.format(str(e)))
|
||||||
raise
|
raise
|
||||||
return file_md5
|
return file_md5
|
||||||
|
|
||||||
def connect(self):
|
def connect(self):
|
||||||
self.logger.debug('[FileTransfer] Connecting to {0} via {1}'.format(self.target_hostname, self.target_port))
|
self.logger.debug('Connecting to {0} via {1}'.format(self.target_hostname, self.target_port))
|
||||||
try:
|
try:
|
||||||
connection = paramiko.Transport(self.target_hostname, int(self.target_port))
|
connection = paramiko.Transport(self.target_hostname, int(self.target_port))
|
||||||
connection.connect(username=self.target_username, password=self.target_password, pkey=self.p_key)
|
connection.connect(username=self.target_username, password=self.target_password, pkey=self.p_key)
|
||||||
self.connection = connection
|
self.connection = connection
|
||||||
self.logger.debug('[FileTransfer] Connected.')
|
self.logger.debug('Connected.')
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.logger.error(
|
self.logger.error(
|
||||||
'[FileTransfer] A problem occurred while connecting to {0} . Exception message: {1}'.format(
|
'A problem occurred while connecting to {0} . Exception message: {1}'.format(
|
||||||
self.target_hostname, str(e)))
|
self.target_hostname, str(e)))
|
||||||
|
|
||||||
def disconnect(self):
|
def disconnect(self):
|
||||||
self.connection.close()
|
self.connection.close()
|
||||||
self.logger.debug('[FileTransfer] Connection is closed.')
|
self.logger.debug('Connection is closed.')
|
||||||
# TODO
|
# TODO
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
|
@ -14,9 +14,9 @@ class MessageResponseQueue(threading.Thread):
|
||||||
|
|
||||||
def __init__(self, outQueue):
|
def __init__(self, outQueue):
|
||||||
super(MessageResponseQueue, self).__init__()
|
super(MessageResponseQueue, self).__init__()
|
||||||
scope = Scope.getInstance()
|
scope = Scope.get_instance()
|
||||||
self.logger = scope.getLogger()
|
self.logger = scope.get_logger()
|
||||||
self.messageManager = scope.getMessenger()
|
self.messageManager = scope.get_messenger()
|
||||||
self.outQueue = outQueue
|
self.outQueue = outQueue
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
|
@ -25,7 +25,7 @@ class MessageResponseQueue(threading.Thread):
|
||||||
# This item will send response to lider.
|
# This item will send response to lider.
|
||||||
# item must be response message. Response message may be generic message type
|
# item must be response message. Response message may be generic message type
|
||||||
responseMessage = self.outQueue.get(block=True)
|
responseMessage = self.outQueue.get(block=True)
|
||||||
self.logger.debug('[MessageResponseQueue] Sending response message to lider. Response Message ' + str(responseMessage))
|
self.logger.debug('Sending response message to lider. Response Message ' + str(responseMessage))
|
||||||
# Call message manager for response
|
# Call message manager for response
|
||||||
self.messageManager.send_direct_message(responseMessage)
|
self.messageManager.send_direct_message(responseMessage)
|
||||||
# self.outQueue.task_done()
|
# self.outQueue.task_done()
|
||||||
|
|
|
@ -1,22 +1,21 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# Author: Volkan Şahin <volkansah.in> <bm.volkansahin@gmail.com>
|
# Author: Volkan Şahin <volkansah.in> <bm.volkansahin@gmail.com>
|
||||||
import datetime
|
|
||||||
import json
|
import json
|
||||||
|
|
||||||
from base.system.system import System
|
|
||||||
from base.scope import Scope
|
from base.scope import Scope
|
||||||
|
from base.system.system import System
|
||||||
from base.util.util import Util
|
from base.util.util import Util
|
||||||
|
|
||||||
|
|
||||||
# TODO Message Factory
|
# TODO Message Factory
|
||||||
class Messaging(object):
|
class Messaging(object):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
scope = Scope().getInstance()
|
scope = Scope().get_instance()
|
||||||
self.logger = scope.getLogger()
|
self.logger = scope.get_logger()
|
||||||
self.conf_manager = scope.getConfigurationManager()
|
self.conf_manager = scope.get_configuration_manager()
|
||||||
self.db_service = scope.getDbService()
|
self.db_service = scope.get_db_service()
|
||||||
self.event_manger = scope.getEventManager()
|
self.event_manger = scope.get_event_manager()
|
||||||
|
|
||||||
def missing_plugin_message(self, plugin):
|
def missing_plugin_message(self, plugin):
|
||||||
data = dict()
|
data = dict()
|
||||||
|
@ -25,7 +24,7 @@ class Messaging(object):
|
||||||
data['pluginVersion'] = plugin.get_version()
|
data['pluginVersion'] = plugin.get_version()
|
||||||
|
|
||||||
json_data = json.dumps(data)
|
json_data = json.dumps(data)
|
||||||
self.logger.debug('[Messaging]Missing plugin message was created')
|
self.logger.debug('Missing plugin message was created')
|
||||||
return str(json_data)
|
return str(json_data)
|
||||||
|
|
||||||
def task_status_msg(self, response):
|
def task_status_msg(self, response):
|
||||||
|
@ -42,7 +41,7 @@ class Messaging(object):
|
||||||
data['timestamp'] = response.get_timestamp()
|
data['timestamp'] = response.get_timestamp()
|
||||||
|
|
||||||
json_data = json.dumps(data)
|
json_data = json.dumps(data)
|
||||||
self.logger.debug('[Messaging] Task status message was created')
|
self.logger.debug('Task status message was created')
|
||||||
return str(json_data)
|
return str(json_data)
|
||||||
|
|
||||||
def policy_status_msg(self, response):
|
def policy_status_msg(self, response):
|
||||||
|
@ -62,7 +61,7 @@ class Messaging(object):
|
||||||
data['timestamp'] = response.get_timestamp()
|
data['timestamp'] = response.get_timestamp()
|
||||||
|
|
||||||
json_data = json.dumps(data)
|
json_data = json.dumps(data)
|
||||||
self.logger.debug('[Messaging] Policy status message was created')
|
self.logger.debug('Policy status message was created')
|
||||||
return str(json_data)
|
return str(json_data)
|
||||||
|
|
||||||
def login_msg(self, username):
|
def login_msg(self, username):
|
||||||
|
@ -72,7 +71,7 @@ class Messaging(object):
|
||||||
data['ipAddresses'] = str(System.Hardware.Network.ip_addresses()).replace('[', '').replace(']', '')
|
data['ipAddresses'] = str(System.Hardware.Network.ip_addresses()).replace('[', '').replace(']', '')
|
||||||
data['timestamp'] = Util.timestamp()
|
data['timestamp'] = Util.timestamp()
|
||||||
json_data = json.dumps(data)
|
json_data = json.dumps(data)
|
||||||
self.logger.debug('[Messaging] Login message was created')
|
self.logger.debug('Login message was created')
|
||||||
return json_data
|
return json_data
|
||||||
|
|
||||||
def logout_msg(self, username):
|
def logout_msg(self, username):
|
||||||
|
@ -81,14 +80,15 @@ class Messaging(object):
|
||||||
data['username'] = str(username)
|
data['username'] = str(username)
|
||||||
data['timestamp'] = Util.timestamp()
|
data['timestamp'] = Util.timestamp()
|
||||||
json_data = json.dumps(data)
|
json_data = json.dumps(data)
|
||||||
self.logger.debug('[Messaging] Logout message was created')
|
self.logger.debug('Logout message was created')
|
||||||
return json_data
|
return json_data
|
||||||
|
|
||||||
def policy_request_msg(self, username):
|
def policy_request_msg(self, username):
|
||||||
data = dict()
|
data = dict()
|
||||||
data['type'] = 'GET_POLICIES'
|
data['type'] = 'GET_POLICIES'
|
||||||
|
|
||||||
user_policy_number = self.db_service.select_one_result('policy', 'version', 'type = \'U\' and name = \'' + username + '\'')
|
user_policy_number = self.db_service.select_one_result('policy', 'version',
|
||||||
|
'type = \'U\' and name = \'' + username + '\'')
|
||||||
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
|
||||||
|
@ -97,7 +97,7 @@ class Messaging(object):
|
||||||
data['username'] = str(username)
|
data['username'] = str(username)
|
||||||
data['timestamp'] = Util.timestamp()
|
data['timestamp'] = Util.timestamp()
|
||||||
json_data = json.dumps(data)
|
json_data = json.dumps(data)
|
||||||
self.logger.debug('[Messaging] Get Policies message was created')
|
self.logger.debug('Get Policies message was created')
|
||||||
return json_data
|
return json_data
|
||||||
|
|
||||||
def registration_msg(self):
|
def registration_msg(self):
|
||||||
|
@ -115,7 +115,7 @@ class Messaging(object):
|
||||||
|
|
||||||
data['timestamp'] = self.db_service.select_one_result('registration', 'timestamp', ' 1=1')
|
data['timestamp'] = self.db_service.select_one_result('registration', 'timestamp', ' 1=1')
|
||||||
json_data = json.dumps(data)
|
json_data = json.dumps(data)
|
||||||
self.logger.debug('[Messaging] Registration message was created')
|
self.logger.debug('Registration message was created')
|
||||||
return json_data
|
return json_data
|
||||||
|
|
||||||
def ldap_registration_msg(self):
|
def ldap_registration_msg(self):
|
||||||
|
@ -128,7 +128,7 @@ class Messaging(object):
|
||||||
data['hostname'] = str(self.conf_manager.get('REGISTRATION', 'hostname'))
|
data['hostname'] = str(self.conf_manager.get('REGISTRATION', 'hostname'))
|
||||||
data['timestamp'] = Util.timestamp()
|
data['timestamp'] = Util.timestamp()
|
||||||
json_data = json.dumps(data)
|
json_data = json.dumps(data)
|
||||||
self.logger.debug('[Messaging] LDAP Registration message was created')
|
self.logger.debug('LDAP Registration message was created')
|
||||||
return json_data
|
return json_data
|
||||||
|
|
||||||
def unregister_msg(self):
|
def unregister_msg(self):
|
||||||
|
@ -142,7 +142,7 @@ class Messaging(object):
|
||||||
# data['username'] = str(pwd.getpwuid( os.getuid() )[ 0 ])
|
# data['username'] = str(pwd.getpwuid( os.getuid() )[ 0 ])
|
||||||
data['timestamp'] = Util.timestamp()
|
data['timestamp'] = Util.timestamp()
|
||||||
json_data = json.dumps(data)
|
json_data = json.dumps(data)
|
||||||
self.logger.debug('[Messaging] Unregister message was created')
|
self.logger.debug('Unregister message was created')
|
||||||
return json_data
|
return json_data
|
||||||
|
|
||||||
def agreement_request_msg(self):
|
def agreement_request_msg(self):
|
||||||
|
@ -159,7 +159,7 @@ class Messaging(object):
|
||||||
|
|
||||||
data['timestamp'] = Util.timestamp()
|
data['timestamp'] = Util.timestamp()
|
||||||
json_data = json.dumps(data)
|
json_data = json.dumps(data)
|
||||||
self.logger.debug('[Messaging] Agreement request message was created')
|
self.logger.debug('Agreement request message was created')
|
||||||
return json_data
|
return json_data
|
||||||
|
|
||||||
def agreement_answer_msg(self, username, answer):
|
def agreement_answer_msg(self, username, answer):
|
||||||
|
@ -168,12 +168,13 @@ class Messaging(object):
|
||||||
data['username'] = username
|
data['username'] = username
|
||||||
data['accepted'] = answer
|
data['accepted'] = answer
|
||||||
data['timestamp'] = Util.timestamp()
|
data['timestamp'] = Util.timestamp()
|
||||||
contract_content = self.db_service.select_one_result('contract', 'content', 'id =(select MAX(id) from contract)')
|
contract_content = self.db_service.select_one_result('contract', 'content',
|
||||||
|
'id =(select MAX(id) from contract)')
|
||||||
if contract_content is not None and contract_content != '':
|
if contract_content is not None and contract_content != '':
|
||||||
data['md5'] = Util.get_md5_text(contract_content)
|
data['md5'] = Util.get_md5_text(contract_content)
|
||||||
else:
|
else:
|
||||||
data['md5'] = ''
|
data['md5'] = ''
|
||||||
|
|
||||||
json_data = json.dumps(data)
|
json_data = json.dumps(data)
|
||||||
self.logger.debug('[Messaging] Agreement answer message was created')
|
self.logger.debug('Agreement answer message was created')
|
||||||
return json_data
|
return json_data
|
||||||
|
|
|
@ -15,10 +15,10 @@ class AbstractPlugin(Util, System):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super(AbstractPlugin, self).__init__()
|
super(AbstractPlugin, self).__init__()
|
||||||
self.scope = Scope.getInstance()
|
self.scope = Scope.get_instance()
|
||||||
|
|
||||||
def handle_task(profile_data, context):
|
def handle_task(profile_data, context):
|
||||||
Scope.getInstance().getLogger().error('[AbstractPlugin] Handle function not found')
|
Scope.get_instance().get_logger().error('Handle function not found')
|
||||||
|
|
||||||
def get_message_code(self):
|
def get_message_code(self):
|
||||||
return MessageCode
|
return MessageCode
|
||||||
|
@ -28,19 +28,19 @@ class AbstractPlugin(Util, System):
|
||||||
|
|
||||||
def get_logger(self):
|
def get_logger(self):
|
||||||
try:
|
try:
|
||||||
return Scope.getInstance().getLogger()
|
return Scope.get_instance().get_logger()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.scope.getLogger().error(
|
self.scope.get_logger().error(
|
||||||
'[AbstractPlugin] A problem occurred while getting logger. Error Message: {0}'.format(str(e)))
|
'A problem occurred while getting logger. Error Message: {0}'.format(str(e)))
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def configuration_manager(self):
|
def configuration_manager(self):
|
||||||
try:
|
try:
|
||||||
return self.scope.getConfigurationManager()
|
return self.scope.get_configuration_manager()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.logger().error(
|
self.logger().error(
|
||||||
'[AbstractPlugin] A problem occurred while getting configuration manager. Error Message: {0}'.format(
|
'A problem occurred while getting configuration manager. Error Message: {0}'.format(
|
||||||
str(e)))
|
str(e)))
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ import signal
|
||||||
|
|
||||||
from watchdog.events import FileSystemEventHandler
|
from watchdog.events import FileSystemEventHandler
|
||||||
|
|
||||||
from base.command.commander import Commander
|
from base.command.command_manager import Commander
|
||||||
from base.system.system import System
|
from base.system.system import System
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,7 @@ from base.model.modes.login_mode import LoginMode
|
||||||
from base.model.modes.logout_mode import LogoutMode
|
from base.model.modes.logout_mode import LogoutMode
|
||||||
from base.model.modes.safe_mode import SafeMode
|
from base.model.modes.safe_mode import SafeMode
|
||||||
from base.model.modes.shutdown_mode import ShutdownMode
|
from base.model.modes.shutdown_mode import ShutdownMode
|
||||||
from base.plugin.Plugin import Plugin
|
from base.plugin.plugin import Plugin
|
||||||
from base.plugin.plugin_queue import PluginQueue
|
from base.plugin.plugin_queue import PluginQueue
|
||||||
from base.plugin.plugin_install_listener import PluginInstallListener
|
from base.plugin.plugin_install_listener import PluginInstallListener
|
||||||
from base.system.system import System
|
from base.system.system import System
|
||||||
|
@ -24,11 +24,11 @@ class PluginManager(object):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super(PluginManager, self).__init__()
|
super(PluginManager, self).__init__()
|
||||||
self.scope = Scope.getInstance()
|
self.scope = Scope.get_instance()
|
||||||
self.configManager = self.scope.getConfigurationManager()
|
self.configManager = self.scope.get_configuration_manager()
|
||||||
self.db_service = self.scope.getDbService()
|
self.db_service = self.scope.get_db_service()
|
||||||
self.message_manager = self.scope.getMessageManager()
|
self.message_manager = self.scope.get_message_manager()
|
||||||
self.logger = self.scope.getLogger()
|
self.logger = self.scope.get_logger()
|
||||||
|
|
||||||
self.plugins = []
|
self.plugins = []
|
||||||
self.pluginQueueDict = dict()
|
self.pluginQueueDict = dict()
|
||||||
|
@ -40,22 +40,22 @@ class PluginManager(object):
|
||||||
|
|
||||||
# TODO version?
|
# TODO version?
|
||||||
def load_plugins(self):
|
def load_plugins(self):
|
||||||
self.logger.info('[PluginManager] Loading plugins...')
|
self.logger.info('Loading plugins...')
|
||||||
self.plugins = []
|
self.plugins = []
|
||||||
self.logger.debug('[PluginManager] Lookup for possible plugins...')
|
self.logger.debug('Lookup for possible plugins...')
|
||||||
try:
|
try:
|
||||||
possible_plugins = os.listdir(self.configManager.get("PLUGIN", "pluginFolderPath"))
|
possible_plugins = os.listdir(self.configManager.get("PLUGIN", "pluginFolderPath"))
|
||||||
self.logger.debug('[PluginManager] Possible plugins: {0} '.format(str(possible_plugins)))
|
self.logger.debug('Possible plugins: {0} '.format(str(possible_plugins)))
|
||||||
for plugin_name in possible_plugins:
|
for plugin_name in possible_plugins:
|
||||||
try:
|
try:
|
||||||
self.load_single_plugin(plugin_name)
|
self.load_single_plugin(plugin_name)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.logger.error(
|
self.logger.error(
|
||||||
'[PluginManager] Exception occurred while loading plugin ! Plugin name : {0}.'
|
'Exception occurred while loading plugin ! Plugin name : {0}.'
|
||||||
' Error Message: {1}'.format(str(plugin_name), str(e)))
|
' Error Message: {1}'.format(str(plugin_name), str(e)))
|
||||||
self.logger.info('[PluginManager] Loaded plugins successfully.')
|
self.logger.info('Loaded plugins successfully.')
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.logger.warning('[PluginManager] Plugin folder path not found. Error Message: {0}'.format(str(e)))
|
self.logger.warning('Plugin folder path not found. Error Message: {0}'.format(str(e)))
|
||||||
|
|
||||||
def load_single_plugin(self, plugin_name):
|
def load_single_plugin(self, plugin_name):
|
||||||
# TODO check already loaded plugin
|
# TODO check already loaded plugin
|
||||||
|
@ -63,11 +63,11 @@ class PluginManager(object):
|
||||||
if not os.path.isdir(location) or not self.configManager.get("PLUGIN", "mainModuleName") + ".py" in os.listdir(
|
if not os.path.isdir(location) or not self.configManager.get("PLUGIN", "mainModuleName") + ".py" in os.listdir(
|
||||||
location):
|
location):
|
||||||
self.logger.debug(
|
self.logger.debug(
|
||||||
'[PluginManager] It is not a plugin location ! There is no main module - {0}'.format(str(location)))
|
'It is not a plugin location ! There is no main module - {0}'.format(str(location)))
|
||||||
else:
|
else:
|
||||||
if self.is_plugin_loaded(plugin_name):
|
if self.is_plugin_loaded(plugin_name):
|
||||||
self.logger.debug(
|
self.logger.debug(
|
||||||
'[PluginManager] {0} plugin was already loaded. Reloading {0} plugin'.format(plugin_name))
|
'{0} plugin was already loaded. Reloading {0} plugin'.format(plugin_name))
|
||||||
# self.reload_single_plugin(plugin_name)
|
# self.reload_single_plugin(plugin_name)
|
||||||
else:
|
else:
|
||||||
self.pluginQueueDict[plugin_name] = PluginQueue()
|
self.pluginQueueDict[plugin_name] = PluginQueue()
|
||||||
|
@ -75,7 +75,7 @@ class PluginManager(object):
|
||||||
plugin.setDaemon(True)
|
plugin.setDaemon(True)
|
||||||
plugin.start()
|
plugin.start()
|
||||||
self.plugins.append(plugin)
|
self.plugins.append(plugin)
|
||||||
self.logger.debug('[PluginManager] New plugin was loaded. Plugin Name: {0}'.format(plugin_name))
|
self.logger.debug('New plugin was loaded. Plugin Name: {0}'.format(plugin_name))
|
||||||
|
|
||||||
# active init mode
|
# active init mode
|
||||||
mode = InitMode()
|
mode = InitMode()
|
||||||
|
@ -84,65 +84,65 @@ class PluginManager(object):
|
||||||
if plugin_name in self.delayed_profiles:
|
if plugin_name in self.delayed_profiles:
|
||||||
self.pluginQueueDict[plugin_name].put(self.delayed_profiles[plugin_name], 1)
|
self.pluginQueueDict[plugin_name].put(self.delayed_profiles[plugin_name], 1)
|
||||||
del self.delayed_profiles[plugin_name]
|
del self.delayed_profiles[plugin_name]
|
||||||
self.logger.debug('[PluginManager] Delayed profile was found for this plugin. It will be run.')
|
self.logger.debug('Delayed profile was found for this plugin. It will be run.')
|
||||||
if plugin_name in self.delayed_tasks:
|
if plugin_name in self.delayed_tasks:
|
||||||
self.pluginQueueDict[plugin_name].put(self.delayed_tasks[plugin_name], 1)
|
self.pluginQueueDict[plugin_name].put(self.delayed_tasks[plugin_name], 1)
|
||||||
del self.delayed_tasks[plugin_name]
|
del self.delayed_tasks[plugin_name]
|
||||||
self.logger.debug('[PluginManager] Delayed task was found for this plugin. It will be run.')
|
self.logger.debug('Delayed task was found for this plugin. It will be run.')
|
||||||
|
|
||||||
def reload_plugins(self):
|
def reload_plugins(self):
|
||||||
try:
|
try:
|
||||||
self.logger.info('[PluginManager] Reloading plugins...')
|
self.logger.info('Reloading plugins...')
|
||||||
for p_queue in self.pluginQueueDict:
|
for p_queue in self.pluginQueueDict:
|
||||||
self.pluginQueueDict[p_queue].put(ShutdownMode(), 1)
|
self.pluginQueueDict[p_queue].put(ShutdownMode(), 1)
|
||||||
self.plugins = []
|
self.plugins = []
|
||||||
self.load_plugins()
|
self.load_plugins()
|
||||||
self.logger.info('[PluginManager] Plugin reloaded successfully.')
|
self.logger.info('Plugin reloaded successfully.')
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.logger.error('[PluginManager] Exception occurred when reloading plugins ' + str(e))
|
self.logger.error('Exception occurred when reloading plugins ' + str(e))
|
||||||
|
|
||||||
def reload_single_plugin(self, plugin_name):
|
def reload_single_plugin(self, plugin_name):
|
||||||
try:
|
try:
|
||||||
self.logger.info('[PluginManager] {0} plugin is reloading'.format(plugin_name))
|
self.logger.info('{0} plugin is reloading'.format(plugin_name))
|
||||||
self.logger.debug('[PluginManager] {0} plugin is killing (in reloading action)'.format(plugin_name))
|
self.logger.debug('{0} plugin is killing (in reloading action)'.format(plugin_name))
|
||||||
self.remove_single_plugin(plugin_name)
|
self.remove_single_plugin(plugin_name)
|
||||||
self.logger.debug('[PluginManager] {0} plugin is loading (in reloading action)'.format(plugin_name))
|
self.logger.debug('{0} plugin is loading (in reloading action)'.format(plugin_name))
|
||||||
self.load_single_plugin(plugin_name)
|
self.load_single_plugin(plugin_name)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.logger.error(
|
self.logger.error(
|
||||||
'[PluginManager] A problem occurred while reloading {0} plugin. Error Message: {1}'.format(plugin_name,
|
'A problem occurred while reloading {0} plugin. Error Message: {1}'.format(plugin_name,
|
||||||
str(e)))
|
str(e)))
|
||||||
|
|
||||||
def remove_plugins(self):
|
def remove_plugins(self):
|
||||||
try:
|
try:
|
||||||
self.logger.debug('[PluginManager] Removing all plugins...')
|
self.logger.debug('Removing all plugins...')
|
||||||
for p_queue in self.pluginQueueDict:
|
for p_queue in self.pluginQueueDict:
|
||||||
self.pluginQueueDict[p_queue].put(ShutdownMode(), 1)
|
self.pluginQueueDict[p_queue].put(ShutdownMode(), 1)
|
||||||
self.plugins = []
|
self.plugins = []
|
||||||
self.pluginQueueDict = dict()
|
self.pluginQueueDict = dict()
|
||||||
self.logger.debug('[PluginManager] All plugins were removed successfully.')
|
self.logger.debug('All plugins were removed successfully.')
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.logger.error(
|
self.logger.error(
|
||||||
'[PluginManager] A problem occurred while removing plugins. Error Message :{0}.'.format(str(e)))
|
'A problem occurred while removing plugins. Error Message :{0}.'.format(str(e)))
|
||||||
|
|
||||||
def remove_single_plugin(self, plugin_name):
|
def remove_single_plugin(self, plugin_name):
|
||||||
try:
|
try:
|
||||||
self.logger.debug('[PluginManager] Trying to remove {0} plugin...'.format(plugin_name))
|
self.logger.debug('Trying to remove {0} plugin...'.format(plugin_name))
|
||||||
if self.is_plugin_loaded(plugin_name):
|
if self.is_plugin_loaded(plugin_name):
|
||||||
self.logger.debug('[PluginManager] {0} plugin is killing...'.format(plugin_name))
|
self.logger.debug('{0} plugin is killing...'.format(plugin_name))
|
||||||
self.pluginQueueDict[plugin_name].put(ShutdownMode(), 1)
|
self.pluginQueueDict[plugin_name].put(ShutdownMode(), 1)
|
||||||
del self.pluginQueueDict[plugin_name]
|
del self.pluginQueueDict[plugin_name]
|
||||||
|
|
||||||
for plugin in self.plugins:
|
for plugin in self.plugins:
|
||||||
if plugin.name == plugin_name:
|
if plugin.name == plugin_name:
|
||||||
self.plugins.remove(plugin)
|
self.plugins.remove(plugin)
|
||||||
self.logger.debug('[PluginManager] {0} plugin was removed.'.format(plugin_name))
|
self.logger.debug('{0} plugin was removed.'.format(plugin_name))
|
||||||
else:
|
else:
|
||||||
self.logger.warning('[PluginManager] {0} plugin not found.'.format(plugin_name))
|
self.logger.warning('{0} plugin not found.'.format(plugin_name))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.logger.error(
|
self.logger.error(
|
||||||
'[PluginManager] A problem occurred while removing {0} plugin. Error Message :{1}.'.format(plugin_name,
|
'A problem occurred while removing {0} plugin. Error Message :{1}.'.format(plugin_name,
|
||||||
str(e)))
|
str(e)))
|
||||||
|
|
||||||
def find_command(self, pluginName, commandId):
|
def find_command(self, pluginName, commandId):
|
||||||
location = os.path.join(self.configManager.get("PLUGIN", "pluginFolderPath"), pluginName)
|
location = os.path.join(self.configManager.get("PLUGIN", "pluginFolderPath"), pluginName)
|
||||||
|
@ -156,8 +156,8 @@ class PluginManager(object):
|
||||||
def process_task(self, task):
|
def process_task(self, task):
|
||||||
|
|
||||||
##
|
##
|
||||||
scope = Scope().getInstance()
|
scope = Scope().get_instance()
|
||||||
self.messenger = scope.getMessenger()
|
self.messenger = scope.get_messenger()
|
||||||
##
|
##
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -167,14 +167,14 @@ class PluginManager(object):
|
||||||
self.pluginQueueDict[plugin_name].put(task, 1)
|
self.pluginQueueDict[plugin_name].put(task, 1)
|
||||||
else:
|
else:
|
||||||
self.logger.warning(
|
self.logger.warning(
|
||||||
'[PluginManager] {0} plugin not found. Task was delayed. Ahenk will request plugin from Lider if distribution available'.format(
|
'{0} plugin not found. Task was delayed. Ahenk will request plugin from Lider if distribution available'.format(
|
||||||
plugin_name))
|
plugin_name))
|
||||||
self.delayed_tasks[plugin_name] = task
|
self.delayed_tasks[plugin_name] = task
|
||||||
msg = self.message_manager.missing_plugin_message(PluginBean(name=plugin_name, version=plugin_ver))
|
msg = self.message_manager.missing_plugin_message(PluginBean(name=plugin_name, version=plugin_ver))
|
||||||
self.messenger.send_direct_message(msg)
|
self.messenger.send_direct_message(msg)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.logger.error(
|
self.logger.error(
|
||||||
'[PluginManager] Exception occurred while processing task. Error Message: {0}'.format(str(e)))
|
'Exception occurred while processing task. Error Message: {0}'.format(str(e)))
|
||||||
|
|
||||||
def find_policy_module(self, plugin_name):
|
def find_policy_module(self, plugin_name):
|
||||||
location = os.path.join(self.configManager.get("PLUGIN", "pluginFolderPath"), plugin_name)
|
location = os.path.join(self.configManager.get("PLUGIN", "pluginFolderPath"), plugin_name)
|
||||||
|
@ -182,18 +182,18 @@ class PluginManager(object):
|
||||||
info = imp.find_module("policy", [location])
|
info = imp.find_module("policy", [location])
|
||||||
return imp.load_module("policy", *info)
|
return imp.load_module("policy", *info)
|
||||||
else:
|
else:
|
||||||
self.logger.warning('[PluginManager] policy.py not found Plugin Name : ' + str(plugin_name))
|
self.logger.warning('policy.py not found Plugin Name : ' + str(plugin_name))
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def process_policy(self, policy):
|
def process_policy(self, policy):
|
||||||
|
|
||||||
self.logger.info('[PluginManager] Processing policies...')
|
self.logger.info('Processing policies...')
|
||||||
username = policy.username
|
username = policy.username
|
||||||
ahenk_profiles = policy.ahenk_profiles
|
ahenk_profiles = policy.ahenk_profiles
|
||||||
user_profiles = policy.user_profiles
|
user_profiles = policy.user_profiles
|
||||||
|
|
||||||
if ahenk_profiles is not None and len(ahenk_profiles) > 0:
|
if ahenk_profiles is not None and len(ahenk_profiles) > 0:
|
||||||
self.logger.info('[PluginManager] Working on Ahenk profiles...')
|
self.logger.info('Working on Ahenk profiles...')
|
||||||
for agent_profile in ahenk_profiles:
|
for agent_profile in ahenk_profiles:
|
||||||
same_plugin_profile = None
|
same_plugin_profile = None
|
||||||
|
|
||||||
|
@ -205,12 +205,12 @@ class PluginManager(object):
|
||||||
if same_plugin_profile is not None:
|
if same_plugin_profile is not None:
|
||||||
if agent_profile.overridable.lower() == 'true':
|
if agent_profile.overridable.lower() == 'true':
|
||||||
self.logger.debug(
|
self.logger.debug(
|
||||||
'[PluginManager] Agent profile of {0} plugin will not executed because of '
|
'Agent profile of {0} plugin will not executed because of '
|
||||||
'profile override rules.'.format(agent_profile.plugin.name))
|
'profile override rules.'.format(agent_profile.plugin.name))
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
self.logger.warning(
|
self.logger.warning(
|
||||||
'[PluginManager] User profile of {0} plugin will not executed because of '
|
'User profile of {0} plugin will not executed because of '
|
||||||
'profile override rules.'.format(agent_profile.plugin.name))
|
'profile override rules.'.format(agent_profile.plugin.name))
|
||||||
user_profiles.remove(same_plugin_profile)
|
user_profiles.remove(same_plugin_profile)
|
||||||
|
|
||||||
|
@ -218,7 +218,7 @@ class PluginManager(object):
|
||||||
self.process_profile(agent_profile)
|
self.process_profile(agent_profile)
|
||||||
|
|
||||||
if user_profiles is not None and len(user_profiles) > 0:
|
if user_profiles is not None and len(user_profiles) > 0:
|
||||||
self.logger.info('[PluginManager] Working on User profiles...')
|
self.logger.info('Working on User profiles...')
|
||||||
for user_profile in user_profiles:
|
for user_profile in user_profiles:
|
||||||
user_profile.set_username(username)
|
user_profile.set_username(username)
|
||||||
self.process_profile(user_profile)
|
self.process_profile(user_profile)
|
||||||
|
@ -233,14 +233,14 @@ class PluginManager(object):
|
||||||
self.pluginQueueDict[plugin_name].put(profile, 1)
|
self.pluginQueueDict[plugin_name].put(profile, 1)
|
||||||
else:
|
else:
|
||||||
self.logger.warning(
|
self.logger.warning(
|
||||||
'[PluginManager] {0} plugin not found. Profile was delayed. Ahenk will request plugin from Lider if distribution available'.format(
|
'{0} plugin not found. Profile was delayed. Ahenk will request plugin from Lider if distribution available'.format(
|
||||||
plugin_name))
|
plugin_name))
|
||||||
self.delayed_profiles[plugin_name] = profile
|
self.delayed_profiles[plugin_name] = profile
|
||||||
msg = self.message_manager.missing_plugin_message(PluginBean(name=plugin_name, version=plugin_ver))
|
msg = self.message_manager.missing_plugin_message(PluginBean(name=plugin_name, version=plugin_ver))
|
||||||
self.scope.getMessenger().send_direct_message(msg)
|
self.scope.get_messenger().send_direct_message(msg)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.logger.error(
|
self.logger.error(
|
||||||
'[PluginManager] Exception occurred while processing profile. Error Message: {0}'.format(str(e)))
|
'Exception occurred while processing profile. Error Message: {0}'.format(str(e)))
|
||||||
|
|
||||||
def check_plugin_exists(self, plugin_name, version=None):
|
def check_plugin_exists(self, plugin_name, version=None):
|
||||||
|
|
||||||
|
@ -267,16 +267,16 @@ class PluginManager(object):
|
||||||
elif mode_type == 'safe':
|
elif mode_type == 'safe':
|
||||||
mode = SafeMode(username)
|
mode = SafeMode(username)
|
||||||
else:
|
else:
|
||||||
self.logger.error('[PluginManager] Unknown mode type: {0}'.format(mode_type))
|
self.logger.error('Unknown mode type: {0}'.format(mode_type))
|
||||||
|
|
||||||
if mode is not None:
|
if mode is not None:
|
||||||
self.logger.info('[PluginManager] {0} mode is running'.format(mode_type))
|
self.logger.info('{0} mode is running'.format(mode_type))
|
||||||
for plugin_name in self.pluginQueueDict:
|
for plugin_name in self.pluginQueueDict:
|
||||||
try:
|
try:
|
||||||
self.pluginQueueDict[plugin_name].put(mode, 1)
|
self.pluginQueueDict[plugin_name].put(mode, 1)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.logger.error(
|
self.logger.error(
|
||||||
'[PluginManager] Exception occurred while switching safe mode. Error Message : {0}'.format(
|
'Exception occurred while switching safe mode. Error Message : {0}'.format(
|
||||||
str(e)))
|
str(e)))
|
||||||
|
|
||||||
def find_module(self, mode, plugin_name):
|
def find_module(self, mode, plugin_name):
|
||||||
|
@ -287,7 +287,7 @@ class PluginManager(object):
|
||||||
info = imp.find_module(mode, [location])
|
info = imp.find_module(mode, [location])
|
||||||
return imp.load_module(mode, *info)
|
return imp.load_module(mode, *info)
|
||||||
else:
|
else:
|
||||||
self.logger.warning('[PluginManager] {0} not found in {1} plugin'.format((mode + '.py'), plugin_name))
|
self.logger.warning('{0} not found in {1} plugin'.format((mode + '.py'), plugin_name))
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def install_listener(self):
|
def install_listener(self):
|
||||||
|
|
|
@ -16,52 +16,52 @@ from base.timer.timer import Timer
|
||||||
|
|
||||||
class Registration:
|
class Registration:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
scope = Scope().getInstance()
|
scope = Scope().get_instance()
|
||||||
self.logger = scope.getLogger()
|
self.logger = scope.get_logger()
|
||||||
self.message_manager = scope.getMessageManager()
|
self.message_manager = scope.get_message_manager()
|
||||||
self.event_manager = scope.getEventManager()
|
self.event_manager = scope.get_event_manager()
|
||||||
self.messenger = scope.getMessenger()
|
self.messenger = scope.get_messenger()
|
||||||
self.conf_manager = scope.getConfigurationManager()
|
self.conf_manager = scope.get_configuration_manager()
|
||||||
self.db_service = scope.getDbService()
|
self.db_service = scope.get_db_service()
|
||||||
|
|
||||||
self.event_manager.register_event('REGISTRATION_RESPONSE', self.registration_process)
|
self.event_manager.register_event('REGISTRATION_RESPONSE', self.registration_process)
|
||||||
|
|
||||||
if self.is_registered():
|
if self.is_registered():
|
||||||
self.logger.debug('[Registration] Ahenk already registered')
|
self.logger.debug('Ahenk already registered')
|
||||||
else:
|
else:
|
||||||
self.register(True)
|
self.register(True)
|
||||||
|
|
||||||
def registration_request(self):
|
def registration_request(self):
|
||||||
self.logger.debug('[Registration] Requesting registration')
|
self.logger.debug('Requesting registration')
|
||||||
SetupTimer.start(Timer(System.Ahenk.registration_timeout(), timeout_function=self.registration_timeout,
|
SetupTimer.start(Timer(System.Ahenk.registration_timeout(), timeout_function=self.registration_timeout,
|
||||||
checker_func=self.is_registered, kwargs=None))
|
checker_func=self.is_registered, kwargs=None))
|
||||||
anon_messenger = AnonymousMessenger(self.message_manager.registration_msg())
|
anon_messenger = AnonymousMessenger(self.message_manager.registration_msg())
|
||||||
anon_messenger.connect_to_server()
|
anon_messenger.connect_to_server()
|
||||||
|
|
||||||
def ldap_registration_request(self):
|
def ldap_registration_request(self):
|
||||||
self.logger.debug('[Registration] Requesting LDAP registration')
|
self.logger.debug('Requesting LDAP registration')
|
||||||
self.messenger.send_Direct_message(self.message_manager.ldap_registration_msg())
|
self.messenger.send_Direct_message(self.message_manager.ldap_registration_msg())
|
||||||
|
|
||||||
def registration_process(self, reg_reply):
|
def registration_process(self, reg_reply):
|
||||||
self.logger.debug('[Registration] Reading registration reply')
|
self.logger.debug('Reading registration reply')
|
||||||
j = json.loads(reg_reply)
|
j = json.loads(reg_reply)
|
||||||
self.logger.debug('[Registration]' + j['message'])
|
self.logger.debug('[Registration]' + j['message'])
|
||||||
status = str(j['status']).lower()
|
status = str(j['status']).lower()
|
||||||
dn = str(j['agentDn'])
|
dn = str(j['agentDn'])
|
||||||
|
|
||||||
self.logger.debug('[Registration] Registration status: ' + str(status))
|
self.logger.debug('Registration status: ' + str(status))
|
||||||
|
|
||||||
if 'already_exists' == str(status) or 'registered' == str(status) or 'registered_without_ldap' == str(status):
|
if 'already_exists' == str(status) or 'registered' == str(status) or 'registered_without_ldap' == str(status):
|
||||||
self.logger.debug('dn:' + dn)
|
self.logger.debug('Current dn:' + dn)
|
||||||
self.update_registration_attrs(dn)
|
self.update_registration_attrs(dn)
|
||||||
elif 'registration_error' == str(status):
|
elif 'registration_error' == str(status):
|
||||||
self.logger.info('[Registration] Registration is failed. New registration request will send')
|
self.logger.info('Registration is failed. New registration request will send')
|
||||||
self.re_register()
|
self.re_register()
|
||||||
else:
|
else:
|
||||||
self.logger.error('[Registration] Bad message type of registration response ')
|
self.logger.error('Bad message type of registration response ')
|
||||||
|
|
||||||
def update_registration_attrs(self, dn=None):
|
def update_registration_attrs(self, dn=None):
|
||||||
self.logger.debug('[Registration] Registration configuration is updating...')
|
self.logger.debug('Registration configuration is updating...')
|
||||||
self.db_service.update('registration', ['dn', 'registered'], [dn, 1], ' registered = 0')
|
self.db_service.update('registration', ['dn', 'registered'], [dn, 1], ' registered = 0')
|
||||||
|
|
||||||
if self.conf_manager.has_section('CONNECTION'):
|
if self.conf_manager.has_section('CONNECTION'):
|
||||||
|
@ -72,7 +72,7 @@ class Registration:
|
||||||
# TODO get file path?
|
# TODO get file path?
|
||||||
with open('/etc/ahenk/ahenk.conf', 'w') as configfile:
|
with open('/etc/ahenk/ahenk.conf', 'w') as configfile:
|
||||||
self.conf_manager.write(configfile)
|
self.conf_manager.write(configfile)
|
||||||
self.logger.debug('[Registration] Registration configuration file is updated')
|
self.logger.debug('Registration configuration file is updated')
|
||||||
|
|
||||||
def is_registered(self):
|
def is_registered(self):
|
||||||
|
|
||||||
|
@ -99,7 +99,7 @@ class Registration:
|
||||||
|
|
||||||
self.db_service.delete('registration', ' 1==1 ')
|
self.db_service.delete('registration', ' 1==1 ')
|
||||||
self.db_service.update('registration', cols, vals)
|
self.db_service.update('registration', cols, vals)
|
||||||
self.logger.debug('[Registration] Registration parameters were created')
|
self.logger.debug('Registration parameters were created')
|
||||||
|
|
||||||
def get_registration_params(self):
|
def get_registration_params(self):
|
||||||
|
|
||||||
|
@ -146,21 +146,21 @@ class Registration:
|
||||||
return json.dumps(params)
|
return json.dumps(params)
|
||||||
|
|
||||||
def unregister(self):
|
def unregister(self):
|
||||||
self.logger.debug('[Registration] Ahenk is unregistering...')
|
self.logger.debug('Ahenk is unregistering...')
|
||||||
self.db_service.delete('registration', ' 1==1 ')
|
self.db_service.delete('registration', ' 1==1 ')
|
||||||
self.logger.debug('[Registration] Ahenk is unregistered')
|
self.logger.debug('Ahenk is unregistered')
|
||||||
|
|
||||||
def re_register(self):
|
def re_register(self):
|
||||||
self.logger.debug('[Registration] Reregistrating...')
|
self.logger.debug('Reregistrating...')
|
||||||
self.unregister()
|
self.unregister()
|
||||||
self.register(False)
|
self.register(False)
|
||||||
|
|
||||||
def generate_uuid(self, depend_mac=True):
|
def generate_uuid(self, depend_mac=True):
|
||||||
if depend_mac is False:
|
if depend_mac is False:
|
||||||
self.logger.debug('[Registration] uuid creating randomly')
|
self.logger.debug('uuid creating randomly')
|
||||||
return uuid.uuid4() # make a random UUID
|
return uuid.uuid4() # make a random UUID
|
||||||
else:
|
else:
|
||||||
self.logger.debug('[Registration] uuid creating according to mac address')
|
self.logger.debug('uuid creating according to mac address')
|
||||||
return uuid.uuid3(uuid.NAMESPACE_DNS,
|
return uuid.uuid3(uuid.NAMESPACE_DNS,
|
||||||
str(get_mac())) # make a UUID using an MD5 hash of a namespace UUID and a mac address
|
str(get_mac())) # make a UUID using an MD5 hash of a namespace UUID and a mac address
|
||||||
|
|
||||||
|
@ -169,8 +169,8 @@ class Registration:
|
||||||
|
|
||||||
def registration_timeout(self):
|
def registration_timeout(self):
|
||||||
self.logger.error(
|
self.logger.error(
|
||||||
'[Registration] Could not reach registration response from Lider. Be sure XMPP server is reachable and it supports anonymous message, Lider is running properly '
|
'Could not reach registration response from Lider. Be sure XMPP server is reachable and it supports anonymous message, Lider is running properly '
|
||||||
'and it is connected to XMPP server! Check your Ahenk configuration file (/etc/ahenk/ahenk.conf)')
|
'and it is connected to XMPP server! Check your Ahenk configuration file (/etc/ahenk/ahenk.conf)')
|
||||||
self.logger.error('[Registration] Ahenk is shutting down...')
|
self.logger.error('Ahenk is shutting down...')
|
||||||
print('Ahenk is shutting down...')
|
print('Ahenk is shutting down...')
|
||||||
System.Process.kill_by_pid(int(System.Ahenk.get_pid_number()))
|
System.Process.kill_by_pid(int(System.Ahenk.get_pid_number()))
|
||||||
|
|
|
@ -8,11 +8,11 @@ from base.scope import Scope
|
||||||
|
|
||||||
class ScheduleTaskJob(object):
|
class ScheduleTaskJob(object):
|
||||||
def __init__(self, task):
|
def __init__(self, task):
|
||||||
scope = Scope.getInstance()
|
scope = Scope.get_instance()
|
||||||
|
|
||||||
self.logger = scope.getLogger()
|
self.logger = scope.get_logger()
|
||||||
self.task_manager = scope.getTaskManager()
|
self.task_manager = scope.get_task_manager()
|
||||||
self.plugin_manager = scope.getPluginManager()
|
self.plugin_manager = scope.get_plugin_manager()
|
||||||
self.task = task
|
self.task = task
|
||||||
cron_sj = self.parse_cron_str(task.get_cron_str())
|
cron_sj = self.parse_cron_str(task.get_cron_str())
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -2,40 +2,41 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# Author: İsmail BAŞARAN <ismail.basaran@tubitak.gov.tr> <basaran.ismaill@gmail.com>
|
# Author: İsmail BAŞARAN <ismail.basaran@tubitak.gov.tr> <basaran.ismaill@gmail.com>
|
||||||
|
|
||||||
from base.scope import Scope
|
|
||||||
from base.model.task import Task
|
from base.model.task import Task
|
||||||
|
from base.scope import Scope
|
||||||
|
|
||||||
|
|
||||||
class ScheduleTaskDB(object):
|
class ScheduleTaskDB(object):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
scope = Scope.getInstance()
|
scope = Scope.get_instance()
|
||||||
self.logger = scope.getLogger()
|
self.logger = scope.get_logger()
|
||||||
self.db_service = scope.getDbService()
|
self.db_service = scope.get_db_service()
|
||||||
|
|
||||||
def initialize(self):
|
def initialize(self):
|
||||||
self.logger.debug('[ScheduleTaskDB] Initializing scheduler database...')
|
self.logger.debug('Initializing scheduler database...')
|
||||||
self.db_service.check_and_create_table('schedule_task', ['id INTEGER PRIMARY KEY AUTOINCREMENT', 'task_id TEXT'])
|
self.db_service.check_and_create_table('schedule_task',
|
||||||
self.logger.debug('[ScheduleTaskDB] Scheduler database is ok.')
|
['id INTEGER PRIMARY KEY AUTOINCREMENT', 'task_id TEXT'])
|
||||||
|
self.logger.debug('Scheduler database is ok.')
|
||||||
|
|
||||||
def save(self, task):
|
def save(self, task):
|
||||||
self.logger.debug('[ScheduleTaskDB] Preparing schedule task for save operation... creating columns and values...')
|
self.logger.debug('Preparing schedule task for save operation... creating columns and values...')
|
||||||
cols = ['task_id']
|
cols = ['task_id']
|
||||||
values = [task.get_id()]
|
values = [task.get_id()]
|
||||||
self.logger.debug('[ScheduleTaskDB] Saving scheduler task to db... ')
|
self.logger.debug('Saving scheduler task to db... ')
|
||||||
self.db_service.update('schedule_task', cols, values, None)
|
self.db_service.update('schedule_task', cols, values, None)
|
||||||
self.logger.debug('[ScheduleTaskDB] Scheduler task saved.')
|
self.logger.debug('Scheduler task saved.')
|
||||||
|
|
||||||
def delete(self, task_id):
|
def delete(self, task_id):
|
||||||
try:
|
try:
|
||||||
self.logger.debug('[ScheduleTaskDB] Deleting schedule task. Task id=' + str(task_id))
|
self.logger.debug('Deleting schedule task. Task id=' + str(task_id))
|
||||||
self.db_service.delete('schedule_task', 'task_id=' + str(task_id))
|
self.db_service.delete('schedule_task', 'task_id=' + str(task_id))
|
||||||
self.logger.debug('[ScheduleTaskDB] Deleting schedule task deleted successfully. task id=' + str(task_id))
|
self.logger.debug('Deleting schedule task deleted successfully. task id=' + str(task_id))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.logger.error('[ScheduleTaskDB] Exception occur when deleting schedule task ' + str(e))
|
self.logger.error('Exception occur when deleting schedule task ' + str(e))
|
||||||
|
|
||||||
def load(self):
|
def load(self):
|
||||||
try:
|
try:
|
||||||
self.logger.debug('[ScheduleTaskDB] Loading schedule tasks...')
|
self.logger.debug('Loading schedule tasks...')
|
||||||
rows = self.db_service.select('schedule_task')
|
rows = self.db_service.select('schedule_task')
|
||||||
tasks = []
|
tasks = []
|
||||||
for row in rows:
|
for row in rows:
|
||||||
|
@ -44,7 +45,7 @@ class ScheduleTaskDB(object):
|
||||||
task.from_json(task_json)
|
task.from_json(task_json)
|
||||||
tasks.append(task)
|
tasks.append(task)
|
||||||
self.logger.debug(
|
self.logger.debug(
|
||||||
'[ScheduleTaskDB] Schedule tasks loaded successfully. Schedule Tasks size=' + str(len(tasks)))
|
'Schedule tasks loaded successfully. Schedule Tasks size=' + str(len(tasks)))
|
||||||
return tasks
|
return tasks
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.logger.error('[ScheduleTaskDB] Exception occur when loading schedule tasks! ' + str(e))
|
self.logger.error('Exception occur when loading schedule tasks! ' + str(e))
|
||||||
|
|
|
@ -18,9 +18,9 @@ from base.scope import Scope
|
||||||
|
|
||||||
class System:
|
class System:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
scope = Scope().getInstance()
|
scope = Scope().get_instance()
|
||||||
self.db_service = scope.getDbService()
|
self.db_service = scope.get_db_service()
|
||||||
self.logger = scope.getLogger()
|
self.logger = scope.get_logger()
|
||||||
|
|
||||||
class BIOS(object):
|
class BIOS(object):
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
|
|
@ -11,9 +11,9 @@ class TaskJob(threading.Thread):
|
||||||
|
|
||||||
def __init__(self, task):
|
def __init__(self, task):
|
||||||
super(TaskJob, self).__init__()
|
super(TaskJob, self).__init__()
|
||||||
scope = Scope.getInstance()
|
scope = Scope.get_instance()
|
||||||
self.task = task
|
self.task = task
|
||||||
self.pluginManager = scope.getPluginManager()
|
self.pluginManager = scope.get_plugin_manager()
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
self.pluginManager.process(self.task)
|
self.pluginManager.process(self.task)
|
||||||
|
|
|
@ -12,32 +12,33 @@ class TaskManager(object):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
# super(TaskManager, self).__init__()
|
# super(TaskManager, self).__init__()
|
||||||
scope = Scope.getInstance()
|
scope = Scope.get_instance()
|
||||||
self.pluginManager = scope.getPluginManager()
|
self.pluginManager = scope.get_plugin_manager()
|
||||||
self.logger = scope.getLogger()
|
self.logger = scope.get_logger()
|
||||||
self.db_service = scope.getDbService()
|
self.db_service = scope.get_db_service()
|
||||||
self.scheduler = scope.get_scheduler()
|
self.scheduler = scope.get_scheduler()
|
||||||
|
|
||||||
def addTask(self, task):
|
def addTask(self, task):
|
||||||
try:
|
try:
|
||||||
self.saveTask(task)
|
self.saveTask(task)
|
||||||
if task.get_cron_str() is None or task.get_cron_str() == '':
|
if task.get_cron_str() is None or task.get_cron_str() == '':
|
||||||
self.logger.debug('[TaskManager] Adding task ... ')
|
self.logger.debug('Adding task ... ')
|
||||||
self.pluginManager.process_task(task)
|
self.pluginManager.process_task(task)
|
||||||
else:
|
else:
|
||||||
self.scheduler.save_and_add_job(task)
|
self.scheduler.save_and_add_job(task)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.logger.debug('[TaskManager] Exception occurred when adding task. Error Message: {0}'.format(str(e)))
|
self.logger.debug('Exception occurred when adding task. Error Message: {0}'.format(str(e)))
|
||||||
|
|
||||||
def addPolicy(self, policy):
|
def addPolicy(self, policy):
|
||||||
try:
|
try:
|
||||||
self.pluginManager.process_policy(policy)
|
self.pluginManager.process_policy(policy)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.logger.error("[TaskManager] Exception occurred when adding policy. Error Message: {0}".format(str(e)))
|
self.logger.error("Exception occurred when adding policy. Error Message: {0}".format(str(e)))
|
||||||
|
|
||||||
def saveTask(self, task):
|
def saveTask(self, task):
|
||||||
try:
|
try:
|
||||||
|
self.logger.debug('task save')
|
||||||
task_cols = ['id', 'create_date', 'modify_date', 'command_cls_id', 'parameter_map', 'deleted', 'plugin',
|
task_cols = ['id', 'create_date', 'modify_date', 'command_cls_id', 'parameter_map', 'deleted', 'plugin',
|
||||||
'cron_expr', 'file_server']
|
'cron_expr', 'file_server']
|
||||||
plu_cols = ['active', 'create_date', 'deleted', 'description', 'machine_oriented', 'modify_date', 'name',
|
plu_cols = ['active', 'create_date', 'deleted', 'description', 'machine_oriented', 'modify_date', 'name',
|
||||||
|
@ -54,7 +55,7 @@ class TaskManager(object):
|
||||||
str(plugin_id), str(task.get_cron_str()), str(task.get_file_server())]
|
str(plugin_id), str(task.get_cron_str()), str(task.get_file_server())]
|
||||||
self.db_service.update('task', task_cols, values)
|
self.db_service.update('task', task_cols, values)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.logger.error("[TaskManager] Exception occurred while saving task. Error Message: {0}".format(str(e)))
|
self.logger.error("Exception occurred while saving task. Error Message: {0}".format(str(e)))
|
||||||
|
|
||||||
def updateTask(self, task):
|
def updateTask(self, task):
|
||||||
# TODO not implemented yet
|
# TODO not implemented yet
|
||||||
|
|
Loading…
Reference in a new issue