Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to monitor the status of multi-source replication and concurrent mail by python2

2025-03-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains "how to monitor the status of multi-source replication and concurrent mail by python2". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "how python2 monitors the status of multi-source replication and concurrent mail".

Multi-source replication is used in our environment, so write a Python script to check the status. Python is 2.6.6 included in the system. The content of the email is in html format, and the interlacing changes color. The script is as follows:

#-*-coding: UTF-8-*-import smtplibfrom email.mime.text import MIMETextfrom email.header import Headerimport datetimeimport MySQLdbdate_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 = 1db = 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'] 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 summary' message ['Subject'] = Header (subject,' utf-8') try: smtpObj = smtplib.SMTP () smtpObj.connect (mail_host, 25) # 25 is SMTP port number smtpObj.sendmail (sender, receivers, message.as_string () print" message sent successfully "except smtplib.SMTPException as e: print" Error: unable to send message ", print e

Schedule a task

00 09 * python / server/scripts/get_html_10010.py & > / dev/null here, I believe you have a better understanding of "how python2 monitors concurrent mail in the status of multi-source replication". You might as well do it in practice! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 250

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report