From 95dda3c4d8b1d4473b96613e18d1883bb1c8fb3f Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 26 Sep 2013 11:31:36 -0700 Subject: [PATCH] initial commit --- README.md | 29 ++++++++ galeranotify.pp | Bin 0 -> 940 bytes galeranotify.py | 186 ++++++++++++++++++++++++++++++++++++++++++++++++ galeranotify.te | 14 ++++ 4 files changed, 229 insertions(+) create mode 100644 galeranotify.pp create mode 100644 galeranotify.py create mode 100644 galeranotify.te diff --git a/README.md b/README.md index 28e96ed..ba734a4 100644 --- a/README.md +++ b/README.md @@ -2,3 +2,32 @@ galeranotify ============ Python E-Mail script for use with Galera wsrep_notify_cmd + +Why do I need / want this? +-------------------------- + +[Galera](http://codership.com/products/galera_replication) makes my life easier with near synchronous replication for MySQL. We have monitoring tools in place, but its nice to get updates in real time about how the cluster is operating. So I wrote galeranotify. + +I've been using this on our [Percona XtraDB Cluster](http://www.percona.com/software/percona-xtradb-cluster) for quite a while now with no issues. + +I hope someone finds it useful. + +Set up +------ + +1. Edit galeranotify.py to change the configuration options. They should be pretty straightforward. + +2. Place galeranotify.py in a common location and make sure you and your MySql user have execute permissions. + +3. Manually execute galeranotify.py with several of the options set (check usage) and check to make sure the script executes with no errors and that you receive the notification e-mail. + +4. Set 'wsrep_notify_cmd = ' in your my.cnf file. + +5. Restart MySql. + +SELinux +------- + +A SELinux policy (galeranotify.pp) is also included that allows the mysql user to connect to a standard remote smtp port (port 25). If you are using an alternate SMTP port (common with SSL), this rule will not work for you. + +This rule was generated on Centos 6.4 64-bit. It may or may not work for your particular setup. diff --git a/galeranotify.pp b/galeranotify.pp new file mode 100644 index 0000000000000000000000000000000000000000..941db22a8c7ee66bb14f05d9bdf25f65587233d6 GIT binary patch literal 940 zcmb`FT}s116oq4b5fyX^U4iHh?u&2ssS6ll8l{?KVlo8_Zb4kHPkO)FLx+kW=z%l$ z%(*|4();%D@_tYh1w41Y`u)t~{Caw`>{idySzN4|dg9ixld>ZxICb8aO+A!dOv}6V zq2I4AF3rO}^a3M*?nIEPK8&$?tP?|VyRxlA6}zsklB#)F9r5HEYI;dHSc!EiI{4br2{FCH+S>D~E;^bso Ww3L%9hi2)r#oBMvBIUk!e8VTD%RS`) literal 0 HcmV?d00001 diff --git a/galeranotify.py b/galeranotify.py new file mode 100644 index 0000000..19a2c6b --- /dev/null +++ b/galeranotify.py @@ -0,0 +1,186 @@ +#!/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 +# Version: 1.2 +# Release: 6/27/2013 +# Use at your own risk. No warranties expressed or implied. +# + +import os +import sys +import getopt + +import smtplib, email + +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'] + +# 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:]) diff --git a/galeranotify.te b/galeranotify.te new file mode 100644 index 0000000..bf033d8 --- /dev/null +++ b/galeranotify.te @@ -0,0 +1,14 @@ + +module galeranotify 1.0; + +require { + type smtp_port_t; + type mysqld_t; + class tcp_socket name_connect; +} + +#============= mysqld_t ============== + +#!!!! This avc can be allowed using one of the these booleans: +# mysql_connect_any, allow_ypbind +allow mysqld_t smtp_port_t:tcp_socket name_connect;