Derive ad-hoc - inventory source notification templates

This commit is contained in:
Matthew Jones 2016-06-29 13:48:00 -04:00
parent fe64b0b478
commit 9bd05abcf3
2 changed files with 20 additions and 1 deletions

View File

@ -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

View File

@ -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'])