From f4dfee230652941e44868a59dc37f3d76edfffab Mon Sep 17 00:00:00 2001 From: PCoder Date: Wed, 13 Sep 2017 07:45:16 +0530 Subject: [PATCH] Send an email in case of a failed save_ssh_key task --- utils/tasks.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/utils/tasks.py b/utils/tasks.py index d9b40ac3..28c00c6e 100644 --- a/utils/tasks.py +++ b/utils/tasks.py @@ -1,4 +1,3 @@ -import os import tempfile import cdist @@ -68,6 +67,15 @@ def save_ssh_key(self, hosts, keys): except Exception as cdist_exception: logger.error(cdist_exception) return_value = False + email_data = { + 'subject': "celery save_ssh_key error - task id {0}".format( + self.request.id.__str__()), + 'from_email': settings.DCL_SUPPORT_FROM_ADDRESS, + 'to': ['info@ungleich.ch'], + 'body': "Task Id: {0}\nResult: {1}\nTraceback: {2}".format( + self.request.id.__str__(), False, str(cdist_exception)), + } + send_plain_email_task(email_data) return return_value