Ejemplo n.º 1
0
    def load_all_host_infos(self):
        if (self.__thread_pool == None):
            self.__thread_pool = threadpool.ThreadPool(
                settings.THREAD_POOL_SIZE)
        sql = "select * from mysql_web.host_infos;"
        for row in db_util.DBUtil().fetchall(settings.MySQL_Host, sql):
            host_info_temp = common.get_object(row)
            host_info_temp.master_host_id = 0
            host_info_temp.key = host_info_temp.host_id
            host_info_temp.is_slave = bool(host_info_temp.is_slave)
            host_info_temp.is_master = bool(host_info_temp.is_master)
            host_info_temp.user = custom_algorithm.decrypt(
                settings.MY_KEY, host_info_temp.user)
            host_info_temp.password = custom_algorithm.decrypt(
                settings.MY_KEY, host_info_temp.password)
            host_info_temp.ssh_password = custom_algorithm.decrypt(
                settings.MY_KEY, host_info_temp.ssh_password) if (
                    len(host_info_temp.ssh_password) > 0) else None

            host_id = host_info_temp.host_id
            self.__host_infos[host_info_temp.host_id] = host_info_temp
            if (host_info_temp.is_deleted == 1):
                self.remove_key(self.__tablespace, host_id)
                self.remove_key(self.__host_infos, host_id)
                self.remove_key(self.__repl_infos, host_id)
                self.remove_key(self.__status_infos, host_id)
                self.remove_key(self.__host_infos, host_id)
                self.remove_key(self.__innodb_infos, host_id)
                self.remove_key(self.__linux_infos, host_id)
                self.remove_key(self.__innodb_status_infos, host_id)
                self.remove_key(self.__analyze_infos, host_id)
            else:
                if (self.__tablespace.has_key(host_id) == False):
                    self.__tablespace[host_id] = BaseClass(host_info_temp)
                if (self.__repl_infos.has_key(host_id) == False):
                    self.__repl_infos[host_id] = BaseClass(host_info_temp)
                if (self.__linux_infos.has_key(host_id) == False):
                    self.__linux_infos[host_id] = BaseClass(host_info_temp)
                if (self.__status_infos.has_key(host_id) == False):
                    self.__status_infos[host_id] = BaseClass(host_info_temp)
                if (self.__innodb_infos.has_key(host_id) == False):
                    self.__innodb_infos[host_id] = self.init_innodb_info(
                        BaseClass(host_info_temp))
                if (self.__analyze_infos.has_key(host_id) == False):
                    self.__analyze_infos[host_id] = self.init_analyze_info(
                        BaseClass(None))
                if (self.__innodb_status_infos.has_key(host_id) == False):
                    self.__innodb_status_infos[host_id] = BaseClass(
                        host_info_temp)
                    self.__innodb_status_infos[
                        host_id].buffer_pool_infos = collections.OrderedDict()

        self.load_mysql_web_user_infos()
        self.check_mysql_server_version_and_branch()
        self.check_master_and_slave_relation()
        result = "load all host infos ok."
        print(result)
        return result
Ejemplo n.º 2
0
def get_host_info(obj):
    sql = "select ip, port, `user`, `password`, host_name from mysql_audit.mysql_hosts where host_id = {0}".format(
        obj.host_id)
    info = common_util.get_object(db_util.DBUtil().fetchone(
        settings.MySQL_HOST, sql))
    info.user = custom_algorithm.decrypt(settings.MY_KEY, info.user)
    return json.dumps(info, default=lambda o: o.__dict__)
Ejemplo n.º 3
0
def get_mysql_info(host_id):
    sql = "select host_id, host, port, user, password, remark, ssh_user, ssh_port, ssh_password from mysql_web.host_infos where host_id = {0};".format(
        host_id)
    result = common.get_object(db_util.DBUtil().fetchone(
        settings.MySQL_Host, sql))
    result.user = custom_algorithm.decrypt(settings.MY_KEY, result.user)
    return common.convert_obj_to_json_str(result)
Ejemplo n.º 4
0
 def load_mysql_host_infos(self):
     rows = db_util.DBUtil().fetchall(
         settings.MySQL_HOST,
         "select * from mysql_audit.mysql_hosts WHERE is_deleted = 0;")
     for row in rows:
         info = common_util.get_object(row)
         if (info.host_id not in self.__mysql_host_infos.keys()):
             info.host = info.ip
             info.key = info.host_id
             info.user = custom_algorithm.decrypt(settings.MY_KEY,
                                                  info.user)
             info.password = custom_algorithm.decrypt(
                 settings.MY_KEY, info.password)
             info.host_ip = info.host
             info.host_port = info.port
             info.host_user = info.user
             info.host_password = info.password
             info.is_alive = host_manager.test_connection_new(info)
             self.__mysql_host_infos[info.host_id] = info