Example #1
0
def cabinet_num():
    '''
    生成机柜号,以及所有机器
    :return:
    返回总机器数量,总机柜数量,机柜机器数字典
    '''
    cabinets_dic = {}
    cabinet = []
    count = []
    data = mysql_query(
        '''select cabinet,count(*) cnt from host  where cabinet not like "O01" group by cabinet order by cabinet  ;''')
    all_count = mysql_query(''' select count(*) from host where cabinet not like "O01" ''')
    sum_cabinet = len(data)
    for x in data:
        cabinets_dic[(x[0])] = x[1]
    return sum_cabinet, all_count[0][0], cabinets_dic
Example #2
0
def get_host(condition='', cabinet=''):
    host_info = []
    if len(condition) == 0 and len(cabinet) == 0:
        host = mysql_query("select * from host order by hostid;")
    elif len(cabinet) != 0:
        host = mysql_query('''select * from host where cabinet like "%s%%"''' % (cabinet))
    else:
        host = mysql_query(
            '''select * from host WHERE hostname like "%s%%" or cabinet="%s" or lanip="%s" or service like "%s%%" or serial="%s" order by hostid;'''
            % (condition, condition, condition, condition, condition))
    if host == 0:
        return host_info

    for i in range(0, len(host)):
        hostid = host[i][0]
        hostname = host[i][1]
        lanip = host[i][2]
        interip = host[i][3]
        mem = host[i][5]
        if mem == 63:
            mem = 64
        sn = host[i][6]
        owner = host[i][10]
        service = host[i][11]
        region = host[i][12]
        cabinet = host[i][13]
        position = host[i][14]
        host_info.append({'hostid': '%s' % (hostid),
                          'hostname': '%s' % (hostname),
                          'lanip': '%s' % (lanip),
                          'interip': '%s' % (interip),
                          'mem': '%s' % (mem),
                          'sn': '%s' % (sn),
                          'service': '%s' % (service),
                          'region': '%s' % (region),
                          'cabinet': '%s' % (cabinet),
                          'postion': '%s' % (position),
                          'owner': '%s' % (owner), })
    print "请求db"
    return host_info
Example #3
0
def services_count():
    '''
    用于生成下拉
    用于生成service数目,比如mysql,redis,php总数
    :return
    返回service={‘service’:‘count’}
    '''
    dic_services = {}
    # 定义一个空的字典
    temp_info = mysql_query(''' select service,count(*) from host   where region="BTTE-zgc" group by service ;''')
    for x in temp_info:
        service = x[0]
        if len(service) == 0:
            service = "Off"
        dic_services[service] = x[1]
    return dic_services
Example #4
0
def cabinet_info(cabinet=''):
    '''
    用于区分机柜,eg:M列,M01,M02 ,M03
    :return:

    '''
    cabinet_dic = {}
    temp_info = []
    cabinet_dic = {}
    tem = re.compile("[0-9]")
    data = mysql_query(
        ''' select cabinet,count(*) from host where cabinet LIKE "%s%%" and region="BTTE-zgc" group by cabinet ;''' % (
            cabinet))
    for x in data:
        print x
        cabinet_dic[x[0]] = x[1]
    return cabinet_dic
Example #5
0
def service_info(service):
    '''
    用于服务分类,比如bsdb* bwdb*
    返回mysql总机器数,以及bsdb,bwdb对应机器数字典
    :return:
    '''
    tup = []
    dic = {}
    tem = re.compile("[0-9]+.XXXXXX.com")
    data = mysql_query(''' select hostname from host where service="%s" and region="BTTE-zgc";''' % (service))
    service_count = len(data)
    for d in data:
        pr = tem.sub("", d[0])
        tup.append(pr)
        dic[pr] = ''
    for key in dic:
        dic[key] = tup.count(key)
    return service_count, dic