Skip to content

Commit

Permalink
Merge pull request #124 from jpylypiw/patch-1
Browse files Browse the repository at this point in the history
Enable STARTTLS Support for Galera Monitoring Script
  • Loading branch information
elcomtik authored May 31, 2022
2 parents 3f7bf00 + b48a408 commit f8acd4d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 2 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,8 @@ galera_notify_smtp_password: ""
galera_notify_smtp_port: 25
# Set to True if you need SMTP over SSL
galera_notify_smtp_ssl: False
# Set to True if you need SMTP over STARTTLS
galera_notify_smtp_starttls: False

# Defines if cacti monitoring should be enabled for mysql - If used. May remove later.
galera_enable_cacti_monitoring: false
Expand Down
10 changes: 8 additions & 2 deletions templates/etc/mysql/galeranotify.py.j2
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ SMTP_PORT = {{ galera_notify_smtp_port }}
# Set to True if you need SMTP over SSL
SMTP_SSL = {{ galera_notify_smtp_ssl }}

# Set to True if you need SMTP over TLS
SMTP_STARTTLS = {{ galera_notify_smtp_starttls }}

# Set to True if you need to authenticate to your SMTP server
SMTP_AUTH = {{ galera_notify_smtp_auth }}
# Fill in authorization information here if True above
Expand Down Expand Up @@ -90,7 +93,7 @@ def main(argv):
message_obj.set_index(arg)
try:
send_notification(MAIL_FROM, MAIL_TO, 'Galera Notification: ' + THIS_SERVER, DATE,
str(message_obj), SMTP_SERVER, SMTP_PORT, SMTP_SSL, SMTP_AUTH,
str(message_obj), SMTP_SERVER, SMTP_PORT, SMTP_SSL, SMTP_STARTTLS, SMTP_AUTH,
SMTP_USERNAME, SMTP_PASSWORD)
except Exception, e:
print "Unable to send notification: %s" % e
Expand All @@ -102,7 +105,7 @@ def main(argv):
sys.exit(0)

def send_notification(from_email, to_email, subject, date, message, smtp_server,
smtp_port, use_ssl, use_auth, smtp_user, smtp_pass):
smtp_port, use_ssl, use_starttls, use_auth, smtp_user, smtp_pass):
msg = MIMEText(message)

msg['From'] = from_email
Expand All @@ -116,6 +119,9 @@ def send_notification(from_email, to_email, subject, date, message, smtp_server,
else:
mailer = smtplib.SMTP(smtp_server, smtp_port)

if(use_starttls):
mailer.starttls()

if(use_auth):
mailer.login(smtp_user, smtp_pass)

Expand Down

0 comments on commit f8acd4d

Please sign in to comment.