Adds job results email notification
This commit is contained in:
Родитель
f629e4cbb3
Коммит
d85742c797
|
@ -22,3 +22,10 @@ verbose=True
|
|||
# Corresponding to jobworker.queue_pull_uri
|
||||
# queue_push_uri = tcp://*:4002
|
||||
|
||||
[smtp]
|
||||
|
||||
# host = localhost
|
||||
# auth_username = "SMTP authentication username"
|
||||
# auth_password = "SMTP authentication password"
|
||||
# email_from = your@email.com
|
||||
|
||||
|
|
|
@ -73,6 +73,7 @@ def new_job():
|
|||
data['job_name'] = request_data.get('job_name', 'default')
|
||||
data['job_args'] = request_data.get('job_args', [])
|
||||
data['return_url'] = request_data.get('return_url', None)
|
||||
data['results_email'] = request_data.get('results_email', None)
|
||||
data['job_id'] = job_id
|
||||
|
||||
enqueue_job(data)
|
||||
|
|
|
@ -24,6 +24,7 @@ import zmq
|
|||
|
||||
from oslo.config import cfg
|
||||
from jobrunner.openstack.common import log as logging
|
||||
from jobrunner.utils import smtp
|
||||
|
||||
opts = [
|
||||
cfg.ListOpt('jobs', default='', help='job_name:path comma separated values'),
|
||||
|
@ -79,7 +80,8 @@ def exec_job(data):
|
|||
LOG.debug('Job stderr:%s' % out)
|
||||
|
||||
return_url = data.get('return_url', None)
|
||||
if return_url:
|
||||
results_email = data.get('results_email', None)
|
||||
if return_url or results_email:
|
||||
return_data = {}
|
||||
return_data['job_id'] = data['job_id']
|
||||
return_data['job_return_code'] = returncode
|
||||
|
@ -88,7 +90,20 @@ def exec_job(data):
|
|||
if err:
|
||||
return_data['err'] = err
|
||||
|
||||
post_data(return_url, return_data)
|
||||
if return_url:
|
||||
try:
|
||||
post_data(return_url, return_data)
|
||||
except Exception, ex:
|
||||
LOG.error("HTTP job results call failed for URL: %s" % return_url)
|
||||
LOG.exception(ex)
|
||||
|
||||
if results_email:
|
||||
try:
|
||||
LOG.debug('Sending job results email to: %s' % results_email)
|
||||
smtp.send_email(None, results_email, None, str(return_data))
|
||||
except Exception, ex:
|
||||
LOG.error("Failed to send email to: %s" % results_email)
|
||||
LOG.exception(ex)
|
||||
|
||||
def get_messages():
|
||||
context = zmq.Context()
|
||||
|
|
|
@ -0,0 +1,58 @@
|
|||
# vim: tabstop=4 shiftwidth=4 softtabstop=4
|
||||
|
||||
# Copyright 2013 Cloudbase Solutions Srl
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import smtplib
|
||||
|
||||
from email.mime import text
|
||||
from oslo.config import cfg
|
||||
from jobrunner.openstack.common import log as logging
|
||||
|
||||
opts = [
|
||||
cfg.StrOpt('host', default='localhost', help='SMTP host'),
|
||||
cfg.StrOpt('auth_username', default='', help='SMTP authentication username'),
|
||||
cfg.StrOpt('auth_password', default='', help='SMTP authentication password'),
|
||||
cfg.StrOpt("auth_method", default='LOGIN PLAIN', help='SMTP authentication method'),
|
||||
cfg.StrOpt('email_from', default='Cloudbase Job Runner <jobrunner@change.me>', help='Email "from" field'),
|
||||
cfg.StrOpt('email_subject', default='[Cloudbase Job Runner] Job Status Update', help='Email subject'),
|
||||
]
|
||||
|
||||
CONF = cfg.CONF
|
||||
CONF.register_opts(opts, 'smtp')
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def send_email(from_email, to_email, subject, body):
|
||||
if not from_email:
|
||||
from_email = CONF.smtp.email_from
|
||||
if not subject:
|
||||
subject = CONF.smtp.email_subject
|
||||
|
||||
msg = text.MIMEText(body)
|
||||
msg['Subject'] = subject
|
||||
msg['From'] = from_email
|
||||
msg['To'] = to_email
|
||||
|
||||
s = smtplib.SMTP(CONF.smtp.host)
|
||||
s.ehlo()
|
||||
if CONF.smtp.auth_username:
|
||||
s.esmtp_features["auth"] = CONF.smtp.auth_method
|
||||
s.login(CONF.smtp.auth_username, CONF.smtp.auth_password)
|
||||
|
||||
s.sendmail(from_email, [to_email], msg.as_string())
|
||||
s.quit()
|
||||
|
|
@ -4,8 +4,14 @@
|
|||
set -e
|
||||
set -o pipefail
|
||||
|
||||
# Required to avoid some quantum client warning messages
|
||||
export EDITOR=vim
|
||||
|
||||
source ./keystone_vars
|
||||
|
||||
# Required to avoid some quantum client warning messages
|
||||
export EDITOR=vim
|
||||
|
||||
JOB_ID=$1
|
||||
IMAGE_URL=$2
|
||||
IMAGE_HASH=$3
|
||||
|
|
|
@ -7,6 +7,9 @@ set -o pipefail
|
|||
JOB_ID=$1
|
||||
VM_ID=$2
|
||||
|
||||
# Required to avoid some quantum client warning messages
|
||||
EDITOR=vim
|
||||
|
||||
source keystone_vars
|
||||
|
||||
echo "Getting the port id for VM: $VM_ID"
|
||||
|
|
|
@ -23,6 +23,7 @@ packages =
|
|||
jobrunner
|
||||
jobrunner.openstack
|
||||
jobrunner.openstack.common
|
||||
jobrunner.utils
|
||||
|
||||
[entry_points]
|
||||
console_scripts =
|
||||
|
|
Загрузка…
Ссылка в новой задаче