#!/usr/bin/python # # 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 # Modified by: Josh Goldsmith # Version: 1.4 # Release: 5/14/2015 # Use at your own risk. No warranties expressed or implied. # import os import sys import getopt import smtplib import datetime try: from email.mime.text import MIMEText except ImportError: # Python 2.4 (CentOS 5.x) from email.MIMEText import MIMEText import socket # 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 = 'YOUR_SMTP_HERE' SMTP_PORT = 25 # Set to True if you need SMTP over SSL SMTP_SSL = False # Set to True if you need to authenticate to your SMTP server SMTP_AUTH = False # Fill in authorization information here if True above SMTP_USERNAME = '' SMTP_PASSWORD = '' # Takes a single sender MAIL_FROM = 'YOUR_EMAIL_HERE' # Takes a list of recipients MAIL_TO = ['SOME_OTHER_EMAIL_HERE'] # Need Date in Header for SMTP RFC Compliance DATE = datetime.datetime.now().strftime( "%d/%m/%Y %H:%M" ) # 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:])