variable names fixed and all logs formatted

This commit is contained in:
Volkan Şahin 2016-09-21 12:05:48 +03:00
parent 52efbbb100
commit b002763145
16 changed files with 228 additions and 221 deletions

View file

@ -13,9 +13,9 @@ class AhenkDbService(object):
"""
def __init__(self):
scope = Scope.getInstance()
self.logger = scope.getLogger()
self.configurationManager = scope.getConfigurationManager()
scope = Scope.get_instance()
self.logger = scope.get_logger()
self.configurationManager = scope.get_configuration_manager()
self.db_path = self.configurationManager.get('BASE', 'dbPath')
self.connection = None
self.cursor = None
@ -50,7 +50,7 @@ class AhenkDbService(object):
self.connection = sqlite3.connect(self.db_path, check_same_thread=False)
self.cursor = self.connection.cursor()
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):
@ -60,7 +60,7 @@ class AhenkDbService(object):
cols = ', '.join([str(x) for x in cols])
self.cursor.execute('create table if not exists ' + table_name + ' (' + cols + ')')
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:
self.lock.release()
@ -91,10 +91,10 @@ class AhenkDbService(object):
self.connection.commit()
return self.cursor.lastrowid
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
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:
self.lock.release()
@ -136,7 +136,7 @@ class AhenkDbService(object):
finally:
self.lock.release()
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=''):
if self.cursor:
@ -157,11 +157,11 @@ class AhenkDbService(object):
finally:
self.lock.release()
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):
try:
self.cursor.close()
self.connection.close()
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)))

View file

@ -25,15 +25,15 @@ class ExecutionManager(object):
def __init__(self):
super(ExecutionManager, self).__init__()
scope = Scope.getInstance()
self.config_manager = scope.getConfigurationManager()
self.event_manager = scope.getEventManager()
self.task_manager = scope.getTaskManager()
self.messenger = scope.getMessenger()
self.logger = scope.getLogger()
self.db_service = scope.getDbService()
self.message_manager = scope.getMessageManager()
self.plugin_manager = scope.getPluginManager()
scope = Scope.get_instance()
self.config_manager = scope.get_configuration_manager()
self.event_manager = scope.get_event_manager()
self.task_manager = scope.get_task_manager()
self.messenger = scope.get_messenger()
self.logger = scope.get_logger()
self.db_service = scope.get_db_service()
self.message_manager = scope.get_message_manager()
self.plugin_manager = scope.get_plugin_manager()
self.policy_executed = dict()
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']])
except Exception as e:
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):
plugin = json.loads(arg)
self.logger.debug('[ExecutionManager] Installing missing plugin')
self.logger.debug('Installing missing plugin')
try:
plugin_name = plugin['pluginName']
plugin_version = plugin['pluginVersion']
@ -82,37 +82,37 @@ class ExecutionManager(object):
downloaded_file = System.Ahenk.received_dir_path() + file_name
except Exception as e:
self.logger.error(
'[ExecutionManager] Plugin package could not fetch. Error Message: {0}.'.format(str(e)))
self.logger.error('[ExecutionManager] Plugin Installation is cancelling')
'Plugin package could not fetch. Error Message: {0}.'.format(str(e)))
self.logger.error('Plugin Installation is cancelling')
self.plugin_installation_failure(plugin_name, plugin_version)
return
try:
Util.install_with_gdebi(downloaded_file)
self.logger.debug('[ExecutionManager] Plugin installed.')
self.logger.debug('Plugin installed.')
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)
return
try:
Util.delete_file(downloaded_file)
self.logger.debug('[ExecutionManager] Temp files were removed.')
self.logger.debug('Temp files were removed.')
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:
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)))
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():
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'],
'id={0}'.format(profile.get_id()))
data = dict()
@ -130,14 +130,14 @@ class ExecutionManager(object):
"ve eksik olan eklenti kurulurken hata oluştu",
execution_id=related_policy[0][1], policy_version=related_policy[0][0],
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))
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():
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['message'] = "Görev işletilirken eklenti bulunamadı "
@ -152,10 +152,10 @@ class ExecutionManager(object):
message="Görev işletilirken eklenti bulunamadı "
"ve eksik olan eklenti kurulmaya çalışırken oluştu.",
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))
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):
if username in self.policy_executed:
@ -167,11 +167,11 @@ class ExecutionManager(object):
self.policy_executed[username] = False
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))
def execute_policy(self, arg):
self.logger.debug('[ExecutionManager] Updating policies...')
self.logger.debug('Updating policies...')
policy = self.json_to_PolicyBean(json.loads(arg))
self.policy_executed[policy.get_username()] = True
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)
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\'')
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)
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\'')
policy = self.get_active_policies(policy.get_username())
@ -314,10 +314,10 @@ class ExecutionManager(object):
json_server_conf = json.dumps(json.loads(arg)['fileServerConf'])
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.logger.debug('[ExecutionManager] Task added')
self.logger.debug('Task added')
def json_to_task_bean(self, json_data, file_server_conf=None):
plu = json_data['plugin']
@ -333,24 +333,24 @@ class ExecutionManager(object):
def execute_script(self, arg):
try:
self.logger.debug('[ExecutionManager] Executing script...')
messenger = Scope().getInstance().getMessenger()
self.logger.debug('Executing script...')
messenger = Scope().get_instance().get_messenger()
json_data = json.loads(arg)
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['type'] = 'SCRIPT_RESULT'
data['timestamp'] = str(Util.timestamp())
if result_code == 0:
self.logger.debug('[ExecutionManager] Command execution was finished successfully')
self.logger.debug('Command execution was finished successfully')
try:
temp_name = str(Util.generate_uuid())
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))
md5 = Util.get_md5_file(temp_full_path)
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'],
json_data['fileServerConf']['parameterMap'])
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)
self.logger.debug('[ExecutionManager] File was transferred')
self.logger.debug('File was transferred')
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:
self.logger.error('[ExecutionManager] A problem occurred while file transferring')
self.logger.error('A problem occurred while file transferring')
data['resultCode'] = '-1'
data[
'errorMessage'] = 'Command executed successfully but a problem occurred while sending result file'
@ -375,19 +375,19 @@ class ExecutionManager(object):
except Exception as e:
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)))
raise
else:
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['errorMessage'] = str(p_err)
messenger.send_direct_message(json.dumps(data))
except Exception as e:
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)))
def json_to_PolicyBean(self, json_data):

View file

@ -9,9 +9,9 @@ from base.file.http_file_transfer import Http
class FileTransferManager(object):
def __init__(self, protocol, parameter_map):
scope = Scope().getInstance()
self.logger = scope.getLogger()
self.configuration_manager = scope.getConfigurationManager()
scope = Scope().get_instance()
self.logger = scope.get_logger()
self.configuration_manager = scope.get_configuration_manager()
self.transporter = self.get_instance(protocol, parameter_map)
def get_instance(self, protocol, parameter_map):
@ -27,6 +27,6 @@ class FileTransferManager(object):
except Exception as e:
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)))
return None

View file

@ -11,14 +11,14 @@ from base.scope import Scope
class Http(object):
def __init__(self, parameter_map):
scope = Scope().getInstance()
self.logger = scope.getLogger()
self.configuration_manager = scope.getConfigurationManager()
scope = Scope().get_instance()
self.logger = scope.get_logger()
self.configuration_manager = scope.get_configuration_manager()
try:
self.url = parameter_map['url']
except Exception as e:
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):
pass
@ -33,10 +33,10 @@ class Http(object):
urllib.request.urlretrieve(self.url, 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)
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:
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
return file_md5

View file

@ -12,9 +12,9 @@ import logging
class Ssh(object):
def __init__(self, parameter_map):
scope = Scope().getInstance()
self.logger = scope.getLogger()
self.configuration_manager = scope.getConfigurationManager()
scope = Scope().get_instance()
self.logger = scope.get_logger()
self.configuration_manager = scope.get_configuration_manager()
logging.getLogger("paramiko").setLevel(logging.INFO)
try:
@ -30,14 +30,14 @@ class Ssh(object):
self.p_key = parameter_map['pkey']
except Exception as e:
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.logger.debug('[Ssh] Parameters set up')
self.logger.debug('Parameters set up')
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:
sftp = paramiko.SFTPClient.from_transport(self.connection)
try:
@ -47,14 +47,14 @@ class Ssh(object):
sftp.chdir(self.target_path)
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
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
def get_file(self):
self.logger.debug('[Ssh] Getting file ...')
def get_file(self, local_path=None):
self.logger.debug('Getting file ...')
file_md5 = None
try:
tmp_file_name = str(Util.generate_uuid())
@ -62,28 +62,32 @@ class Ssh(object):
sftp = paramiko.SFTPClient.from_transport(self.connection)
sftp.get(self.target_path, 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)
self.logger.debug('[Ssh] File was downloaded to {0} from {1}'.format(local_full_path, self.target_path))
if local_path is None:
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:
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
return file_md5
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:
connection = paramiko.Transport(self.target_hostname, int(self.target_port))
connection.connect(username=self.target_username, password=self.target_password, pkey=self.p_key)
self.connection = connection
self.logger.debug('[FileTransfer] Connected.')
self.logger.debug('Connected.')
except Exception as e:
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)))
def disconnect(self):
self.connection.close()
self.logger.debug('[FileTransfer] Connection is closed.')
self.logger.debug('Connection is closed.')
# TODO
pass

View file

@ -14,9 +14,9 @@ class MessageResponseQueue(threading.Thread):
def __init__(self, outQueue):
super(MessageResponseQueue, self).__init__()
scope = Scope.getInstance()
self.logger = scope.getLogger()
self.messageManager = scope.getMessenger()
scope = Scope.get_instance()
self.logger = scope.get_logger()
self.messageManager = scope.get_messenger()
self.outQueue = outQueue
def run(self):
@ -25,7 +25,7 @@ class MessageResponseQueue(threading.Thread):
# This item will send response to lider.
# item must be response message. Response message may be generic message type
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
self.messageManager.send_direct_message(responseMessage)
# self.outQueue.task_done()

View file

@ -1,22 +1,21 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Author: Volkan Şahin <volkansah.in> <bm.volkansahin@gmail.com>
import datetime
import json
from base.system.system import System
from base.scope import Scope
from base.system.system import System
from base.util.util import Util
# TODO Message Factory
class Messaging(object):
def __init__(self):
scope = Scope().getInstance()
self.logger = scope.getLogger()
self.conf_manager = scope.getConfigurationManager()
self.db_service = scope.getDbService()
self.event_manger = scope.getEventManager()
scope = Scope().get_instance()
self.logger = scope.get_logger()
self.conf_manager = scope.get_configuration_manager()
self.db_service = scope.get_db_service()
self.event_manger = scope.get_event_manager()
def missing_plugin_message(self, plugin):
data = dict()
@ -25,7 +24,7 @@ class Messaging(object):
data['pluginVersion'] = plugin.get_version()
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)
def task_status_msg(self, response):
@ -42,7 +41,7 @@ class Messaging(object):
data['timestamp'] = response.get_timestamp()
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)
def policy_status_msg(self, response):
@ -62,7 +61,7 @@ class Messaging(object):
data['timestamp'] = response.get_timestamp()
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)
def login_msg(self, username):
@ -72,7 +71,7 @@ class Messaging(object):
data['ipAddresses'] = str(System.Hardware.Network.ip_addresses()).replace('[', '').replace(']', '')
data['timestamp'] = Util.timestamp()
json_data = json.dumps(data)
self.logger.debug('[Messaging] Login message was created')
self.logger.debug('Login message was created')
return json_data
def logout_msg(self, username):
@ -81,14 +80,15 @@ class Messaging(object):
data['username'] = str(username)
data['timestamp'] = Util.timestamp()
json_data = json.dumps(data)
self.logger.debug('[Messaging] Logout message was created')
self.logger.debug('Logout message was created')
return json_data
def policy_request_msg(self, username):
data = dict()
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\'')
data['userPolicyVersion'] = user_policy_number
@ -97,7 +97,7 @@ class Messaging(object):
data['username'] = str(username)
data['timestamp'] = Util.timestamp()
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
def registration_msg(self):
@ -115,7 +115,7 @@ class Messaging(object):
data['timestamp'] = self.db_service.select_one_result('registration', 'timestamp', ' 1=1')
json_data = json.dumps(data)
self.logger.debug('[Messaging] Registration message was created')
self.logger.debug('Registration message was created')
return json_data
def ldap_registration_msg(self):
@ -128,7 +128,7 @@ class Messaging(object):
data['hostname'] = str(self.conf_manager.get('REGISTRATION', 'hostname'))
data['timestamp'] = Util.timestamp()
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
def unregister_msg(self):
@ -142,7 +142,7 @@ class Messaging(object):
# data['username'] = str(pwd.getpwuid( os.getuid() )[ 0 ])
data['timestamp'] = Util.timestamp()
json_data = json.dumps(data)
self.logger.debug('[Messaging] Unregister message was created')
self.logger.debug('Unregister message was created')
return json_data
def agreement_request_msg(self):
@ -159,7 +159,7 @@ class Messaging(object):
data['timestamp'] = Util.timestamp()
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
def agreement_answer_msg(self, username, answer):
@ -168,12 +168,13 @@ class Messaging(object):
data['username'] = username
data['accepted'] = answer
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 != '':
data['md5'] = Util.get_md5_text(contract_content)
else:
data['md5'] = ''
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

View file

@ -15,10 +15,10 @@ class AbstractPlugin(Util, System):
def __init__(self):
super(AbstractPlugin, self).__init__()
self.scope = Scope.getInstance()
self.scope = Scope.get_instance()
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):
return MessageCode
@ -28,19 +28,19 @@ class AbstractPlugin(Util, System):
def get_logger(self):
try:
return Scope.getInstance().getLogger()
return Scope.get_instance().get_logger()
except Exception as e:
self.scope.getLogger().error(
'[AbstractPlugin] A problem occurred while getting logger. Error Message: {0}'.format(str(e)))
self.scope.get_logger().error(
'A problem occurred while getting logger. Error Message: {0}'.format(str(e)))
return None
def configuration_manager(self):
try:
return self.scope.getConfigurationManager()
return self.scope.get_configuration_manager()
except Exception as e:
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)))
return None

View file

@ -7,7 +7,7 @@ import signal
from watchdog.events import FileSystemEventHandler
from base.command.commander import Commander
from base.command.command_manager import Commander
from base.system.system import System

View file

@ -12,7 +12,7 @@ from base.model.modes.login_mode import LoginMode
from base.model.modes.logout_mode import LogoutMode
from base.model.modes.safe_mode import SafeMode
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_install_listener import PluginInstallListener
from base.system.system import System
@ -24,11 +24,11 @@ class PluginManager(object):
def __init__(self):
super(PluginManager, self).__init__()
self.scope = Scope.getInstance()
self.configManager = self.scope.getConfigurationManager()
self.db_service = self.scope.getDbService()
self.message_manager = self.scope.getMessageManager()
self.logger = self.scope.getLogger()
self.scope = Scope.get_instance()
self.configManager = self.scope.get_configuration_manager()
self.db_service = self.scope.get_db_service()
self.message_manager = self.scope.get_message_manager()
self.logger = self.scope.get_logger()
self.plugins = []
self.pluginQueueDict = dict()
@ -40,22 +40,22 @@ class PluginManager(object):
# TODO version?
def load_plugins(self):
self.logger.info('[PluginManager] Loading plugins...')
self.logger.info('Loading plugins...')
self.plugins = []
self.logger.debug('[PluginManager] Lookup for possible plugins...')
self.logger.debug('Lookup for possible plugins...')
try:
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:
try:
self.load_single_plugin(plugin_name)
except Exception as e:
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)))
self.logger.info('[PluginManager] Loaded plugins successfully.')
self.logger.info('Loaded plugins successfully.')
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):
# 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(
location):
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:
if self.is_plugin_loaded(plugin_name):
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)
else:
self.pluginQueueDict[plugin_name] = PluginQueue()
@ -75,7 +75,7 @@ class PluginManager(object):
plugin.setDaemon(True)
plugin.start()
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
mode = InitMode()
@ -84,65 +84,65 @@ class PluginManager(object):
if plugin_name in self.delayed_profiles:
self.pluginQueueDict[plugin_name].put(self.delayed_profiles[plugin_name], 1)
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:
self.pluginQueueDict[plugin_name].put(self.delayed_tasks[plugin_name], 1)
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):
try:
self.logger.info('[PluginManager] Reloading plugins...')
self.logger.info('Reloading plugins...')
for p_queue in self.pluginQueueDict:
self.pluginQueueDict[p_queue].put(ShutdownMode(), 1)
self.plugins = []
self.load_plugins()
self.logger.info('[PluginManager] Plugin reloaded successfully.')
self.logger.info('Plugin reloaded successfully.')
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):
try:
self.logger.info('[PluginManager] {0} plugin is reloading'.format(plugin_name))
self.logger.debug('[PluginManager] {0} plugin is killing (in reloading action)'.format(plugin_name))
self.logger.info('{0} plugin is reloading'.format(plugin_name))
self.logger.debug('{0} plugin is killing (in reloading action)'.format(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)
except Exception as e:
self.logger.error(
'[PluginManager] A problem occurred while reloading {0} plugin. Error Message: {1}'.format(plugin_name,
str(e)))
'A problem occurred while reloading {0} plugin. Error Message: {1}'.format(plugin_name,
str(e)))
def remove_plugins(self):
try:
self.logger.debug('[PluginManager] Removing all plugins...')
self.logger.debug('Removing all plugins...')
for p_queue in self.pluginQueueDict:
self.pluginQueueDict[p_queue].put(ShutdownMode(), 1)
self.plugins = []
self.pluginQueueDict = dict()
self.logger.debug('[PluginManager] All plugins were removed successfully.')
self.logger.debug('All plugins were removed successfully.')
except Exception as e:
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):
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):
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)
del self.pluginQueueDict[plugin_name]
for plugin in self.plugins:
if plugin.name == plugin_name:
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:
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:
self.logger.error(
'[PluginManager] A problem occurred while removing {0} plugin. Error Message :{1}.'.format(plugin_name,
str(e)))
'A problem occurred while removing {0} plugin. Error Message :{1}.'.format(plugin_name,
str(e)))
def find_command(self, pluginName, commandId):
location = os.path.join(self.configManager.get("PLUGIN", "pluginFolderPath"), pluginName)
@ -156,8 +156,8 @@ class PluginManager(object):
def process_task(self, task):
##
scope = Scope().getInstance()
self.messenger = scope.getMessenger()
scope = Scope().get_instance()
self.messenger = scope.get_messenger()
##
try:
@ -167,14 +167,14 @@ class PluginManager(object):
self.pluginQueueDict[plugin_name].put(task, 1)
else:
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))
self.delayed_tasks[plugin_name] = task
msg = self.message_manager.missing_plugin_message(PluginBean(name=plugin_name, version=plugin_ver))
self.messenger.send_direct_message(msg)
except Exception as e:
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):
location = os.path.join(self.configManager.get("PLUGIN", "pluginFolderPath"), plugin_name)
@ -182,18 +182,18 @@ class PluginManager(object):
info = imp.find_module("policy", [location])
return imp.load_module("policy", *info)
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
def process_policy(self, policy):
self.logger.info('[PluginManager] Processing policies...')
self.logger.info('Processing policies...')
username = policy.username
ahenk_profiles = policy.ahenk_profiles
user_profiles = policy.user_profiles
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:
same_plugin_profile = None
@ -205,12 +205,12 @@ class PluginManager(object):
if same_plugin_profile is not None:
if agent_profile.overridable.lower() == 'true':
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))
continue
else:
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))
user_profiles.remove(same_plugin_profile)
@ -218,7 +218,7 @@ class PluginManager(object):
self.process_profile(agent_profile)
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:
user_profile.set_username(username)
self.process_profile(user_profile)
@ -233,14 +233,14 @@ class PluginManager(object):
self.pluginQueueDict[plugin_name].put(profile, 1)
else:
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))
self.delayed_profiles[plugin_name] = profile
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:
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):
@ -267,16 +267,16 @@ class PluginManager(object):
elif mode_type == 'safe':
mode = SafeMode(username)
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:
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:
try:
self.pluginQueueDict[plugin_name].put(mode, 1)
except Exception as e:
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)))
def find_module(self, mode, plugin_name):
@ -287,7 +287,7 @@ class PluginManager(object):
info = imp.find_module(mode, [location])
return imp.load_module(mode, *info)
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
def install_listener(self):

View file

@ -16,52 +16,52 @@ from base.timer.timer import Timer
class Registration:
def __init__(self):
scope = Scope().getInstance()
self.logger = scope.getLogger()
self.message_manager = scope.getMessageManager()
self.event_manager = scope.getEventManager()
self.messenger = scope.getMessenger()
self.conf_manager = scope.getConfigurationManager()
self.db_service = scope.getDbService()
scope = Scope().get_instance()
self.logger = scope.get_logger()
self.message_manager = scope.get_message_manager()
self.event_manager = scope.get_event_manager()
self.messenger = scope.get_messenger()
self.conf_manager = scope.get_configuration_manager()
self.db_service = scope.get_db_service()
self.event_manager.register_event('REGISTRATION_RESPONSE', self.registration_process)
if self.is_registered():
self.logger.debug('[Registration] Ahenk already registered')
self.logger.debug('Ahenk already registered')
else:
self.register(True)
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,
checker_func=self.is_registered, kwargs=None))
anon_messenger = AnonymousMessenger(self.message_manager.registration_msg())
anon_messenger.connect_to_server()
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())
def registration_process(self, reg_reply):
self.logger.debug('[Registration] Reading registration reply')
self.logger.debug('Reading registration reply')
j = json.loads(reg_reply)
self.logger.debug('[Registration]' + j['message'])
status = str(j['status']).lower()
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):
self.logger.debug('dn:' + dn)
self.logger.debug('Current dn:' + dn)
self.update_registration_attrs(dn)
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()
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):
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')
if self.conf_manager.has_section('CONNECTION'):
@ -72,7 +72,7 @@ class Registration:
# TODO get file path?
with open('/etc/ahenk/ahenk.conf', 'w') as 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):
@ -99,7 +99,7 @@ class Registration:
self.db_service.delete('registration', ' 1==1 ')
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):
@ -146,21 +146,21 @@ class Registration:
return json.dumps(params)
def unregister(self):
self.logger.debug('[Registration] Ahenk is unregistering...')
self.logger.debug('Ahenk is unregistering...')
self.db_service.delete('registration', ' 1==1 ')
self.logger.debug('[Registration] Ahenk is unregistered')
self.logger.debug('Ahenk is unregistered')
def re_register(self):
self.logger.debug('[Registration] Reregistrating...')
self.logger.debug('Reregistrating...')
self.unregister()
self.register(False)
def generate_uuid(self, depend_mac=True):
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
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,
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):
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)')
self.logger.error('[Registration] Ahenk is shutting down...')
self.logger.error('Ahenk is shutting down...')
print('Ahenk is shutting down...')
System.Process.kill_by_pid(int(System.Ahenk.get_pid_number()))

View file

@ -8,11 +8,11 @@ from base.scope import Scope
class ScheduleTaskJob(object):
def __init__(self, task):
scope = Scope.getInstance()
scope = Scope.get_instance()
self.logger = scope.getLogger()
self.task_manager = scope.getTaskManager()
self.plugin_manager = scope.getPluginManager()
self.logger = scope.get_logger()
self.task_manager = scope.get_task_manager()
self.plugin_manager = scope.get_plugin_manager()
self.task = task
cron_sj = self.parse_cron_str(task.get_cron_str())
try:

View file

@ -2,40 +2,41 @@
# -*- coding: utf-8 -*-
# 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.scope import Scope
class ScheduleTaskDB(object):
def __init__(self):
scope = Scope.getInstance()
self.logger = scope.getLogger()
self.db_service = scope.getDbService()
scope = Scope.get_instance()
self.logger = scope.get_logger()
self.db_service = scope.get_db_service()
def initialize(self):
self.logger.debug('[ScheduleTaskDB] Initializing scheduler database...')
self.db_service.check_and_create_table('schedule_task', ['id INTEGER PRIMARY KEY AUTOINCREMENT', 'task_id TEXT'])
self.logger.debug('[ScheduleTaskDB] Scheduler database is ok.')
self.logger.debug('Initializing scheduler database...')
self.db_service.check_and_create_table('schedule_task',
['id INTEGER PRIMARY KEY AUTOINCREMENT', 'task_id TEXT'])
self.logger.debug('Scheduler database is ok.')
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']
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.logger.debug('[ScheduleTaskDB] Scheduler task saved.')
self.logger.debug('Scheduler task saved.')
def delete(self, task_id):
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.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:
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):
try:
self.logger.debug('[ScheduleTaskDB] Loading schedule tasks...')
self.logger.debug('Loading schedule tasks...')
rows = self.db_service.select('schedule_task')
tasks = []
for row in rows:
@ -44,7 +45,7 @@ class ScheduleTaskDB(object):
task.from_json(task_json)
tasks.append(task)
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
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))

View file

@ -18,9 +18,9 @@ from base.scope import Scope
class System:
def __init__(self):
scope = Scope().getInstance()
self.db_service = scope.getDbService()
self.logger = scope.getLogger()
scope = Scope().get_instance()
self.db_service = scope.get_db_service()
self.logger = scope.get_logger()
class BIOS(object):
@staticmethod

View file

@ -11,9 +11,9 @@ class TaskJob(threading.Thread):
def __init__(self, task):
super(TaskJob, self).__init__()
scope = Scope.getInstance()
scope = Scope.get_instance()
self.task = task
self.pluginManager = scope.getPluginManager()
self.pluginManager = scope.get_plugin_manager()
def run(self):
self.pluginManager.process(self.task)

View file

@ -12,32 +12,33 @@ class TaskManager(object):
def __init__(self):
# super(TaskManager, self).__init__()
scope = Scope.getInstance()
self.pluginManager = scope.getPluginManager()
self.logger = scope.getLogger()
self.db_service = scope.getDbService()
scope = Scope.get_instance()
self.pluginManager = scope.get_plugin_manager()
self.logger = scope.get_logger()
self.db_service = scope.get_db_service()
self.scheduler = scope.get_scheduler()
def addTask(self, task):
try:
self.saveTask(task)
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)
else:
self.scheduler.save_and_add_job(task)
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):
try:
self.pluginManager.process_policy(policy)
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):
try:
self.logger.debug('task save')
task_cols = ['id', 'create_date', 'modify_date', 'command_cls_id', 'parameter_map', 'deleted', 'plugin',
'cron_expr', 'file_server']
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())]
self.db_service.update('task', task_cols, values)
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):
# TODO not implemented yet