Created
February 25, 2015 21:32
-
-
Save tomgidden/64867af26f41e1d92424 to your computer and use it in GitHub Desktop.
Send wsrep / galera notifications for mysql clusters to a slack.com webhook
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# configure this in my.cnf on a Galera-based MySQL-alike server: | |
# wsrep_notify_cmd=/usr/local/sbin/wsrep_notify_slack | |
# by Tom Gidden <[email protected]> | |
url = 'https://hooks.slack.com/services/XXXXXXX/XXXXXXXX/XXXXXXXX' | |
import argparse | |
import urllib, urllib2 | |
import socket | |
import json | |
import re | |
if __name__ == '__main__': | |
parser = argparse.ArgumentParser() | |
parser.add_argument('-s', '--status') | |
# parser.add_argument('-u', '--uuid') | |
# parser.add_argument('-p', '--primary') | |
# parser.add_argument('-i', '--index') | |
# parser.add_argument('-m', '--members') | |
args = parser.parse_args() | |
name = socket.gethostname() | |
shortname = re.sub(r'\..*$', '', name) | |
text = "*"+shortname+"* status changed to *"+args.status+"*" | |
q = {} | |
q['username'] = "Database node "+shortname | |
colors = { | |
'Joined' : 'warning', | |
'Synced' : 'good', | |
'Undefined' : 'danger', | |
'Joiner' : 'warning', | |
'Donor' : 'warning' | |
} | |
a = {} | |
a["fallback"] = "Cluster change notification: "+text | |
a["text"] = text | |
a["mrkdwn_in"] = ["text", "fallback"] | |
if args.status in colors: | |
a['color'] = colors[args.status] | |
else: | |
a['color'] = 'danger' | |
q['attachments'] = [ a ] | |
enc = "payload="+json.dumps(q) | |
urllib2.urlopen(url, enc) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for this - very helpful.
This causes unknown parameter errors though; the
uuid
,primary
,index
andmembers
params should be included (uncommented) even if they're not used.