示例#1
0
    def do_onefile(self, f, tarpath):
        if not os.path.exists(f):
            return

        if not re.match('.+[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+.+\.tar\.gz', tarpath):
            return

        match = re.search('[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+', tarpath)
        serverip = tarpath[match.start(): match.end()]

        namecache = {}
        dis_pre = []
        with open(f) as f:
            for line in f:
                if re.match('.+MONKK Disconnect state.+dbid.+', line):
                    res = re.split('[ ,=]', line)
#2013-11-27 11:47:50 MONKK Disconnect state=PrepareLeave,classid=5903,usrdbid=0,userid=0,toaddr=192.168.11.45:14456:3
#      0        1      2        3       4         5          6     7     8    9   10   11   12         13
                    if '' in res:
                        logging.error('none data: %s' % line)
                        continue
                    classid = res[7] if '.' not in res[7] else res[7].split('.')[0]
                    usrip = res[13].split(':')[0]
                    dbid = res[9]
                    usrid = res[11]
                    if dbid == '0':
                        continue

                    if dbid in namecache:
                        usrname = namecache[dbid]
                    else:
                        usrname = util.get_usrname(dbid)
                        namecache[dbid] = usrname
                        time.sleep(2)
                    recordtime = '%s %s' % (res[0], res[1])
                    state = res[5]

                    if state == 'PrepareLeave':
                        dis_pre.append(dbid)
                    elif state == 'CancelLeave':
                        if dbid in dis_pre:
                            dis_pre = filter(lambda a: a != dbid, dis_pre)

                elif re.match('.+MONKK RealDisconnect.+', line):
                    res = re.split('[ ,=]', line)
#2013-11-27 15:35:27 MONKK RealDisconnect classid=5903,usrdbid=0,userid=0,servertype=mcu,usrip=192.168.11.45:29062:3
#      0        1      2        3             4     5      6   7    8   9   10       11    12        13
                    if '' in res:
                        logging.error('none data: %s' % line)
                        continue
                    classid = res[5] if '.' not in res[5] else res[5].split('.')[0]
                    usrip = res[13].split(':')[0]
                    dbid = res[7]
                    usrid = res[9]
                    if dbid == '0':
                        continue

                    if dbid in namecache:
                        usrname = namecache[dbid]
                    else:
                        usrname = util.get_usrname(dbid)
                        namecache[dbid] = usrname
                        time.sleep(2)
                    recordtime = '%s %s' % (res[0], res[1])
                    servertype = res[11]

                    if dbid in dis_pre:
                        dis_pre = filter(lambda a: a != dbid, dis_pre)
                        continue

                    dbconn = util.getdbconn()
                    dbconn.execute(
                        "INSERT INTO t_disconnect (classid,usrdbid,usrid,usrip,usrname,servertype,serverip,recordtime) "
                        "VALUES (%s,%s,%s,'%s','%s','%s','%s','%s')"
                        % (classid, dbid, usrid, usrip, usrname, servertype, serverip, recordtime)
                    )
示例#2
0
    def do_onefile(self, f, tarpath):
        if not os.path.exists(f):
            return

        if not re.match('.+[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+.+\.tar\.gz', tarpath):
            return

        match = re.search('[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+', tarpath)
        serverip = tarpath[match.start(): match.end()]

        namecache = {}

        with open(f) as f:
            for line in f:
                if re.match('.+MONKK GC PacketLost.+', line):
                    res = re.split('[ ,=]', line)
#2013-11-19 17:28:58 MONKK GC PacketLost classid=43,userid=5,userdbid=20,stream=liveA3,count=0,toaddr=192.168.11.45:31585:3
#      0        1      2    3    4          5     6    7   8    9     10    11     12    13  14   15          16
                    if '' in res:
                        logging.error('none data: %s' % line)
                        continue
                    if res[14] == '0':  # count=0 not save
                        continue
                    if res[10] == '0':
                        continue
                    if '.' in res[6]:
                        res[6] = res[6].split('.')[0]
                    res[16] = res[16].split(':')[0]

                    dbid = res[10]
                    if dbid in namecache:
                        usrname = namecache[dbid]
                    else:
                        usrname = util.get_usrname(dbid)
                        namecache[dbid] = usrname
                        import time
                        time.sleep(2)

                    dbconn = util.getdbconn()
                    dbconn.execute(
                        "INSERT INTO t_gc_packetlost (classid,usrid,usrdbid,usrip,usrname,stream,recordtime,count,server) "
                        "VALUES (%s,%s,%s,'%s','%s','%s','%s %s',%s,'%s')"
                        % (res[6], res[8], res[10], res[16], usrname, res[12], res[0], res[1], res[14], serverip)
                    )

                elif re.match('.+MONKK GG PacketLost.+', line):
                    res = re.split('[ ,=]', line)
#2013-11-19 17:04:57 MONKK GG PacketLost classid=43.000,stream=liveA5,count=0,toaddr=192.168.11.45:31587:3
#      0        1      2    3    4          5     6        7      8     9   10   11       12
                    if '' in res:
                        logging.error('none data: %s' % line)
                        continue
                    if res[10] == '0':  # count=0 not save
                        continue
                    if '.' in res[6]:
                        res[6] = res[6].split('.')[0]
                    res[12] = res[12].split(':')[0]

                    dbconn = util.getdbconn()
                    dbconn.execute(
                        "INSERT INTO t_gg_packetlost (classid,mg_sour,mg_dest,stream,recordtime,count) "
                        "VALUES (%s,'%s','%s','%s','%s %s',%s)"
                        % (res[6], serverip, res[12], res[8], res[0], res[1], res[10])
                    )