本篇內(nèi)容主要講解“python2怎么監(jiān)控多源復(fù)制狀態(tài)并發(fā)郵件”,感興趣的朋友不妨來(lái)看看。本文介紹的方法操作簡(jiǎn)單快捷,實(shí)用性強(qiáng)。下面就讓小編來(lái)帶大家學(xué)習(xí)“python2怎么監(jiān)控多源復(fù)制狀態(tài)并發(fā)郵件”吧!
創(chuàng)新互聯(lián)公司是一家從事企業(yè)網(wǎng)站建設(shè)、網(wǎng)站設(shè)計(jì)制作、做網(wǎng)站、行業(yè)門戶網(wǎng)站建設(shè)、網(wǎng)頁(yè)設(shè)計(jì)制作的專業(yè)的建站公司,擁有經(jīng)驗(yàn)豐富的網(wǎng)站建設(shè)工程師和網(wǎng)頁(yè)設(shè)計(jì)人員,具備各種規(guī)模與類型網(wǎng)站建設(shè)的實(shí)力,在網(wǎng)站建設(shè)領(lǐng)域樹(shù)立了自己獨(dú)特的設(shè)計(jì)風(fēng)格。自公司成立以來(lái)曾獨(dú)立設(shè)計(jì)制作的站點(diǎn)超過(guò)千家。
我們環(huán)境中用到了多源復(fù)制,因此寫個(gè)查看狀態(tài)的Python腳本,python為系統(tǒng)中自帶的2.6.6,郵件內(nèi)容為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 = """
Report of 10.10.100.10 multi source repl status {current_time}
Master_Host |
Slave_IO_Running |
Slave_SQL_Running |
Seconds_Behind_Master |
Channel_Name |
""".format(current_time=date_end)
html_part2 = """
"""
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 = '''
'''+ row[1].encode('utf-8','ignore') + " | " + '''
'''+ row[10].encode('utf-8','ignore') + " | " + '''
'''+ row[11].encode('utf-8','ignore') + " | " + '''
'''+ str(row[32]) + " | " + '''
'''+ Channel_Name + ''' |
'''
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 端口號(hào)
smtpObj.sendmail(sender, receivers, message.as_string())
print "郵件發(fā)送成功"
except smtplib.SMTPException as e:
print "Error: 無(wú)法發(fā)送郵件",
print e計(jì)劃任務(wù)
00 09 * * * python /server/scripts/get_html_10010.py &> /dev/null
到此,相信大家對(duì)“python2怎么監(jiān)控多源復(fù)制狀態(tài)并發(fā)郵件”有了更深的了解,不妨來(lái)實(shí)際操作一番吧!這里是創(chuàng)新互聯(lián)網(wǎng)站,更多相關(guān)內(nèi)容可以進(jìn)入相關(guān)頻道進(jìn)行查詢,關(guān)注我們,繼續(xù)學(xué)習(xí)!
網(wǎng)站標(biāo)題:python2怎么監(jiān)控多源復(fù)制狀態(tài)并發(fā)郵件
標(biāo)題路徑:http://weahome.cn/article/joiece.html
-
在線咨詢
微信咨詢
電話咨詢
-
028-86922220(工作日)
18980820575(7×24)
-
提交需求
-
返回頂部