Commit 18ecf579 authored by Kristian Feldsam's avatar Kristian Feldsam

Added email notifications on errors

Signed-off-by: Kristian Feldsam's avatarKristián Feldsam <feldsam@gmail.com>
parent 8ae347a5
......@@ -40,6 +40,9 @@ images = functions.filter_images(all_images, datastores, args)
from drivers import _3par
_3par.login()
# starting backup
functions.send_email('Backup started! Images count: %d' % len(images))
for image_key in images:
image = images[image_key]
datastore = datastores[image.DATASTORE_ID]
......@@ -78,6 +81,7 @@ for image_key in images:
if vmDiskId is None:
# error
print 'Can not found VM Disk ID for image %d:%s attached to VM %d:%s' % (image.ID, image.NAME, vmId, vm.NAME)
functions.send_email('Can not found VM Disk ID for image %d:%s attached to VM %d:%s' % (image.ID, image.NAME, vmId, vm.NAME))
continue
if args.verbose:
......@@ -93,6 +97,7 @@ for image_key in images:
_3par.backup_live(one, image, vm, vmDiskId, args.verbose)
except Exception as ex:
print ex
functions.send_email('Error backup image %d:%s: "%s"' % (image.ID, image.NAME, ex))
continue
# unlock VM
......@@ -110,6 +115,7 @@ for image_key in images:
_3par.backup(image, args.verbose)
except Exception as ex:
print ex
functions.send_email('Error backup image %d:%s: "%s"' % (image.ID, image.NAME, ex))
continue
# non-persistent
......@@ -121,6 +127,7 @@ for image_key in images:
_3par.backup(image, args.verbose)
except Exception as ex:
print ex
functions.send_email('Error backup image %d:%s: "%s"' % (image.ID, image.NAME, ex))
continue
# unlock image
......
......@@ -22,4 +22,8 @@ _3PAR = {
}
# export volumes to host - backup host name defined in 3PAR
EXPORT_HOST = 'backup.hostname'
\ No newline at end of file
EXPORT_HOST = 'backup.hostname'
# email settings, we use local email server localhost:25
EMAIL_SEND_FROM = 'backup@domain.tld'
EMAIL_SEND_TO = 'admin@domain.tld'
......@@ -4,6 +4,7 @@ import sys
import time
from hpe3parclient import client, exceptions
import config
import functions
base_path = os.path.abspath(os.path.dirname(sys.argv[0]))
cl = client.HPE3ParClient(config._3PAR['api'], False, config._3PAR['secure'], None, True)
......@@ -16,6 +17,7 @@ def login():
cl.login(config._3PAR['username'], config._3PAR['password'])
except exceptions.HTTPUnauthorized:
print "Login failed."
functions.send_email('Can not login to 3PAR!')
def logout():
......
import subprocess
import smtplib
import config
......@@ -132,4 +133,11 @@ def borgbackup_info():
try:
return subprocess.check_output('borg info %s' % (config.BACKUP_REPO), shell=True)
except subprocess.CalledProcessError as ex:
raise Exception('Can not issue borg info command on repo %s!' % (config.BACKUP_REPO), ex)
\ No newline at end of file
raise Exception('Can not issue borg info command on repo %s!' % (config.BACKUP_REPO), ex)
def send_email(log):
msg = 'Subject: %s\n\n%s' % ('Cloud Backup Information', log)
server = smtplib.SMTP("localhost", 25, )
server.sendmail(config.EMAIL_SEND_FROM, config.EMAIL_SEND_TO, msg)
server.quit()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment