本篇内容主要讲解“python2怎么监控多源复制状态并发邮件”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“python2怎么监控多源复制状态并发邮件”吧!
我们环境中用到了多源复制,因此写个查看状态的Python脚本,python为系统中自带的2.6.6,邮件内容为html格式,隔行变色,脚本如下:
# -*- coding: UTF-8 -*- import smtplib from email.mime.text import MIMEText from email.header import Header import datetime import MySQLdb date_end = datetime.date.today() html_part1 = """ <html> <head></head> <body><h3>Report of 10.10.100.10 multi source repl status {current_time}</h3> <table border=\"1\" bordercolor=\"#000000\" width=\"350\" style=\"width:85%;BORDER-COLLAPSE: collapse\" > <tbody> <tr bgColor=#0066CC> <th>Master_Host</th> <th>Slave_IO_Running</th> <th>Slave_SQL_Running</th> <th>Seconds_Behind_Master</th> <th>Channel_Name</th> </tr> """.format(current_time=date_end) html_part2 = """ </body> </html> """ td_bgcolor_num = 1 db = MySQLdb.connect("10.10.100.10","mysqldba","mysql-dba-168" ) cursor = db.cursor() cursor.execute("show slave status") results = cursor.fetchall() with open('/tmp/slavesof10010.html',mode='w') as f: f.write(html_part1) for row in results: Master_Host = row[1] Slave_IO_Running = row[10] Slave_SQL_Running = row[11] Seconds_Behind_Master = row[32] Channel_Name = row[-2] if td_bgcolor_num%2==0: td_bgcolor='#F0F0F0' else: td_bgcolor='#FFFFCE' td_bgcolor_num += 1 pro = ''' <tr bgcolor="'''+td_bgcolor+'''" align=\"center\" > <td >'''+ row[1].encode('utf-8','ignore') + "</td>" + ''' <td >'''+ row[10].encode('utf-8','ignore') + "</td>" + ''' <td >'''+ row[11].encode('utf-8','ignore') + "</td>" + ''' <td >'''+ str(row[32]) + "</td>" + ''' <td >'''+ Channel_Name + '''</td> </tr> ''' f.write(pro) f.write(html_part2) db.close() mail_host="smtp.xxxx.com" sender = 'devops@xxxx.com' receivers = ['devops@xxxx.com','123456789@qq.com','126@126.com','163@163.com'] with open('/tmp/slavesof10010.html',mode='r') as f: html=f.read() message = MIMEText(html, 'html') message['From'] = Header("devops@xxxx.com") message['To'] = Header(";".join(v for v in receivers)) subject = 'multi-source-repl of 100.10汇总' message['Subject'] = Header(subject, 'utf-8') try: smtpObj = smtplib.SMTP() smtpObj.connect(mail_host, 25) # 25 为 SMTP 端口号 smtpObj.sendmail(sender, receivers, message.as_string()) print "邮件发送成功" except smtplib.SMTPException as e: print "Error: 无法发送邮件", print e
计划任务
00 09 * * * python /server/scripts/get_html_10010.py &> /dev/null
到此,相信大家对“python2怎么监控多源复制状态并发邮件”有了更深的了解,不妨来实际操作一番吧!这里是创新互联网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!
另外有需要云服务器可以了解下创新互联cdcxhl.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。
网站题目:python2怎么监控多源复制状态并发邮件-创新互联
网站路径:https://www.cdcxhl.com/article2/djdeic.html
成都网站建设公司_创新互联,为您提供网页设计公司、服务器托管、营销型网站建设、网站收录、品牌网站设计、网站建设
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联