mirror of
https://github.com/Pardus-LiderAhenk/ahenk
synced 2024-11-22 10:52:17 +03:00
running multiple policies is coded, deleting unassigned or deleted policies from agent db is coded
This commit is contained in:
parent
7471cc705a
commit
2875258147
7 changed files with 188 additions and 147 deletions
|
@ -32,11 +32,12 @@ class AhenkDbService(object):
|
||||||
'parameter_map BLOB', 'deleted INTEGER', 'plugin TEXT', 'cron_expr TEXT',
|
'parameter_map BLOB', 'deleted INTEGER', 'plugin TEXT', 'cron_expr TEXT',
|
||||||
'file_server TEXT'])
|
'file_server TEXT'])
|
||||||
self.check_and_create_table('policy',
|
self.check_and_create_table('policy',
|
||||||
['id INTEGER PRIMARY KEY AUTOINCREMENT', 'type TEXT', 'version TEXT', 'name TEXT',
|
['id INTEGER PRIMARY KEY AUTOINCREMENT', 'policy_id INTEGER',
|
||||||
'execution_id TEXT','expiration_date TEXT'])
|
'type TEXT', 'version TEXT', 'name TEXT',
|
||||||
|
'execution_id TEXT', 'expiration_date TEXT', 'assign_date TEXT'])
|
||||||
self.check_and_create_table('profile', ['id INTEGER', 'create_date TEXT', 'label TEXT', 'description TEXT',
|
self.check_and_create_table('profile', ['id INTEGER', 'create_date TEXT', 'label TEXT', 'description TEXT',
|
||||||
'overridable INTEGER', 'active TEXT', 'deleted TEXT',
|
'overridable INTEGER', 'active TEXT', 'deleted TEXT',
|
||||||
'profile_data TEXT', 'modify_date TEXT', 'plugin TEXT'])
|
'profile_data TEXT', 'modify_date TEXT', 'plugin TEXT', 'policy_id INTEGER'])
|
||||||
self.check_and_create_table('plugin',
|
self.check_and_create_table('plugin',
|
||||||
['id INTEGER PRIMARY KEY AUTOINCREMENT', 'active TEXT', 'create_date TEXT',
|
['id INTEGER PRIMARY KEY AUTOINCREMENT', 'active TEXT', 'create_date TEXT',
|
||||||
'deleted TEXT', 'description TEXT', 'machine_oriented TEXT', 'modify_date TEXT',
|
'deleted TEXT', 'description TEXT', 'machine_oriented TEXT', 'modify_date TEXT',
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
import json
|
import json
|
||||||
import time
|
import time
|
||||||
|
import datetime
|
||||||
from base.file.file_transfer_manager import FileTransferManager
|
from base.file.file_transfer_manager import FileTransferManager
|
||||||
from base.model.enum.content_type import ContentType
|
from base.model.enum.content_type import ContentType
|
||||||
from base.model.enum.message_code import MessageCode
|
from base.model.enum.message_code import MessageCode
|
||||||
|
@ -173,7 +174,10 @@ class ExecutionManager(object):
|
||||||
|
|
||||||
def execute_default_policy(self, username):
|
def execute_default_policy(self, username):
|
||||||
self.logger.debug('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))
|
policy_list = self.get_active_policies(username)
|
||||||
|
for i in range(len(policy_list)):
|
||||||
|
self.task_manager.addPolicy(policy_list[i])
|
||||||
|
|
||||||
|
|
||||||
def update_scheduled_task(self, arg):
|
def update_scheduled_task(self, arg):
|
||||||
self.logger.debug('Working on scheduled task ...')
|
self.logger.debug('Working on scheduled task ...')
|
||||||
|
@ -215,106 +219,121 @@ class ExecutionManager(object):
|
||||||
|
|
||||||
def execute_policy(self, arg):
|
def execute_policy(self, arg):
|
||||||
try:
|
try:
|
||||||
self.logger.debug('Updating policies...')
|
j = json.loads(str(arg))
|
||||||
policy = self.json_to_PolicyBean(json.loads(arg))
|
for i in range(len(j['executePolicyList'])):
|
||||||
self.policy_executed[policy.get_username()] = True
|
policy = self.json_to_PolicyBean(json.loads(json.dumps(j['executePolicyList'][i])))
|
||||||
machine_uid = self.db_service.select_one_result('registration', 'jid', 'registered=1')
|
self.logger.debug('Updating policies...')
|
||||||
ahenk_policy_ver = self.db_service.select_one_result('policy', 'version', 'type = \'A\'')
|
# policy is deleted or unassigned on server
|
||||||
user_policy_version = self.db_service.select_one_result('policy', 'version',
|
# delete on ahenk db
|
||||||
'type = \'U\' and name = \'' + policy.get_username() + '\'')
|
|
||||||
|
|
||||||
profile_columns = ['id', 'create_date', 'modify_date', 'label', 'description', 'overridable', 'active',
|
if policy.get_is_deleted():
|
||||||
'deleted', 'profile_data', 'plugin']
|
existing_policy_id = self.db_service.select('policy', ['id'],
|
||||||
plugin_columns = ['active', 'create_date', 'deleted', 'description', 'machine_oriented', 'modify_date',
|
'type = \'U\' and name = \'' + policy.get_username() + '\'' +
|
||||||
'name',
|
'and policy_id = ' + str(policy.get_policy_id()))
|
||||||
'policy_plugin', 'user_oriented', 'version', 'task_plugin', 'x_based']
|
existing_profile_list = self.db_service.select('profile',
|
||||||
|
['id', 'plugin', 'policy_id'],
|
||||||
if policy.get_ahenk_policy_version() != ahenk_policy_ver:
|
' id=' + str(existing_policy_id[0][0]))
|
||||||
ahenk_policy_id = self.db_service.select_one_result('policy', 'id', 'type = \'A\'')
|
for profile in existing_profile_list:
|
||||||
if ahenk_policy_id is not None:
|
self.db_service.delete('plugin', 'id=' + str(profile[1]))
|
||||||
self.db_service.delete('profile', 'id=' + str(ahenk_policy_id))
|
self.db_service.delete('profile', 'id=' + str(existing_policy_id[0][0]))
|
||||||
self.db_service.delete('plugin', 'id=' + str(ahenk_policy_id))
|
self.db_service.delete('policy', 'type = \'U\' and name = \'' + policy.get_username() + '\'' +
|
||||||
self.db_service.update('policy', ['version', 'execution_id', 'expiration_date'],
|
'and policy_id = ' + str(policy.get_policy_id()))
|
||||||
[str(policy.get_ahenk_policy_version()), policy.agent_execution_id,
|
|
||||||
str(policy.agent_expiration_date)], 'type=\'A\'')
|
|
||||||
else:
|
else:
|
||||||
self.db_service.update('policy', ['type', 'version', 'name', 'execution_id', 'expiration_date'],
|
self.policy_executed[policy.get_username()] = True
|
||||||
['A', str(policy.get_ahenk_policy_version()), machine_uid,
|
machine_uid = self.db_service.select_one_result('registration', 'jid', 'registered=1')
|
||||||
policy.get_agent_execution_id(), policy.agent_expiration_date])
|
user_policy_version = self.db_service.select_one_result('policy', 'version',
|
||||||
ahenk_policy_id = self.db_service.select_one_result('policy', 'id', 'type = \'A\'')
|
'type = \'U\' and name = \'' + policy.get_username() + '\'' +
|
||||||
|
'and policy_id = ' + str(policy.get_policy_id()))
|
||||||
|
|
||||||
for profile in policy.get_ahenk_profiles():
|
profile_columns = ['id', 'create_date', 'modify_date', 'label', 'description', 'overridable', 'active',
|
||||||
plugin = profile.get_plugin()
|
'deleted', 'profile_data', 'policy_id', 'plugin']
|
||||||
|
plugin_columns = ['active', 'create_date', 'deleted', 'description', 'machine_oriented', 'modify_date',
|
||||||
|
'name',
|
||||||
|
'policy_plugin', 'user_oriented', 'version', 'task_plugin', 'x_based']
|
||||||
|
|
||||||
plugin_args = [str(plugin.get_active()), str(plugin.get_create_date()), str(plugin.get_deleted()),
|
# if user_policy_version is null that means this policy is not added to db
|
||||||
str(plugin.get_description()), str(plugin.get_machine_oriented()),
|
# add this policy to db
|
||||||
str(plugin.get_modify_date()), str(plugin.get_name()),
|
if user_policy_version is None:
|
||||||
str(plugin.get_policy_plugin()),
|
self.db_service.update('policy', ['policy_id', 'type', 'version', 'name', 'execution_id', 'expiration_date', 'assign_date'],
|
||||||
str(plugin.get_user_oriented()), str(plugin.get_version()),
|
[policy.get_policy_id(), 'U', str(policy.get_user_policy_version()),
|
||||||
str(plugin.get_task_plugin()), str(plugin.get_x_based())]
|
policy.get_username(), policy.user_execution_id,
|
||||||
plugin_id = self.db_service.update('plugin', plugin_columns, plugin_args)
|
str(policy.user_expiration_date), str(policy.get_assign_date())])
|
||||||
|
user_policy_id = self.db_service.select_one_result('policy', 'id',
|
||||||
|
'type = \'U\' and name=\'' + policy.get_username() + '\''
|
||||||
|
+ 'and policy_id = ' + str(policy.get_policy_id()))
|
||||||
|
for profile in policy.get_user_profiles():
|
||||||
|
plugin = profile.get_plugin()
|
||||||
|
|
||||||
profile_args = [str(ahenk_policy_id), str(profile.get_create_date()),
|
plugin_args = [str(plugin.get_active()), str(plugin.get_create_date()), str(plugin.get_deleted()),
|
||||||
str(profile.get_modify_date()),
|
str(plugin.get_description()), str(plugin.get_machine_oriented()),
|
||||||
str(profile.get_label()), str(profile.get_description()),
|
str(plugin.get_modify_date()), str(plugin.get_name()),
|
||||||
str(profile.get_overridable()), str(profile.get_active()),
|
str(plugin.get_policy_plugin()),
|
||||||
str(profile.get_deleted()),
|
str(plugin.get_user_oriented()), str(plugin.get_version()),
|
||||||
str(profile.get_profile_data()), plugin_id]
|
str(plugin.get_task_plugin()), str(plugin.get_x_based())]
|
||||||
self.db_service.update('profile', profile_columns, profile_args)
|
plugin_id = self.db_service.update('plugin', plugin_columns, plugin_args)
|
||||||
|
|
||||||
elif ahenk_policy_ver:
|
profile_args = [str(user_policy_id), str(profile.get_create_date()), str(profile.get_modify_date()),
|
||||||
self.logger.debug('Already there is ahenk policy. Command Execution Id is updating')
|
str(profile.get_label()), str(profile.get_description()),
|
||||||
self.db_service.update('policy', ['execution_id'], [policy.get_agent_execution_id()], 'type = \'A\'')
|
str(profile.get_overridable()), str(profile.get_active()),
|
||||||
else:
|
str(profile.get_deleted()),
|
||||||
self.logger.debug('There is no any Ahenk policy.')
|
str(profile.get_profile_data()), policy.get_policy_id(), plugin_id]
|
||||||
|
self.db_service.update('profile', profile_columns, profile_args)
|
||||||
|
|
||||||
if policy.get_user_policy_version() != user_policy_version:
|
elif policy.get_user_policy_version() != user_policy_version:
|
||||||
user_policy_id = self.db_service.select_one_result('policy', 'id',
|
# policy is in db but policy version is updated
|
||||||
'type = \'U\' and name=\'' + policy.get_username() + '\'')
|
# delete profiles and plugins of that policcy and then insert new profiles and plugins
|
||||||
if user_policy_id is not None:
|
existing_profile_list = self.db_service.select('profile',
|
||||||
# TODO remove profiles' plugins
|
['id', 'plugin', 'policy_id'],
|
||||||
self.db_service.delete('profile', 'id=' + str(user_policy_id))
|
' policy_id=\'' + str(policy.get_policy_id()) + '\'')
|
||||||
self.db_service.delete('plugin', 'id=' + str(user_policy_id))
|
self.db_service.update('policy', ['version', 'execution_id', 'expiration_date', 'assign_date'],
|
||||||
self.db_service.update('policy', ['version', 'execution_id', 'expiration_date'],
|
[str(policy.get_user_policy_version()), policy.user_execution_id,
|
||||||
[str(policy.get_user_policy_version()), policy.user_execution_id,
|
str(policy.user_expiration_date), str(policy.assign_date)],
|
||||||
str(policy.user_expiration_date)],
|
'type=\'U\' and name=\'' + policy.get_username() + '\'' +
|
||||||
'type=\'U\' and name=\'' + policy.get_username() + '\'')
|
' and policy_id=\'' + str(policy.get_policy_id()) + '\'')
|
||||||
else:
|
user_policy_id = self.db_service.select_one_result('policy', 'id',
|
||||||
self.db_service.update('policy', ['type', 'version', 'name', 'execution_id', 'expiration_date'],
|
'type = \'U\' and name=\'' + policy.get_username() + '\'' +
|
||||||
['U', str(policy.get_user_policy_version()), policy.get_username(),
|
' and policy_id=\'' + str(policy.get_policy_id()) + '\'')
|
||||||
policy.get_user_execution_id(), policy.user_expiration_date])
|
|
||||||
user_policy_id = self.db_service.select_one_result('policy', 'id',
|
|
||||||
'type = \'U\' and name=\'' + policy.get_username() + '\'')
|
|
||||||
|
|
||||||
for profile in policy.get_user_profiles():
|
# update all profiles
|
||||||
plugin = profile.get_plugin()
|
for profile in existing_profile_list:
|
||||||
|
self.db_service.delete('profile', 'id=' + str(profile[0]))
|
||||||
|
self.db_service.delete('plugin', 'id=' + str(profile[1]))
|
||||||
|
|
||||||
plugin_args = [str(plugin.get_active()), str(plugin.get_create_date()), str(plugin.get_deleted()),
|
# add new profile and policies
|
||||||
str(plugin.get_description()), str(plugin.get_machine_oriented()),
|
for profile in policy.get_user_profiles():
|
||||||
str(plugin.get_modify_date()), str(plugin.get_name()),
|
plugin = profile.get_plugin()
|
||||||
str(plugin.get_policy_plugin()),
|
|
||||||
str(plugin.get_user_oriented()), str(plugin.get_version()),
|
|
||||||
str(plugin.get_task_plugin()), str(plugin.get_x_based())]
|
|
||||||
plugin_id = self.db_service.update('plugin', plugin_columns, plugin_args)
|
|
||||||
|
|
||||||
profile_args = [str(user_policy_id), str(profile.get_create_date()), str(profile.get_modify_date()),
|
plugin_args = [str(plugin.get_active()), str(plugin.get_create_date()), str(plugin.get_deleted()),
|
||||||
str(profile.get_label()), str(profile.get_description()),
|
str(plugin.get_description()), str(plugin.get_machine_oriented()),
|
||||||
str(profile.get_overridable()), str(profile.get_active()),
|
str(plugin.get_modify_date()), str(plugin.get_name()),
|
||||||
str(profile.get_deleted()),
|
str(plugin.get_policy_plugin()),
|
||||||
str(profile.get_profile_data()), plugin_id]
|
str(plugin.get_user_oriented()), str(plugin.get_version()),
|
||||||
self.db_service.update('profile', profile_columns, profile_args)
|
str(plugin.get_task_plugin()), str(plugin.get_x_based())]
|
||||||
|
plugin_id = self.db_service.update('plugin', plugin_columns, plugin_args)
|
||||||
|
|
||||||
elif user_policy_version:
|
profile_args = [str(user_policy_id), str(profile.get_create_date()), str(profile.get_modify_date()),
|
||||||
self.logger.debug('Already there is user policy. . Command Execution Id is updating')
|
str(profile.get_label()), str(profile.get_description()),
|
||||||
self.db_service.update('policy', ['execution_id'], [policy.get_user_execution_id()], 'type = \'U\'')
|
str(profile.get_overridable()), str(profile.get_active()),
|
||||||
else:
|
str(profile.get_deleted()),
|
||||||
self.logger.debug('There is no any user policy')
|
str(profile.get_profile_data()), policy.get_policy_id(), plugin_id]
|
||||||
|
self.db_service.update('profile', profile_columns, profile_args)
|
||||||
|
else:
|
||||||
|
existing_policy = self.db_service.select('policy', ['id', 'assign_date'],
|
||||||
|
'type = \'U\' and name = \'' + policy.get_username() + '\'' +
|
||||||
|
'and policy_id = ' + str(policy.get_policy_id()))
|
||||||
|
|
||||||
policy = self.get_active_policies(policy.get_username())
|
self.db_service.update('policy', ['assign_date'], [str(policy.get_assign_date())]
|
||||||
|
, 'type = \'U\' and name = \'' + policy.get_username() + '\'' +
|
||||||
|
'and policy_id = ' + str(policy.get_policy_id()))
|
||||||
|
|
||||||
|
|
||||||
|
policy_list = self.get_active_policies(j['username'])
|
||||||
# TODO check is null
|
# TODO check is null
|
||||||
self.task_manager.addPolicy(policy)
|
for i in range(len(policy_list)):
|
||||||
|
self.task_manager.addPolicy(policy_list[i])
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.logger.error('A problem occurred while executing policy. Erroe Message: {0}:'.format(str(e)))
|
self.logger.error('A problem occurred while executing policy. Error Message: {0}:'.format(str(e)))
|
||||||
|
|
||||||
def check_expiration(self, expiration):
|
def check_expiration(self, expiration):
|
||||||
current_timestamp = int(time.time()) * 1000
|
current_timestamp = int(time.time()) * 1000
|
||||||
|
@ -329,8 +348,8 @@ class ExecutionManager(object):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# TODO vt den gecerli son tarihi olani cek
|
# TODO vt den gecerli son tarihi olani cek
|
||||||
user_policy = self.db_service.select('policy', ['id', 'version', 'name', 'expiration_date'],
|
user_policy_list = self.db_service.select('policy', ['id', 'version', 'name', 'policy_id', 'expiration_date'],
|
||||||
' type=\'U\' and name=\'' + username + '\'')
|
' type=\'U\' and name=\'' + username + '\' order by assign_date asc')
|
||||||
ahenk_policy = self.db_service.select('policy', ['id', 'version', 'expiration_date'], ' type=\'A\' ')
|
ahenk_policy = self.db_service.select('policy', ['id', 'version', 'expiration_date'], ' type=\'A\' ')
|
||||||
|
|
||||||
plugin_columns = ['id', 'active', 'create_date', 'deleted', 'description', 'machine_oriented',
|
plugin_columns = ['id', 'active', 'create_date', 'deleted', 'description', 'machine_oriented',
|
||||||
|
@ -339,52 +358,34 @@ class ExecutionManager(object):
|
||||||
profile_columns = ['id', 'create_date', 'label', 'description', 'overridable', 'active', 'deleted',
|
profile_columns = ['id', 'create_date', 'label', 'description', 'overridable', 'active', 'deleted',
|
||||||
'profile_data', 'modify_date', 'plugin']
|
'profile_data', 'modify_date', 'plugin']
|
||||||
|
|
||||||
policy = PolicyBean(username=username)
|
|
||||||
|
|
||||||
if len(user_policy) > 0 and self.check_expiration(user_policy[0][3]):
|
policy_list = []
|
||||||
user_policy_version = user_policy[0][0]
|
if len(user_policy_list) > 0:
|
||||||
policy.set_user_policy_version(user_policy_version)
|
for i in range(len(user_policy_list)):
|
||||||
|
policy = PolicyBean(username=username)
|
||||||
|
user_policy_version = user_policy_list[i][0]
|
||||||
|
policy_id = user_policy_list[i][3]
|
||||||
|
policy.set_user_policy_version(user_policy_version)
|
||||||
|
|
||||||
user_profiles = self.db_service.select('profile', profile_columns,
|
user_profiles = self.db_service.select('profile', profile_columns,
|
||||||
' id=' + str(user_policy_version) + ' ')
|
' id=' + str(user_policy_version) + ' ')
|
||||||
arr_profiles = []
|
arr_profiles = []
|
||||||
if len(user_profiles) > 0:
|
if len(user_profiles) > 0:
|
||||||
for profile in user_profiles:
|
for profile in user_profiles:
|
||||||
plu = self.db_service.select('plugin', plugin_columns, ' id=\'' + profile[9] + '\'')[0]
|
plu = self.db_service.select('plugin', plugin_columns, ' id=\'' + profile[9] + '\'')[0]
|
||||||
plugin = PluginBean(p_id=plu[0], active=plu[1], create_date=plu[2], deleted=plu[3],
|
plugin = PluginBean(p_id=plu[0], active=plu[1], create_date=plu[2], deleted=plu[3],
|
||||||
description=plu[4], machine_oriented=plu[5], modify_date=plu[6],
|
description=plu[4], machine_oriented=plu[5], modify_date=plu[6],
|
||||||
name=plu[7],
|
name=plu[7],
|
||||||
policy_plugin=plu[8], user_oriented=plu[9], version=plu[10],
|
policy_plugin=plu[8], user_oriented=plu[9], version=plu[10],
|
||||||
task_plugin=plu[11], x_based=plu[12])
|
task_plugin=plu[11], x_based=plu[12])
|
||||||
|
|
||||||
arr_profiles.append(
|
arr_profiles.append(
|
||||||
ProfileBean(profile[0], profile[1], profile[2], profile[3], profile[4], profile[5],
|
ProfileBean(profile[0], profile[1], profile[2], profile[3], profile[4], profile[5],
|
||||||
profile[6],
|
profile[6],
|
||||||
profile[7], profile[8], plugin, policy.get_username()))
|
profile[7], profile[8], user_policy_list[i][3], plugin, policy.get_username()))
|
||||||
policy.set_user_profiles(arr_profiles)
|
policy.set_user_profiles(arr_profiles)
|
||||||
|
policy_list.append(policy)
|
||||||
if len(ahenk_policy) > 0 and self.check_expiration(ahenk_policy[0][2]):
|
return policy_list
|
||||||
ahenk_policy_version = ahenk_policy[0][0]
|
|
||||||
policy.set_ahenk_policy_version(ahenk_policy_version)
|
|
||||||
ahenk_profiles = self.db_service.select('profile', profile_columns,
|
|
||||||
' id=' + str(ahenk_policy_version) + ' ')
|
|
||||||
arr_profiles = []
|
|
||||||
if len(ahenk_profiles) > 0:
|
|
||||||
for profile in ahenk_profiles:
|
|
||||||
plu = self.db_service.select('plugin', plugin_columns, ' id=\'' + profile[9] + '\'')[0]
|
|
||||||
plugin = PluginBean(p_id=plu[0], active=plu[1], create_date=plu[2], deleted=plu[3],
|
|
||||||
description=plu[4], machine_oriented=plu[5], modify_date=plu[6],
|
|
||||||
name=plu[7],
|
|
||||||
policy_plugin=plu[8], user_oriented=plu[9], version=plu[10],
|
|
||||||
task_plugin=plu[11], x_based=plu[12])
|
|
||||||
|
|
||||||
arr_profiles.append(
|
|
||||||
ProfileBean(profile[0], profile[1], profile[2], profile[3], profile[4], profile[5],
|
|
||||||
profile[6],
|
|
||||||
profile[7], profile[8], plugin, policy.get_username()))
|
|
||||||
policy.set_ahenk_profiles(arr_profiles)
|
|
||||||
|
|
||||||
return policy
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.logger.error('A problem occurred while getting active policies. Error Message : {0}'.format(str(e)))
|
self.logger.error('A problem occurred while getting active policies. Error Message : {0}'.format(str(e)))
|
||||||
|
|
||||||
|
@ -414,7 +415,7 @@ class ExecutionManager(object):
|
||||||
else:
|
else:
|
||||||
Util.show_message(user_name, display, "Ahenk Lider MYS sisteminden çıkarılmıştır.", "")
|
Util.show_message(user_name, display, "Ahenk Lider MYS sisteminden çıkarılmıştır.", "")
|
||||||
if Util.show_message(user_name, display, "Değişikliklerin etkili olması için sistem yeniden başlatılacaktır. Lütfen bekleyiniz...", "") :
|
if Util.show_message(user_name, display, "Değişikliklerin etkili olması için sistem yeniden başlatılacaktır. Lütfen bekleyiniz...", "") :
|
||||||
registration= Scope.get_instance().get_registration()
|
registration = Scope.get_instance().get_registration()
|
||||||
registration.purge_and_unregister()
|
registration.purge_and_unregister()
|
||||||
|
|
||||||
|
|
||||||
|
@ -494,6 +495,7 @@ class ExecutionManager(object):
|
||||||
username = json_data['username']
|
username = json_data['username']
|
||||||
ahenk_prof_json_arr = json_data['agentPolicyProfiles']
|
ahenk_prof_json_arr = json_data['agentPolicyProfiles']
|
||||||
user_prof_json_arr = json_data['userPolicyProfiles']
|
user_prof_json_arr = json_data['userPolicyProfiles']
|
||||||
|
policy_id = json_data['policyID']
|
||||||
|
|
||||||
ahenk_prof_arr = []
|
ahenk_prof_arr = []
|
||||||
user_prof_arr = []
|
user_prof_arr = []
|
||||||
|
@ -508,7 +510,7 @@ class ExecutionManager(object):
|
||||||
task_plugin=plu['taskPlugin'], x_based=plu['xBased'])
|
task_plugin=plu['taskPlugin'], x_based=plu['xBased'])
|
||||||
ahenk_prof_arr.append(
|
ahenk_prof_arr.append(
|
||||||
ProfileBean(prof['id'], prof['createDate'], prof['label'], prof['description'], prof['overridable'],
|
ProfileBean(prof['id'], prof['createDate'], prof['label'], prof['description'], prof['overridable'],
|
||||||
prof['active'], prof['deleted'], json.dumps(prof['profileData']), prof['modifyDate'],
|
prof['active'], prof['deleted'], json.dumps(prof['profileData']), prof['modifyDate'], policy_id,
|
||||||
plugin, username))
|
plugin, username))
|
||||||
|
|
||||||
if user_prof_json_arr is not None:
|
if user_prof_json_arr is not None:
|
||||||
|
@ -522,16 +524,19 @@ class ExecutionManager(object):
|
||||||
task_plugin=plu['taskPlugin'], x_based=plu['xBased'])
|
task_plugin=plu['taskPlugin'], x_based=plu['xBased'])
|
||||||
user_prof_arr.append(
|
user_prof_arr.append(
|
||||||
ProfileBean(prof['id'], prof['createDate'], prof['label'], prof['description'], prof['overridable'],
|
ProfileBean(prof['id'], prof['createDate'], prof['label'], prof['description'], prof['overridable'],
|
||||||
prof['active'], prof['deleted'], json.dumps(prof['profileData']), prof['modifyDate'],
|
prof['active'], prof['deleted'], json.dumps(prof['profileData']), prof['modifyDate'], policy_id,
|
||||||
plugin, username))
|
plugin, username))
|
||||||
|
|
||||||
return PolicyBean(ahenk_policy_version=json_data['agentPolicyVersion'],
|
return PolicyBean(policy_id=json_data['policyID'],
|
||||||
|
ahenk_policy_version=json_data['agentPolicyVersion'],
|
||||||
user_policy_version=json_data['userPolicyVersion'], ahenk_profiles=ahenk_prof_arr,
|
user_policy_version=json_data['userPolicyVersion'], ahenk_profiles=ahenk_prof_arr,
|
||||||
user_profiles=user_prof_arr, timestamp=json_data['timestamp'], username=json_data['username'],
|
user_profiles=user_prof_arr, timestamp=json_data['timestamp'], username=json_data['username'],
|
||||||
agent_execution_id=json_data['agentCommandExecutionId'],
|
agent_execution_id=json_data['agentCommandExecutionId'],
|
||||||
user_execution_id=json_data['userCommandExecutionId'],
|
user_execution_id=json_data['userCommandExecutionId'],
|
||||||
agent_expiration_date=json_data['agentPolicyExpirationDate'],
|
agent_expiration_date=json_data['agentPolicyExpirationDate'],
|
||||||
user_expiration_date=json_data['userPolicyExpirationDate'])
|
user_expiration_date=json_data['userPolicyExpirationDate'],
|
||||||
|
is_deleted=json_data['isDeleted'],
|
||||||
|
assign_date=json_data['assignDate'])
|
||||||
|
|
||||||
def login_response(self, msg):
|
def login_response(self, msg):
|
||||||
jData = json.loads(msg)
|
jData = json.loads(msg)
|
||||||
|
|
|
@ -105,6 +105,15 @@ class Messaging(object):
|
||||||
'type = \'U\' and name = \'' + username + '\'')
|
'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\'')
|
||||||
|
|
||||||
|
user_policy_list = self.db_service.select('policy', ['id', 'version', 'name', 'policy_id', 'assign_date'],
|
||||||
|
' type=\'U\' and name=\'' + username + '\'')
|
||||||
|
# to add policy_id and policy_version
|
||||||
|
user_policy_hash_list = dict()
|
||||||
|
if len(user_policy_list) > 0:
|
||||||
|
for i in range(len(user_policy_list)):
|
||||||
|
user_policy_hash_list[str(user_policy_list[i][3])] = [user_policy_list[i][1], user_policy_list[i][4]]
|
||||||
|
data['policyList'] = user_policy_hash_list
|
||||||
|
|
||||||
data['userPolicyVersion'] = user_policy_number
|
data['userPolicyVersion'] = user_policy_number
|
||||||
data['agentPolicyVersion'] = machine_policy_number
|
data['agentPolicyVersion'] = machine_policy_number
|
||||||
|
|
||||||
|
|
|
@ -116,7 +116,6 @@ class Messenger(ClientXMPP):
|
||||||
self.logger.info("---------->Received message: {}".format(str(parameter_map)))
|
self.logger.info("---------->Received message: {}".format(str(parameter_map)))
|
||||||
else:
|
else:
|
||||||
self.logger.info('---------->Received message: {0}'.format(str(msg['body'])))
|
self.logger.info('---------->Received message: {0}'.format(str(msg['body'])))
|
||||||
|
|
||||||
self.event_manger.fireEvent(message_type, str(msg['body']))
|
self.event_manger.fireEvent(message_type, str(msg['body']))
|
||||||
self.logger.debug('Fired event is: {0}'.format(message_type))
|
self.logger.debug('Fired event is: {0}'.format(message_type))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|
|
@ -6,9 +6,10 @@
|
||||||
class PolicyBean(object):
|
class PolicyBean(object):
|
||||||
"""docstring for PolicyBean"""
|
"""docstring for PolicyBean"""
|
||||||
|
|
||||||
def __init__(self, ahenk_policy_version=None, user_policy_version=None, ahenk_profiles=None, user_profiles=None,
|
def __init__(self, policy_id=None, ahenk_policy_version=None, user_policy_version=None, ahenk_profiles=None, user_profiles=None,
|
||||||
timestamp=None, username=None, agent_execution_id=None, user_execution_id=None,
|
timestamp=None, username=None, agent_execution_id=None, user_execution_id=None,
|
||||||
agent_expiration_date=None, user_expiration_date=None):
|
agent_expiration_date=None, user_expiration_date=None, is_deleted=None, assign_date=None):
|
||||||
|
self.policy_id = policy_id
|
||||||
self.ahenk_policy_version = ahenk_policy_version
|
self.ahenk_policy_version = ahenk_policy_version
|
||||||
self.user_policy_version = user_policy_version
|
self.user_policy_version = user_policy_version
|
||||||
self.ahenk_profiles = ahenk_profiles
|
self.ahenk_profiles = ahenk_profiles
|
||||||
|
@ -19,6 +20,14 @@ class PolicyBean(object):
|
||||||
self.user_execution_id = user_execution_id
|
self.user_execution_id = user_execution_id
|
||||||
self.agent_expiration_date = agent_expiration_date
|
self.agent_expiration_date = agent_expiration_date
|
||||||
self.user_expiration_date = user_expiration_date
|
self.user_expiration_date = user_expiration_date
|
||||||
|
self.is_deleted = is_deleted
|
||||||
|
self.assign_date = assign_date
|
||||||
|
|
||||||
|
def get_policy_id(self):
|
||||||
|
return self.policy_id
|
||||||
|
|
||||||
|
def set_policy_id(self, policy_id):
|
||||||
|
self.policy_id = policy_id
|
||||||
|
|
||||||
def get_ahenk_policy_version(self):
|
def get_ahenk_policy_version(self):
|
||||||
return self.ahenk_policy_version
|
return self.ahenk_policy_version
|
||||||
|
@ -67,3 +76,15 @@ class PolicyBean(object):
|
||||||
|
|
||||||
def get_user_execution_id(self):
|
def get_user_execution_id(self):
|
||||||
return self.user_execution_id
|
return self.user_execution_id
|
||||||
|
|
||||||
|
def set_is_deleted(self, is_deleted):
|
||||||
|
self.is_deleted = is_deleted
|
||||||
|
|
||||||
|
def get_is_deleted(self):
|
||||||
|
return self.is_deleted
|
||||||
|
|
||||||
|
def set_assign_date(self, assign_date):
|
||||||
|
self.assign_date = assign_date
|
||||||
|
|
||||||
|
def get_assign_date(self):
|
||||||
|
return self.assign_date
|
|
@ -8,8 +8,7 @@ from base.model.plugin_bean import PluginBean
|
||||||
|
|
||||||
class ProfileBean(object):
|
class ProfileBean(object):
|
||||||
"""docstring for Profile"""
|
"""docstring for Profile"""
|
||||||
|
def __init__(self, p_id=None, create_date=None, label=None, description=None, overridable=None, active=None, deleted=None, profile_data=None, modify_date=None, policy_id=None, plugin=None, username=None):
|
||||||
def __init__(self, p_id=None, create_date=None, label=None, description=None, overridable=None, active=None, deleted=None, profile_data=None, modify_date=None, plugin=None, username=None):
|
|
||||||
self.id = p_id
|
self.id = p_id
|
||||||
self.create_date = create_date
|
self.create_date = create_date
|
||||||
self.modify_date = modify_date
|
self.modify_date = modify_date
|
||||||
|
@ -19,6 +18,7 @@ class ProfileBean(object):
|
||||||
self.active = active
|
self.active = active
|
||||||
self.deleted = deleted
|
self.deleted = deleted
|
||||||
self.profile_data = profile_data
|
self.profile_data = profile_data
|
||||||
|
self.policy_id = policy_id
|
||||||
self.plugin = plugin
|
self.plugin = plugin
|
||||||
self.username = username
|
self.username = username
|
||||||
|
|
||||||
|
@ -47,7 +47,7 @@ class ProfileBean(object):
|
||||||
self.label = label
|
self.label = label
|
||||||
|
|
||||||
def get_description(self):
|
def get_description(self):
|
||||||
return self.modify_date
|
return self.description
|
||||||
|
|
||||||
def set_description(self, description):
|
def set_description(self, description):
|
||||||
self.description = description
|
self.description = description
|
||||||
|
@ -76,6 +76,12 @@ class ProfileBean(object):
|
||||||
def set_profile_data(self, profile_data):
|
def set_profile_data(self, profile_data):
|
||||||
self.profile_data = profile_data
|
self.profile_data = profile_data
|
||||||
|
|
||||||
|
def get_policy_id(self):
|
||||||
|
return self.policy_id
|
||||||
|
|
||||||
|
def set_policy_id(self, policy_id):
|
||||||
|
self.policy_id = policy_id
|
||||||
|
|
||||||
def get_plugin(self):
|
def get_plugin(self):
|
||||||
return self.plugin
|
return self.plugin
|
||||||
|
|
||||||
|
|
|
@ -202,7 +202,7 @@ class PluginManager(object):
|
||||||
for usr_profile in user_profiles:
|
for usr_profile in user_profiles:
|
||||||
if usr_profile.plugin.name == agent_profile.plugin.name:
|
if usr_profile.plugin.name == agent_profile.plugin.name:
|
||||||
same_plugin_profile = usr_profile
|
same_plugin_profile = usr_profile
|
||||||
|
policy.get_user_policy_version()
|
||||||
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(
|
||||||
|
|
Loading…
Reference in a new issue