def delete_system_info(json_obj):
     """
     insert or update instance
     :param json_obj:
     :return:
     """
     sql = DELETE_SYSTEM_INFO % (TypeChange.to_string(json_obj, 'id'))
     DB_POOL.execute_sql_str(sql)
     return {'is_success': True}
 def delete_instance(json_obj):
     """
     insert or update instance
     :param json_obj:
     :return:
     """
     sql = DELETE_MONITOR_INSTANCE % (TypeChange.to_string(json_obj, 'id'))
     DB_POOL.execute_sql_str(sql)
     return {'is_success': True}
 def __insert_system_info(json_obj):
     """
     insert monitor instance
     :param json_obj:
     :return:
     """
     sql = INSERT_SYSTEM_INFO % (
         get_uuid_str(),
         TypeChange.to_string(json_obj, 'name'),
         TypeChange.to_string(json_obj, 'manager'),
         TypeChange.to_string(json_obj, 'telephone'),
         TypeChange.to_string(json_obj, 'job_number'),
     )
     DB_POOL.execute_sql_str(sql)
 def __update_system_info(json_obj):
     """
     UPDATE MONITOR INSTANCE
     :param json_obj:
     :return:
     """
     sql = UPDATE_SYSTEM_INFO % (
         TypeChange.to_string(json_obj,
                              'id'), TypeChange.to_string(json_obj, 'name'),
         TypeChange.to_string(json_obj, 'manager'),
         TypeChange.to_string(json_obj, 'telephone'),
         TypeChange.to_string(
             json_obj, 'job_number'), TypeChange.to_string(json_obj, 'id'))
     DB_POOL.execute_sql_str(sql)
 def __insert_monitor_instance(json_obj):
     """
     insert monitor instance
     :param json_obj:
     `id`,`sys_id`,`sys_name`,`description`,`ip`,`port`,`type`,`interval`,`is_use`
     :return:
     """
     sql = INSERT_MONITOR_INSTANCE % (
         get_uuid_str(), TypeChange.to_string(json_obj, 'sys_id'),
         TypeChange.to_string(json_obj, 'sys_name'),
         TypeChange.to_string(
             json_obj, 'description'), TypeChange.to_string(
                 json_obj, 'ip'), TypeChange.to_string(json_obj, 'port'),
         TypeChange.to_string(
             json_obj, 'type'), TypeChange.to_string(json_obj, 'interval'),
         TypeChange.to_string(json_obj, 'is_use'))
     DB_POOL.execute_sql_str(sql)
 def __update_monitor_instance(json_obj):
     """
     UPDATE MONITOR INSTANCE
     :param json_obj:
     :return:
     """
     sys_name = SystemInfoService.get_system_name_by_id(json_obj['sys_id'])
     sql = UPDATE_MONITOR_INSTANCE % (
         TypeChange.to_string(json_obj, 'id'),
         TypeChange.to_string(json_obj, 'sys_id'), sys_name,
         TypeChange.to_string(
             json_obj, 'description'), TypeChange.to_string(
                 json_obj, 'ip'), TypeChange.to_int(json_obj, 'port'),
         TypeChange.to_string(
             json_obj, 'type'), TypeChange.to_int(json_obj, 'interval'),
         TypeChange.to_int(json_obj,
                           'is_use'), TypeChange.to_string(json_obj, 'id'))
     DB_POOL.execute_sql_str(sql)
Example #7
0
from common.utility.uuid_utility import get_uuid_str
from db.mysql_relevant.connection_pool.db_pool import DB_POOL
from db.mysql_relevant.sql_str.monitor_instance import INSERT_MONITOR_INSTANCE

sys_id = 'f6f7aa8239a24499962ee7f45a763bc5'
sys_name = '综合运营平台'
with open('1.csv', 'r', encoding='utf8') as f:
    reader = csv.reader(f)
    print(type(reader))
    for row in reader:
        description = str(row[0]).replace(' ', '')
        ip = row[1].replace(' ', '')
        ports = row[2].replace(' ', '')
        ports = str(ports).split('/')
        for port in ports:
            if len(port) < 2:
                continue
            sql = INSERT_MONITOR_INSTANCE % (get_uuid_str(),
                                             sys_id,
                                             sys_name,
                                             description,
                                             ip,
                                             str(port),
                                             '半连接',
                                             '60',
                                             '1')
            print(sql)
            DB_POOL.execute_sql_str(sql)
        print(row)