def query_instance_by_condition(sys_id=None,
                                 sys_name=None,
                                 ip=None,
                                 check_type=None,
                                 description=None):
     """
     query instance by condition
     :param description:
     :param sys_id:
     :param sys_name:
     :param ip:
     :param check_type:
     :return:
     """
     base_sql = QUERY_MONITOR_INSTANCE
     if sys_id is not None and len(sys_id) > 0:
         base_sql = base_sql + """and sys_id = '%s'""" % sys_id
     if sys_name is not None and len(sys_name) > 0:
         base_sql = base_sql + "and sys_name like '%" + sys_name + "%'"
     if ip is not None and len(ip) > 0:
         base_sql = base_sql + "and ip like '%" + ip + "%'"
     if check_type is not None and len(check_type) > 0:
         base_sql = base_sql + "and `type` like '%" + check_type + "%'"
     if description is not None and len(description) > 0:
         base_sql = base_sql + "and `description` like '%" + description + "%'"
     base_sql = base_sql + 'order by sys_name limit 200;'
     result = DB_POOL.select(sql=base_sql)
     return result
 def get_system_info_tree():
     """
     get system info tree
     :return:
     """
     system_info = DB_POOL.select(SELECT_SYSTEM_INFO)
     half_connection = []
     ping = []
     for sys in system_info:
         half_connection.append({
             'id': sys['id'],
             'name': sys['name'],
             'type': '半连接'
         })
         ping.append({'id': sys['id'], 'name': sys['name'], 'type': 'ping'})
     return_data = {
         'results': {
             'data': [{
                 'id': 1,
                 'name': '半连接',
                 'children': half_connection
             }, {
                 'id': 2,
                 'name': 'ping',
                 'children': ping
             }]
         }
     }
     return return_data
Esempio n. 3
0
 def query_warning_history_by_condition(sys_id=None, sys_name=None,
                                        ip=None, check_type=None):
     """
     query instance by condition
     :param sys_id:
     :param sys_name:
     :param ip:
     :param check_type:
     :return:
     """
     base_sql = SELECT_WARNING_HISTORY_BASE
     if sys_id is not None and len(sys_id) > 0:
         base_sql = base_sql + """and sys_id = '%s'""" % sys_id
     if sys_name is not None and len(sys_name) > 0:
         base_sql = base_sql + "and sys_name like '%" + sys_name + "%'"
     if ip is not None and len(ip) > 0:
         base_sql = base_sql + "and ip like '%" + ip + "%'"
     if check_type is not None and len(check_type) > 0:
         base_sql = base_sql + "and `check_type` like '%" + check_type + "%'"
     base_sql = base_sql + 'ORDER BY check_time DESC limit 200;'
     print(base_sql)
     result = DB_POOL.select(sql=base_sql)
     for res in result:
         res['check_time'] = str(res['check_time'])
         if res['check_type'] == 'half_connection':
             res['check_type'] = '半连接'
     return result
 def get_all_used_check_instances():
     """
     get all used check instances
     :return:
     """
     base_sql = QUERY_MONITOR_INSTANCE
     result = DB_POOL.select(sql=base_sql)
     return result
 def get_system_name_by_id(sys_id):
     """
     get system name by id
     :param sys_id:
     :return:
     """
     sql = SELECT_BASE_SYSTEM_INFO + """ and id ='%s'""" % sys_id
     sys_name = DB_POOL.select(sql)[0]['name']
     return sys_name
Esempio n. 6
0
 def get_ping_last_state(item):
     """
     get ping last state
     :param item:
     :return:
     """
     ip = item.ip
     sql = SELECT_WARNING_HISTORY_BASE + """ and 
     check_type = 'ping' and ip = '%s' order by check_time desc;""" % ip
     res = DB_POOL.select(sql)
     return res
Esempio n. 7
0
def gen_obj_mapping():
    """
    get obj mapping
    :return:
    """
    column_info = DB_POOL.select(GET_COLUMN_INFO)
    content = {}
    for info in column_info:
        table_name = info['TABLE_NAME']
        column_name = info['COLUMN_NAME']
        if table_name not in content.keys():
            content[table_name] = [column_name]
        else:
            content[table_name].append(column_name)
    gen_py_file(content)
 def query_sys_info(json_object):
     """
     query sys info
     :param json_object:
     :return:
     """
     sys_name, manager, job_number = json_object.get('name'), \
                                     json_object.get('manager'), \
                                     json_object.get('job_number')
     base_sql = QUERY_SYS_INFO
     if sys_name is not None and len(sys_name) > 0:
         base_sql = base_sql + "and name like '%" + sys_name + "%'"
     if manager is not None and len(manager) > 0:
         base_sql = base_sql + "and manager like '%" + manager + "%'"
     if job_number is not None and len(job_number) > 0:
         base_sql = base_sql + "and job_number like '%" + job_number + "%'"
     base_sql = base_sql + 'order by name limit 200;'
     result = DB_POOL.select(sql=base_sql)
     return result
Esempio n. 9
0
 def get_monitor_history_data(json_obj):
     """
     get monitor history data
     :param json_obj:
     :return:
     """
     ip = json_obj['ip']
     check_type = json_obj['check_type']
     port = 0
     if 'port' in json_obj:
         port = str(json_obj['port'])
     start_time = json_obj['start_time'].replace('T', ' ').split('.')[0]
     end_time = json_obj['end_time'].replace('T', ' ').split('.')[0]
     if check_type == 'half_connection':
         sql = QUERY_MONITOR_DETAIL_HALF_CONNECTION % (start_time, end_time, ip, port, check_type)
     else:
         sql = QUERY_MONITOR_DETAIL_PING % (start_time, end_time, ip, check_type)
     sql = sql + ' order by start_time asc'
     print(sql)
     res = DB_POOL.select(sql)
     filter_monitor_result = MonitorDetailService.__filter_monitor_detail(res)
     return filter_monitor_result
Esempio n. 10
0
 def get_tcp_last_state(item):
     ip = item.ip
     sql = SELECT_WARNING_HISTORY_BASE + """ and
         check_type = 'half_connection' and ip = '%s' order by check_time desc;""" % ip
     res = DB_POOL.select(sql)
     return res