From 9bd05abcf3b842e2e9284761ba17fa86b4127ead Mon Sep 17 00:00:00 2001 From: Matthew Jones Date: Wed, 29 Jun 2016 13:48:00 -0400 Subject: [PATCH] Derive ad-hoc - inventory source notification templates --- awx/main/models/ad_hoc_commands.py | 19 +++++++++++++++++++ awx/main/tasks.py | 2 +- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/awx/main/models/ad_hoc_commands.py b/awx/main/models/ad_hoc_commands.py index 8694f56537..da9aaf740b 100644 --- a/awx/main/models/ad_hoc_commands.py +++ b/awx/main/models/ad_hoc_commands.py @@ -156,6 +156,25 @@ class AdHocCommand(UnifiedJob): h = hmac.new(settings.SECRET_KEY, self.created.isoformat()) return '%d-%s' % (self.pk, h.hexdigest()) + @property + def notification_templates(self): + all_inventory_sources = set() + for h in self.hosts.all(): + for invsrc in h.inventory_sources.all(): + all_inventory_sources.add(invsrc) + active_templates = dict(error=set(), + success=set(), + any=set()) + for invsrc in all_inventory_sources: + notifications_dict = invsrc.notification_templates + for notification_type in active_templates.keys(): + for templ in notifications_dict[notification_type]: + active_templates[notification_type].add(templ) + active_templates['error'] = list(active_templates['error']) + active_templates['any'] = list(active_templates['any']) + active_templates['success'] = list(active_templates['success']) + return active_templates + def get_passwords_needed_to_start(self): return self.passwords_needed_to_start diff --git a/awx/main/tasks.py b/awx/main/tasks.py index f174ffe37f..4419146db1 100644 --- a/awx/main/tasks.py +++ b/awx/main/tasks.py @@ -212,7 +212,7 @@ def handle_work_success(self, result, task_actual): elif task_actual['type'] == 'ad_hoc_command': instance = AdHocCommand.objects.get(id=task_actual['id']) instance_name = instance.module_name - notification_templates = [] # TODO: Ad-hoc commands need to notify someone + notification_templates = instance.notification_templates friendly_name = "AdHoc Command" elif task_actual['type'] == 'system_job': instance = SystemJob.objects.get(id=task_actual['id'])