zoukankan      html  css  js  c++  java
  • get_slave_status.py

    #!/usr/bin/env python
    #-*- encoding: utf8 -*-

    import mysql.connector
    import get_mysql_conn_info
        
    """
    SHOW SLAVE STATUS命令输出内容
    """
    class GetSlaveResult:
        """
        getdbconfig 参数是一个列表,第一列是IP,第二列是账号,第三列是密码,第四列是端口号。
        """   
        def __init__(self,getdbconfig):       
            self.getdbconfig = getdbconfig
             
        """
        获取 SHOW SLAVE STATUS 输出结果
        """
        def get_slave_status(self):
            dbconfig = self.getdbconfig
            for i in range(int(len(dbconfig))):                           
                show_slave_status = "SHOW slave STATUS;"        
                cnn = mysql.connector.connect(host=dbconfig[i][0] ,user=dbconfig[i][1] ,password=dbconfig[i][2] ,port=dbconfig[i][3])
                cursor = cnn.cursor(dictionary=True)
                cursor.execute(show_slave_status)
                result_fet = cursor.fetchall()
                result = result_fet[0]
                result["checkmysql_host"] = dbconfig[i][0]
                result["checkmysql_user"] = dbconfig[i][1]
                result["checkmysql_port"] = int(dbconfig[i][3])
                return result        
                                                         
        """
        检查SHOW SLAVE STATUS状态
        """
        def check_slave_status(self):
            check_ture_false_slave_status = True
            result = self.get_slave_status()
            if result.get('Slave_IO_Running') == 'Yes' and result.get('Slave_SQL_Running') == 'Yes':
                pass
            else:
                check_ture_false_slave_status = False
            print  "主机名: %s , 端口号: %s , Slave_IO_Running 状态 = %s , Slave_SQL_Running 状态 = %s " %(str(result.get('checkmysql_host')),str(result.get('checkmysql_port')),str(result.get('Slave_IO_Running')),str(result.get('Slave_SQL_Running')))
     
        """
        获取Last_SQL_Error内容
        """
        def get_last_sql_error(self):
            check_ture_false_last_sql_error = True
            result = self.get_slave_status()     
            if result.get('Last_SQL_Error')== '':
                pass
            else:
                check_ture_false_last_sql_error = False
            print  "主机名: %s , 端口号: %s , Last_SQL_Error 内容 = %s " %(str(result.get('checkmysql_host')),str(result.get('checkmysql_port')),str(result.get('Last_SQL_Error')))
                    
    checkdbconfig = get_mysql_conn_info.GetConn('/data/lgj/dblist.xlsx').get_csv()

    print_result = GetSlaveResult(checkdbconfig)
    print_result.check_slave_status()
    print_result.get_last_sql_error()
     


  • 相关阅读:
    安装插件 YouCompleteMe 成功却无法自动补全C++的解决办法
    Ubuntu 16.04 使用 vim_plug 安装插件 YouCompleteMe 报错“ycmd server SHUT DOWN”
    POJ #1062 昂贵的聘礼 有限制的最短路 枚举+dijkstra求最短路
    POJ #3259 Wormholes 判负环 SPFA
    POJ #1860 Currency Exchange 最短路径算法 Bellman-ford SPFA 判断负环
    spfa 算法模板 可求带负权边的最短路 判断负环
    POJ #1042 Gone Fishing 贪心
    路人甲
    Perface
    1. Perface
  • 原文地址:https://www.cnblogs.com/liang545621/p/7616032.html
Copyright © 2011-2022 走看看