vi /usr/local/sunlight/wsrep_notify_cmd.sh

chown mysql:mysql  /usr/local/sunlight/wsrep_notify_cmd.sh

chmod 700 /usr/local/sunlight/wsrep_notify_cmd.sh

内容如下:

#!/usr/bin/python
# -*- coding: utf-8 -*-
# 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 <gguillen@gesa.com>
# Version: 1.3
# Release: 10/03/2013
# Use at your own risk. No warranties expressed or implied.
#

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
from email.utils import formataddr
# Change this to some value if you don't want your server hostname to show in
# the notification emails
SP_NAME="深圳广信"
THIS_SERVER = socket.gethostname()

# Server hostname or IP address
SMTP_SERVER = 'smtp.exmail.qq.com'
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 = 'SL-zabbix@sunlight-tech.com'
SMTP_PASSWORD = 'SLzAbbix@2016'

# Takes a single sender
MAIL_FROM = 'SL-zabbix@sunlight-tech.com'
# Takes a list of recipients
MAIL_TO = ['chao.dong@sunlight-tech.com']

MAIL_TITLE = "深圳广信 - 数据库集群-监控报警"
# 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 <status str>"
usage += " --uuid <state UUID> --primary <yes/no> --members <comma-seperated"
usage += " list of the component member UUIDs> --index <n>"

try:
opts, args = getopt.getopt(argv, "h", ["status=","uuid=",'primary=','members=','index='])
except getopt.GetoptError:
print usage
sys.exit(2)

if(len(opts) > 0):
message_obj = GaleraStatus(SP_NAME,THIS_SERVER)

for opt, arg in opts:
if opt == '-h':
print usage
sys.exit()
elif opt in ("--status"):
message_obj.set_status(arg)
elif opt in ("--uuid"):
message_obj.set_uuid(arg)
elif opt in ("--primary"):
message_obj.set_primary(arg)
elif opt in ("--members"):
message_obj.set_members(arg)
elif opt in ("--index"):
message_obj.set_index(arg)
try:
send_notice_email(message_obj)
except Exception, e:
print "Unable to send notification: %s" % e
sys.exit(1)
else:
print usage
sys.exit(2)

sys.exit(0)

def send_notice_email(message):
global SMTP_USERNAME,SMTP_PASSWORD,MAIL_FROM,MAIL_TO
msg = MIMEText(str(message), 'plain', 'utf-8')
msg['From'] = formataddr(["盛阳监控管理员",MAIL_FROM])
msg['To'] = formataddr(["Chao",MAIL_TO])
msg['Subject'] = "盛阳科技 - 数据库集群监控报警"
try:
server = smtplib.SMTP(SMTP_SERVER, SMTP_PORT)
server.login(SMTP_USERNAME,SMTP_PASSWORD)
server.sendmail(SMTP_USERNAME, MAIL_TO, msg.as_string())
print u"邮件发送成功!"
server.quit()
except smtplib.SMTPException:
print u"Error: 无法发送邮件"

class GaleraStatus:
def __init__(self, sp,server):
self._sp = sp
self._server = server
self._status = ""
self._uuid = ""
self._primary = ""
self._members = ""
self._index = ""
self._count = 0

def set_status(self, status):
self._status = status
self._count += 1

def set_uuid(self, uuid):
self._uuid = uuid
self._count += 1

def set_primary(self, primary):
self._primary = primary.capitalize()
self._count += 1

def set_members(self, members):
self._members = members.split(',')
self._count += 1

def set_index(self, index):
self._index = index
self._count += 1

def __str__(self):
message = "运营商名称: " + self._sp + "\n\n"
message += "节点Hostname: " + self._server + "\n\n"
message += "触发规则: " + "数据库集群-节点状态-发生变化"

if(self._count > 1):
message += "s"

message += "\n\n"
message += "--------------------------------------------------------\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"
message += "--------------------------------------------------------\n"
message += "\n"
message += "收到这封邮件,说明集群节点角色或状态发生变化,请登录服务器进行检查!"
return message

if __name__ == "__main__":
main(sys.argv[1:])

galera cluster,mysql配置wsrep_notify_cmd参数,增加邮件告警的更多相关文章

  1. Galera Cluster mysql+keepalived集群部署

    1.卸载mysql 查找本机安装的mysqlrpm -qa | grep -i mysql --nodeps --force rpm -ev MySQL-server-5.6.15-1.el6.x86 ...

  2. MariaDB Galera Cluster的配置测试

    参考的https://fykuan.hsnuer.net/blog/2015/01/23/debian-%E4%B8%8A%E5%AE%89%E8%A3%9D-mariadb-galera-clust ...

  3. zabbix配置自动发现,故障邮件告警

    对网段内的主机进行自动发现,自动加入主机组,自定加入template 创建动作时,类型这里选择discovery 然后将发现的主机加入host group和template: 动作针对的是discov ...

  4. linux下ELK搭建好之后配置sentinl插件,进行邮件告警

    ELK的环境搭建好之后,如何利用收集到的数据进行数据告警呢?在破解ELK之后,它本身提供一个监视器功能,配置偏向编写脚本.有一个更加方便的插件sentiel. 一.下载并安装sentinl插件 htt ...

  5. Galera Cluster——一种新型的高一致性MySQL集群架构

    原文链接:https://www.sohu.com/a/147032902_505779,最近被分配定位mysql的问题,学习下. 1. 何谓Galera Cluster 何谓Galera Clust ...

  6. 超详细,多图文使用galera cluster搭建mysql集群并介绍wsrep相关参数

    超详细,多图文使用galera cluster搭建mysql集群并介绍wsrep相关参数 介绍galera cluster原理的文章已经有一大堆了,百度几篇看一看就能有相关了解,这里就不赘述了.本文主 ...

  7. MySQL高可用(Galera Cluster)

    Galera Cluster简介 Galera Cluster是集成了Galera插件的MySQL集群,是一种新型的,数据不共享的,高度冗余的高可用方案,目前Galera Cluster有两个版本,分 ...

  8. 从 MySQL+MMM 到 MariaDB+Galera Cluster : 一个高可用性系统改造

    很少有事情比推出高可用性(HA)系统之后便经常看到的系统崩溃更糟糕.对于我们这个Rails运行机的团队来说,这个失效的HA系统是MySQL多主复制管理器(MMM). 我们已经找寻MMM的替代品有一段时 ...

  9. 【原】基于 HAproxy 1.6.3 Keeplived 在 Centos 7 中实现mysql mariadb galera cluster 集群分发读写 —— 上篇

    前言 有一段时间没有写blogs,乘着周末开始整理下haproxy + keeplived 实现 mysql mariadb galera cluster 集群访问环境的搭建工作. 本文集中讲hapr ...

随机推荐

  1. Python模块和包使用

    1.什么是模块 模块就是一个.py的文件 2.为什么要使用模块? 最开始的程序(没有任何组织)----> 函数------>类----->模块------>包  为了让程序的组 ...

  2. Python学习之路【第三篇】--集合

    语法结构: set1.issubset(set2)判断集合set1是否为set2的子集,返回布尔值. ? 1 2 3 4 5 6 s1 = {'Java', 'PHP', 'Python', 'C++ ...

  3. OpenSSH隐藏版本号教程

    1.查看当前OpenSSH版本号 sshd -v #sshd并没有-v选项,这并不是重点重点是这样能曝出版本号 2.查看sshd位置 which sshd 3.备份sshd cp /usr/sbin/ ...

  4. VLC添加水印

    Name: LibVLC control APIDescription: VLC media player external control libraryVersion: 2.1.3 参照:http ...

  5. echo * 打印当前目录列表

    所以在脚本中 类似 echo $a*  如果$a为空  则会打印 目录列表.

  6. MFC CDHtmlDialog 加载本地资源

    步骤:1.资源视图 项目右击选择资源添加,自定义添加新类型 如:JS(会增加JS文件夹)2. 选择1新建的文件夹右击 添加资源 导入 选择js文件引入3. 在资源文件Resource.h文件夹能找到资 ...

  7. 【内存泄漏】 C/C++内存泄漏及其检测工具

    对于一个c/c++程序员来说,内存泄漏是一个常见的也是令人头疼的问题.已经有许多技术被研究出来以应对这个问题,比如 Smart Pointer,Garbage Collection等.Smart Po ...

  8. FPGA复位的可靠性(转)

    FPGA复位的可靠性(同步复位和异步复位)  reference:http://www.eetop.cn/blog/html/17/743817-24442.html 一.特点: 同步复位:顾名思义, ...

  9. 一个简单的JSP程序示例

    <%@ page language="java" import="java.util.*" pageEncoding="utf-8"% ...

  10. easyui datagrid 首次不加载做法

    我们一般遇到首次不执行查询,只有你点击查询按钮才查询的功能 我使用easyui的datagird做法是这样的: onBeforeLoad: function (param) { var firstLo ...