diff --git a/defaults/main.yml b/defaults/main.yml index e27e3c6..b3cb288 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -274,7 +274,7 @@ mariadb_mysql_users: [] galera_enable_galera_monitoring_script: false # Define galera monitoring script path & name -galera_monitor_script_name: "galeranotify.py" +galera_monitor_script_name: "galeranotify.py{{ ansible_python.version.major|int }}" galera_monitor_script_path: "/etc/mysql" # Defines the which node should be considered the first in the cluster diff --git a/templates/etc/mysql/galeranotify.py.j2 b/templates/etc/mysql/galeranotify.py2.j2 similarity index 100% rename from templates/etc/mysql/galeranotify.py.j2 rename to templates/etc/mysql/galeranotify.py2.j2 diff --git a/templates/etc/mysql/galeranotify.py3.j2 b/templates/etc/mysql/galeranotify.py3.j2 new file mode 100644 index 0000000..823b04d --- /dev/null +++ b/templates/etc/mysql/galeranotify.py3.j2 @@ -0,0 +1,201 @@ +#!/usr/bin/python3 +# +# Script to send email notifications when a change in Galera cluster membership +# occurs. +# +# Complies with http://www.codership.com/wiki/doku.php?id=notification_command +# +# Author: Gabe Guillen +# Version: 1.5 +# Release: 3/5/2015 +# Use at your own risk. No warranties expressed or implied. +# + +# {{ ansible_managed }} + +import os +import sys +import getopt + +import smtplib + +try: from email.mime.text import MIMEText +except ImportError: + # Python 2.4 (CentOS 5.x) + from email.MIMEText import MIMEText + +import socket +import email.utils + +# Change this to some value if you don't want your server hostname to show in +# the notification emails +THIS_SERVER = socket.gethostname() + +# Server hostname or IP address +SMTP_SERVER = '{{ galera_notify_smtp_server }}' +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 +SMTP_USERNAME = '{{ galera_notify_smtp_username }}' +SMTP_PASSWORD = '{{ galera_notify_smtp_password }}' + +# Takes a single sender +MAIL_FROM = '{{ galera_notify_mail_from }}' +# Takes a list of recipients +# Need Date in Header for SMTP RFC Compliance +DATE = email.utils.formatdate() +MAIL_TO = ['{{ galera_notify_mail_to }}'] + +# Edit below at your own risk +################################################################################ +def main(argv): + str_status = '' + str_uuid = '' + str_primary = '' + str_members = '' + str_index = '' + message = '' + + usage = "Usage: " + os.path.basename(sys.argv[0]) + " --status " + usage += " --uuid --primary --members 1): + message += "s" + + message += ":\n\n" + + if(self._status): + message += "Status of this node: " + self._status + "\n\n" + + if(self._uuid): + message += "Cluster state UUID: " + self._uuid + "\n\n" + + if(self._primary): + message += "Current cluster component is primary: " + self._primary + "\n\n" + + if(self._members): + message += "Current members of the component:\n" + + if(self._index): + for i in range(len(self._members)): + if(i == int(self._index)): + message += "-> " + else: + message += "-- " + + message += self._members[i] + "\n" + else: + message += "\n".join((" " + str(x)) for x in self._members) + + message += "\n" + + if(self._index): + message += "Index of this node in the member list: " + self._index + "\n" + + return message + +if __name__ == "__main__": + main(sys.argv[1:])