Example #1
0
def connect(request):
    #req_dump = request.copy();
    try:
        jsonData = json.loads(request.body, encoding='utf-8')
    except Exception as e:
        #Json Parsing Exception
        print >> sys.stderr, 'connect error!!!!! bad request.body'
        print >> sys.stderr, 'Exception = ', e
        return HttpResponse(
            json.dumps({
                'idsession':
                long(time.time() * 1000 + random.randint(0, 1000))
            }), 'application/json')

    #step1: apikey를 이용하여 project찾기
    try:
        apikey = jsonData['apikey']
        projectElement = Projects.objects.get(apikey=apikey)
    except ObjectDoesNotExist:
        print 'Invalid from client(connect)'
        return HttpResponse(json.dumps({'idsession': '0'}), 'application/json')

    #step2: idsession 발급하기
    appversion = jsonData['appversion']
    idsession = long(time.time() * 1000 + random.randint(0, 1000))

    print 'Project: %s, Ver: %s, new idsession: %d' % (projectElement.name,
                                                       appversion, idsession)

    #step3: app version별 누적카운트 증가하기
    try:
        #App 실행횟수 증가
        appruncountElement, created = Appruncount.objects.get_or_create(
            pid=projectElement,
            appversion=appversion,
            defaults={'runcount': 1},
            date=getUTCawaredatetime())
        if created == False:
            appruncountElement.runcount += 1
            appruncountElement.save()
        else:
            print 'project: %s, new version: %s' % (
                projectElement.name, appruncountElement.appversion)
    except MultipleObjectsReturned:
        print "MultipleObjectsReturned in client app version count"

    return HttpResponse(json.dumps({'idsession': idsession}),
                        'application/json')
Example #2
0
def receive_native(request):
    #Client Native를 받는 루틴
    print 'receive_native requested'
    try:
        jsonData = json.loads(request.body,encoding='utf-8')
        #req_dump = None
    except Exception as e:
        print >> sys.stderr, 'connect error!!!!! bad request.body'
        #print >> sys.stderr, 'request.body = ', req_dump.body
        #print >> sys.stderr, 'request = ',req_dump
        print >> sys.stderr, 'Exception = ', e
        #req_dump = None
        return HttpResponse(json.dumps({'idinstance':0}), 'application/json');
    #print jsonData

    jsonData = client_data_validate(jsonData)

    #step1: apikey를 이용하여 project찾기
    #apikey가 validate한지 확인하기.
    try:
        apikey = jsonData['apikey']
        projectElement = Projects.objects.get(apikey=apikey)
    except ObjectDoesNotExist:
        print 'Invalid apikey'
        return HttpResponse('Invalid apikey')


    #step2: dummy errorElement생성
    #새로 들어온 에러라면 새로운 에러 생성
    #if int(jsonData['rank']) == -1:
    #    autodetermine = 1 #True
    #else:
    #    autodetermine = 0 #False
    autodetermine = 0

    errorElement = Errors(
        pid = projectElement,
        errorname = 'dummy',
        errorclassname = 'native',
        linenum = 0,
        autodetermine = autodetermine,
        rank = int(jsonData['rank']), # Undesided = -1, unhandled = 0, critical = 1, major = 2, minor = 3, native = 4
        status = 0, # 0 = new, 1 = open, 2 = ignore, 3 = renew
        createdate = getUTCawaredatetime(),
        lastdate = getUTCawaredatetime(),
        numofinstances = 1,
        callstack = '',#jsonData['callstack'],
        wifion = jsonData['wifion'],
        gpson = jsonData['gpson'],
        mobileon = jsonData['mobileon'],
        totalmemusage = jsonData['appmemtotal'],
        errorweight = 10,
        recur = 0,
    )
    errorElement.save()

    #step3: 테그 저장
    tagstr = jsonData['tag']
    if tagstr:
        tagElement, created = Tags.objects.get_or_create(iderror=errorElement,pid=projectElement,tag=tagstr)
    #step4: 인스턴스 생성하기

    instanceElement = Instances(
        iderror = errorElement,
        ins_count = errorElement.numofinstances,
        sdkversion = jsonData['sdkversion'],
        appversion = jsonData['appversion'],
        osversion = jsonData['osversion'],
        kernelversion = jsonData['kernelversion'],
        appmemmax = jsonData['appmemmax'],
        appmemfree = jsonData['appmemfree'],
        appmemtotal = jsonData['appmemtotal'],
        country = jsonData['country'],
        datetime = getUTCawaredatetime(),
        locale = jsonData['locale'],
        mobileon = jsonData['mobileon'],
        gpson = jsonData['gpson'],
        wifion = jsonData['wifion'],
        device = jsonData['device'],
        rooted = jsonData['rooted'],
        scrheight = jsonData['scrheight'],
        scrwidth = jsonData['scrwidth'],
        scrorientation = jsonData['scrorientation'],
        sysmemlow = jsonData['sysmemlow'],
        log_path = '',
        batterylevel = jsonData['batterylevel'],
        availsdcard = jsonData['availsdcard'],
        xdpi = jsonData['xdpi'],
        ydpi = jsonData['ydpi'],
        lastactivity = jsonData['lastactivity'],
    )
    # primary key가 Auto-incrementing이기 때문에 save한 후 primary key를 읽을 수 있다.
    instanceElement.save()


    #step5: 이벤트패스 생성
    #print 'here! ' + instanceElement.idinstance
    #instanceElement.update()
    appversion = jsonData['appversion']

    map_path = os.path.join(PROJECT_DIR,get_config('proguard_map_path'))
    map_path = os.path.join(map_path,projectElement.apikey)
    map_path = os.path.join(map_path,appversion)

    try:
        mapElement = Proguardmap.objects.get(pid=projectElement,appversion=appversion)
    except ObjectDoesNotExist:
        mapElement = None
        print 'no proguard mapfile'



    print 'instanceElement.idinstance',instanceElement.idinstance
    eventpath = jsonData['eventpaths']

    depth = 10
    for event in reversed(eventpath):
        temp_str = event['classname'] + '.' + event['methodname']
        temp_str = proguard_retrace_oneline(temp_str,event['linenum'],map_path,mapElement)
        flag = temp_str.rfind('.')
        classname = temp_str[0:flag]
        methodname =  temp_str[flag+1:]

        if not 'label' in event:    #event path에 label적용, 기존버전과 호환성을 확보하기위해 'label'초기화를 해줌 client ver 0.91 ->
            event['label'] = ""
        Eventpaths.objects.create(
            idinstance = instanceElement,
            iderror = errorElement,
            ins_count = errorElement.numofinstances,
            datetime = naive2aware(event['datetime']),
            classname = classname,
            methodname = methodname,
            linenum = event['linenum'],
            label = event['label'],
            depth = depth,
        )
        depth -= 1
    return HttpResponse(json.dumps({'idinstance':instanceElement.idinstance}), 'application/json');
Example #3
0
def connect(request):
    #req_dump = request.copy();
    try:
        jsonData = json.loads(request.body,encoding='utf-8')
    except Exception as e:
        #Json Parsing Exception
        print >> sys.stderr, 'connect error!!!!! bad request.body'
        print >> sys.stderr, 'Exception = ', e
        return HttpResponse(json.dumps({'idsession':long(time.time() * 1000 + random.randint(0,1000))}), 'application/json');

    #step1: apikey를 이용하여 project찾기
    try:
        apikey = jsonData['apikey']
        projectElement = Projects.objects.get(apikey=apikey)
    except ObjectDoesNotExist:
        print 'Invalid from client(connect)'
        return HttpResponse(json.dumps({'idsession':'0'}), 'application/json');

    #step2: idsession 발급하기
    appversion = jsonData['appversion']
    idsession = long(time.time() * 1000 + random.randint(0,1000))

    print 'Project: %s, Ver: %s, new idsession: %d' % (projectElement.name,appversion,idsession)

    #step3: app version별 누적카운트 증가하기
    try:
        #App 실행횟수 증가
    	appruncountElement, created = Appruncount.objects.get_or_create(pid=projectElement,appversion=appversion,defaults={'runcount':1},date=getUTCawaredatetime())
    	if created == False:
        	appruncountElement.runcount += 1
        	appruncountElement.save()
    	else:
        	print 'project: %s, new version: %s' % (projectElement.name,appruncountElement.appversion)
    except MultipleObjectsReturned:
	print "MultipleObjectsReturned in client app version count"

    return HttpResponse(json.dumps({'idsession':idsession}), 'application/json');
Example #4
0
def receive_exception(request):
    #Client로부터 올라오는 exception을 수집하는 루틴
    try:
        jsonData = json.loads(request.body,encoding='utf-8')
        #req_dump = None
    except Exception as e:
        print >> sys.stderr, 'connect error!!!!! bad request.body'
        #print >> sys.stderr, 'request.body = ', req_dump.body
        #print >> sys.stderr, 'request = ',req_dump
        print >> sys.stderr, 'Exception = ', e
        #req_dump = None
        return HttpResponse(json.dumps({'idinstance':0}), 'application/json');

    #Client로부터 들어온 데이터의 무결성을 검사한다.
    jsonData = client_data_validate(jsonData)


    #step1: apikey를 이용하여 project찾기
    #apikey가 validate한지 확인하기.
    try:
        apikey = jsonData['apikey']
        projectElement = Projects.objects.get(apikey=apikey)
    except ObjectDoesNotExist:
        print 'Invalid apikey'
        return HttpResponse('Invalid apikey')

    #Exception데이터 로깅.
    print >> sys.stderr, 'receive_exception requested',apikey
    print >> sys.stderr, '=========== JsonData ========='
    print >> sys.stderr, jsonData
    print >> sys.stderr, '=============================='

    #step2: errorname, errorclassname, linenum을 이용하여 동일한 에러가 있는지 찾기
    errorname = jsonData['errorname']
    errorclassname = jsonData['errorclassname']
    linenum = jsonData['linenum']

    print >> sys.stderr, 'appver:', jsonData['appversion'], 'osver:', jsonData['osversion']
    print >> sys.stderr, '%s %s %s' % (errorname,errorclassname,linenum)

    #step2-0: Proguard 적용 확인
    appversion = jsonData['appversion']

    map_path = os.path.join(PROJECT_DIR,get_config('proguard_map_path'))
    map_path = os.path.join(map_path,projectElement.apikey)
    map_path = os.path.join(map_path,appversion)
    try:
        #Proguard가 적용된 프로젝트의 경우 Proguard Map파일을 이용하여 Parsing한다.
        mapElement = Proguardmap.objects.get(pid=projectElement,appversion=appversion)

        errorname = proguard_retrace_oneline(errorname,linenum,map_path,mapElement)
        errorclassname = proguard_retrace_oneline(errorclassname,linenum,map_path,mapElement)
        callstack = proguard_retrace_callstack(jsonData['callstack'],map_path,mapElement)
    except ObjectDoesNotExist:
        #Proguard가 적용되지 않은 프로젝트의 경우 데이터를 그대로 사용함.
        mapElement = None
        callstack = jsonData['callstack']
        print 'no proguard mapfile'

    try:
        #동일 에러가 있는지 DB로부터 얻어온다.
        #동일 에러가 없을경우 exception루틴으로 간다.

        errorElement = Errors.objects.get(pid=projectElement,errorname=errorname,errorclassname=errorclassname,linenum=linenum)

        #새로온 인스턴스 정보로 시간 갱신
        #errorElement.lastdate = naive2aware(jsonData['datetime'])
        errorElement.callstack = callstack
        errorElement.lastdate = getUTCawaredatetime()
        errorElement.numofinstances += 1
        #errorElement.totalmemusage += jsonData['appmemtotal']
        errorElement.wifion += int(jsonData['wifion'])
        errorElement.gpson += int(jsonData['gpson'])
        errorElement.mobileon += int(jsonData['mobileon'])
        errorElement.totalmemusage += int(jsonData['appmemtotal'])
        errorElement.save()

        #통계에 사용할 DB갱신
        e, created = Appstatistics.objects.get_or_create(iderror=errorElement,appversion=jsonData['appversion'],defaults={'count':1})
        if not created:
            e.count += 1
            e.save()
        e, created = Osstatistics.objects.get_or_create(iderror=errorElement,osversion=jsonData['osversion'],defaults={'count':1})
        if not created:
            e.count += 1
            e.save()
        e, created = Devicestatistics.objects.get_or_create(iderror=errorElement,devicename=jsonData['device'],defaults={'count':1})
        if not created:
            e.count += 1
            e.save()
        e, created = Countrystatistics.objects.get_or_create(iderror=errorElement,countryname=jsonData['country'],defaults={'count':1})
        if not created:
            e.count += 1
            e.save()
        e, created = Activitystatistics.objects.get_or_create(iderror=errorElement,activityname=jsonData['lastactivity'],defaults={'count':1})
        if not created:
            e.count += 1
            e.save()

    except ObjectDoesNotExist:
        #새로운 에러로 판별하여 DB 에러테이블에 데이터를 생성한다.
        autodetermine = 0 #deprecated
        errorElement = Errors(
            pid = projectElement,
            errorname = errorname,
            errorclassname = errorclassname,
            linenum = linenum,
            autodetermine = autodetermine,
            rank = int(jsonData['rank']), # Undesided = -1, unhandled = 0, critical = 1, major = 2, minor = 3, native = 4
            status = 0, # 0 = new, 1 = open, 2 = fixed, 3 = ignore
            createdate = getUTCawaredatetime(),
            lastdate = getUTCawaredatetime(),
            numofinstances = 1,
            callstack = callstack,
            wifion = jsonData['wifion'],
            gpson = jsonData['gpson'],
            mobileon = jsonData['mobileon'],
            totalmemusage = jsonData['appmemtotal'],
            errorweight = 10,
            recur = 0,
        )
        errorElement.save()
        #통계용 데이터도 생성한다.
        Appstatistics.objects.create(iderror=errorElement,appversion=jsonData['appversion'],count=1)
        Osstatistics.objects.create(iderror=errorElement,osversion=jsonData['osversion'],count=1)
        Devicestatistics.objects.create(iderror=errorElement,devicename=jsonData['device'],count=1)
        Countrystatistics.objects.create(iderror=errorElement,countryname=jsonData['country'],count=1)
        Activitystatistics.objects.create(iderror=errorElement,activityname=jsonData['lastactivity'],count=1)
        #error score 계산 에러스코어 삭제
        #calc_errorScore(errorElement)
    #step3: 테그 저장
    if jsonData['tag']:
        #테그 데이터가 있다면 테그를 생성한다.
        tagstr = jsonData['tag']
        tagElement, created = Tags.objects.get_or_create(iderror=errorElement,pid=projectElement,tag=tagstr)


    #step4: 인스턴스 생성하기
    #1개의 에러에는 여러개이 인스턴스
    instanceElement = Instances(
        iderror = errorElement,
        ins_count = errorElement.numofinstances,
        sdkversion = jsonData['sdkversion'],
        appversion = jsonData['appversion'],
        osversion = jsonData['osversion'],
        kernelversion = jsonData['kernelversion'],
        appmemmax = jsonData['appmemmax'],
        appmemfree = jsonData['appmemfree'],
        appmemtotal = jsonData['appmemtotal'],
        country = jsonData['country'],
        datetime = getUTCawaredatetime(),
        locale = jsonData['locale'],
        mobileon = jsonData['mobileon'],
        gpson = jsonData['gpson'],
        wifion = jsonData['wifion'],
        device = jsonData['device'],
        rooted = jsonData['rooted'],
        scrheight = jsonData['scrheight'],
        scrwidth = jsonData['scrwidth'],
        scrorientation = jsonData['scrorientation'],
        sysmemlow = jsonData['sysmemlow'],
        log_path = '',
        batterylevel = jsonData['batterylevel'],
        availsdcard = jsonData['availsdcard'],
        xdpi = jsonData['xdpi'],
        ydpi = jsonData['ydpi'],
        lastactivity = jsonData['lastactivity'],
        callstack = callstack,
    )
    # primary key가 Auto-incrementing이기 때문에 save한 후 primary key를 읽을 수 있다.
    instanceElement.save()


    #step5: 이벤트패스 생성
    #print 'here! ' + instanceElement.idinstance
    #instanceElement.update()
    print >> sys.stderr, 'instanceElement.idinstance',instanceElement.idinstance
    eventpath = jsonData['eventpaths']

    depth = 10
    for event in reversed(eventpath):
        temp_str = event['classname'] + '.' + event['methodname']
        temp_str = proguard_retrace_oneline(temp_str,event['linenum'],map_path,mapElement)
        flag = temp_str.rfind('.')
        classname = temp_str[0:flag]
        methodname =  temp_str[flag+1:]
        if not 'label' in event:    #event path에 label적용, 기존버전과 호환성을 확보하기위해 'label'초기화를 해줌 client ver 0.91 ->
            event['label'] = ""
        Eventpaths.objects.create(
            idinstance = instanceElement,
            iderror = errorElement,
            ins_count = errorElement.numofinstances,
            datetime = naive2aware(event['datetime']),
            classname = classname,
            methodname = methodname,
            linenum = event['linenum'],
            label = event['label'],
            depth = depth
        )
        depth -= 1

    #calc_eventpath(errorElement)
    return HttpResponse(json.dumps({'idinstance':instanceElement.idinstance}), 'application/json');
Example #5
0
def proguardmap_upload(request, apikey):
    print 'proguardmap_upload',apikey

    result, msg, userElement, projectElement = validUserPjt(request.user, apikey)

    if not result:
        return HttpResponse(msg)
    print request.FILES

    appver = request.POST['appversion']
    retdat = {'result':-1,'msg':'Failed to Upload File'}

    if request.method != 'POST':
        retdat = {'result':-1,'msg':'Bad request'}
    elif len(appver) == 0:
        retdat = {'result':-1,'msg':'Invalid App version'}
    elif not 'file' in request.FILES:
        retdat = {'result':-1,'msg':'You should select file'}
    else:
        file = request.FILES['file']
        temp_fname = file._name

        temp_path = os.path.join(PROJECT_DIR,get_config('proguard_map_path'))
        if not os.path.isdir(temp_path):
            os.mkdir(temp_path)
        temp_path = os.path.join(temp_path,apikey)
        if not os.path.isdir(temp_path):
            os.mkdir(temp_path)
        temp_path = os.path.join(temp_path,appver)
        if not os.path.isdir(temp_path):
            os.mkdir(temp_path)

        fp = open(os.path.join(temp_path,temp_fname) , 'wb')
        for chunk in file.chunks():
            fp.write(chunk)
        fp.close()
        retdat = {'result':0,'msg':'File successfully Uploaded'}

    if retdat['result'] == 0:
        try:
            mapElement = Proguardmap.objects.get(pid=projectElement,appversion=appver)
            if mapElement.filename != temp_fname:
                temp_path = os.path.join(PROJECT_DIR,get_config('proguard_map_path'))
                temp_path = os.path.join(temp_path,apikey)
                temp_path = os.path.join(temp_path,appver)
                os.remove(os.path.join(temp_path,mapElement.filename))
            mapElement.filename = temp_fname
            mapElement.uploadtime = getUTCawaredatetime()
            mapElement.save()
            retdat = {'result':1,'msg':'File successfully re Uploaded'}
            print 'mapping file overwrite'
        except ObjectDoesNotExist:
            print 'new mapping file'
            mapElement = Proguardmap(
                pid=projectElement,
                appversion=appver,
                filename=temp_fname,
                uploadtime=getUTCawaredatetime(),
            )
            mapElement.save();
        retdat['appversion'] = mapElement.appversion
        retdat['filename'] = mapElement.filename
        retdat['date'] = toTimezone(mapElement.uploadtime,projectElement.timezone).__format__('%Y.%m.%d')
        retdat['time'] = toTimezone(mapElement.uploadtime,projectElement.timezone).__format__('%H:%M')
    print retdat
    return HttpResponse(json.dumps(retdat), 'application/json');
Example #6
0
def connect(request):
    #req_dump = request.copy();
    try:
        jsonData = json.loads(request.body,encoding='utf-8')
        #req_dump = None
    except Exception as e:
        print >> sys.stderr, 'connect error!!!!! bad request.body'
        #print >> sys.stderr, 'request.body = ', req_dump.body
        #print >> sys.stderr, 'request = ',req_dump
        print >> sys.stderr, 'Exception = ', e
        #req_dump = None
        return HttpResponse(json.dumps({'idsession':long(time.time() * 1000 + random.randint(0,1000))}), 'application/json');
    #print jsonData

    #step1: apikey를 이용하여 project찾기
    try:
        apikey = jsonData['apikey']
        projectElement = Projects.objects.get(apikey=apikey)
    except ObjectDoesNotExist:
        print 'Invalid from client(connect)'
        return HttpResponse(json.dumps({'idsession':'0'}), 'application/json');

    #step2: idsession 발급하기
    appversion = jsonData['appversion']
    idsession = long(time.time() * 1000 + random.randint(0,1000))
    #duple = Session.objects.filter(idsession=idsession);
    #if len(duple) != 0:
    #    idsession = long(time.time() * 1000 + random.randint(0,1000));
    #Session.objects.create(idsession=idsession,pid=projectElement,appversion=appversion)
    print 'Project: %s, Ver: %s, new idsession: %d' % (projectElement.name,appversion,idsession)

    #step3: app version별 누적카운트 증가하기
    appruncountElement, created = Appruncount.objects.get_or_create(pid=projectElement,appversion=appversion,defaults={'runcount':1},date=getUTCawaredatetime())
    if created == False:
        appruncountElement.runcount += 1
        appruncountElement.save()
    else:
        print 'project: %s, new version: %s' % (projectElement.name,appruncountElement.appversion)
    return HttpResponse(json.dumps({'idsession':idsession}), 'application/json');
Example #7
0
def proguardmap_upload(request, apikey):
    #Proguard MAP데이터를 업로드한다.
    print 'proguardmap_upload', apikey

    result, msg, userElement, projectElement = validUserPjt(
        request.user, apikey)

    if not result:
        return HttpResponse(msg)
    print request.FILES

    appver = request.POST['appversion']
    retdat = {'result': -1, 'msg': 'Failed to Upload File'}

    if request.method != 'POST':
        retdat = {'result': -1, 'msg': 'Bad request'}
    elif len(appver) == 0:
        retdat = {'result': -1, 'msg': 'Invalid App version'}
    elif not 'file' in request.FILES:
        retdat = {'result': -1, 'msg': 'You should select file'}
    else:
        file = request.FILES['file']
        temp_fname = file._name

        temp_path = os.path.join(PROJECT_DIR, get_config('proguard_map_path'))
        if not os.path.isdir(temp_path):
            os.mkdir(temp_path)
        temp_path = os.path.join(temp_path, apikey)
        if not os.path.isdir(temp_path):
            os.mkdir(temp_path)
        temp_path = os.path.join(temp_path, appver)
        if not os.path.isdir(temp_path):
            os.mkdir(temp_path)

        fp = open(os.path.join(temp_path, temp_fname), 'wb')
        for chunk in file.chunks():
            fp.write(chunk)
        fp.close()
        retdat = {'result': 0, 'msg': 'File successfully Uploaded'}

    #정상적으로 Map파일이 업로드 되었다면
    if retdat['result'] == 0:
        try:
            mapElement = Proguardmap.objects.get(pid=projectElement,
                                                 appversion=appver)
            if mapElement.filename != temp_fname:
                temp_path = os.path.join(PROJECT_DIR,
                                         get_config('proguard_map_path'))
                temp_path = os.path.join(temp_path, apikey)
                temp_path = os.path.join(temp_path, appver)
                os.remove(os.path.join(temp_path, mapElement.filename))
            mapElement.filename = temp_fname
            mapElement.uploadtime = getUTCawaredatetime()
            mapElement.save()
            retdat = {'result': 1, 'msg': 'File successfully re Uploaded'}
            print 'mapping file overwrite'
        except ObjectDoesNotExist:
            print 'new mapping file'
            mapElement = Proguardmap(
                pid=projectElement,
                appversion=appver,
                filename=temp_fname,
                uploadtime=getUTCawaredatetime(),
            )
            mapElement.save()
        retdat['appversion'] = mapElement.appversion
        retdat['filename'] = mapElement.filename
        retdat['date'] = toTimezone(
            mapElement.uploadtime,
            projectElement.timezone).__format__('%Y.%m.%d')
        retdat['time'] = toTimezone(
            mapElement.uploadtime, projectElement.timezone).__format__('%H:%M')
    print retdat
    return HttpResponse(json.dumps(retdat), 'application/json')
Example #8
0
def receive_native(request):
    #Client Native를 받는 루틴
    print 'receive_native requested'
    try:
        jsonData = json.loads(request.body, encoding='utf-8')
        #req_dump = None
    except Exception as e:
        print >> sys.stderr, 'connect error!!!!! bad request.body'
        #print >> sys.stderr, 'request.body = ', req_dump.body
        #print >> sys.stderr, 'request = ',req_dump
        print >> sys.stderr, 'Exception = ', e
        #req_dump = None
        return HttpResponse(json.dumps({'idinstance': 0}), 'application/json')
    #print jsonData

    jsonData = client_data_validate(jsonData)

    #step1: apikey를 이용하여 project찾기
    #apikey가 validate한지 확인하기.
    try:
        apikey = jsonData['apikey']
        projectElement = Projects.objects.get(apikey=apikey)
    except ObjectDoesNotExist:
        print 'Invalid apikey'
        return HttpResponse('Invalid apikey')

    #step2: dummy errorElement생성
    #새로 들어온 에러라면 새로운 에러 생성
    #if int(jsonData['rank']) == -1:
    #    autodetermine = 1 #True
    #else:
    #    autodetermine = 0 #False
    autodetermine = 0

    errorElement = Errors(
        pid=projectElement,
        errorname='dummy',
        errorclassname='native',
        linenum=0,
        autodetermine=autodetermine,
        rank=int(
            jsonData['rank']
        ),  # Undesided = -1, unhandled = 0, critical = 1, major = 2, minor = 3, native = 4
        status=0,  # 0 = new, 1 = open, 2 = ignore, 3 = renew
        createdate=getUTCawaredatetime(),
        lastdate=getUTCawaredatetime(),
        numofinstances=1,
        callstack='',  #jsonData['callstack'],
        wifion=jsonData['wifion'],
        gpson=jsonData['gpson'],
        mobileon=jsonData['mobileon'],
        totalmemusage=jsonData['appmemtotal'],
        errorweight=10,
        recur=0,
    )
    errorElement.save()

    #step3: 테그 저장
    tagstr = jsonData['tag']
    if tagstr:
        tagElement, created = Tags.objects.get_or_create(iderror=errorElement,
                                                         pid=projectElement,
                                                         tag=tagstr)
    #step4: 인스턴스 생성하기

    instanceElement = Instances(
        iderror=errorElement,
        ins_count=errorElement.numofinstances,
        sdkversion=jsonData['sdkversion'],
        appversion=jsonData['appversion'],
        osversion=jsonData['osversion'],
        kernelversion=jsonData['kernelversion'],
        appmemmax=jsonData['appmemmax'],
        appmemfree=jsonData['appmemfree'],
        appmemtotal=jsonData['appmemtotal'],
        country=jsonData['country'],
        datetime=getUTCawaredatetime(),
        locale=jsonData['locale'],
        mobileon=jsonData['mobileon'],
        gpson=jsonData['gpson'],
        wifion=jsonData['wifion'],
        device=jsonData['device'],
        rooted=jsonData['rooted'],
        scrheight=jsonData['scrheight'],
        scrwidth=jsonData['scrwidth'],
        scrorientation=jsonData['scrorientation'],
        sysmemlow=jsonData['sysmemlow'],
        log_path='',
        batterylevel=jsonData['batterylevel'],
        availsdcard=jsonData['availsdcard'],
        xdpi=jsonData['xdpi'],
        ydpi=jsonData['ydpi'],
        lastactivity=jsonData['lastactivity'],
    )
    # primary key가 Auto-incrementing이기 때문에 save한 후 primary key를 읽을 수 있다.
    instanceElement.save()

    #step5: 이벤트패스 생성
    #print 'here! ' + instanceElement.idinstance
    #instanceElement.update()
    appversion = jsonData['appversion']

    map_path = os.path.join(PROJECT_DIR, get_config('proguard_map_path'))
    map_path = os.path.join(map_path, projectElement.apikey)
    map_path = os.path.join(map_path, appversion)

    try:
        mapElement = Proguardmap.objects.get(pid=projectElement,
                                             appversion=appversion)
    except ObjectDoesNotExist:
        mapElement = None
        print 'no proguard mapfile'

    print 'instanceElement.idinstance', instanceElement.idinstance
    eventpath = jsonData['eventpaths']

    depth = 10
    for event in reversed(eventpath):
        temp_str = event['classname'] + '.' + event['methodname']
        temp_str = proguard_retrace_oneline(temp_str, event['linenum'],
                                            map_path, mapElement)
        flag = temp_str.rfind('.')
        classname = temp_str[0:flag]
        methodname = temp_str[flag + 1:]

        if not 'label' in event:  #event path에 label적용, 기존버전과 호환성을 확보하기위해 'label'초기화를 해줌 client ver 0.91 ->
            event['label'] = ""
        Eventpaths.objects.create(
            idinstance=instanceElement,
            iderror=errorElement,
            ins_count=errorElement.numofinstances,
            datetime=naive2aware(event['datetime']),
            classname=classname,
            methodname=methodname,
            linenum=event['linenum'],
            label=event['label'],
            depth=depth,
        )
        depth -= 1
    return HttpResponse(json.dumps({'idinstance': instanceElement.idinstance}),
                        'application/json')
Example #9
0
def receive_exception(request):
    #Client로부터 올라오는 exception을 수집하는 루틴
    try:
        jsonData = json.loads(request.body, encoding='utf-8')
        #req_dump = None
    except Exception as e:
        print >> sys.stderr, 'connect error!!!!! bad request.body'
        #print >> sys.stderr, 'request.body = ', req_dump.body
        #print >> sys.stderr, 'request = ',req_dump
        print >> sys.stderr, 'Exception = ', e
        #req_dump = None
        return HttpResponse(json.dumps({'idinstance': 0}), 'application/json')

    #Client로부터 들어온 데이터의 무결성을 검사한다.
    jsonData = client_data_validate(jsonData)

    #step1: apikey를 이용하여 project찾기
    #apikey가 validate한지 확인하기.
    try:
        apikey = jsonData['apikey']
        projectElement = Projects.objects.get(apikey=apikey)
    except ObjectDoesNotExist:
        print 'Invalid apikey'
        return HttpResponse('Invalid apikey')

    #Exception데이터 로깅.
    print >> sys.stderr, 'receive_exception requested', apikey
    print >> sys.stderr, '=========== JsonData ========='
    print >> sys.stderr, jsonData
    print >> sys.stderr, '=============================='

    #step2: errorname, errorclassname, linenum을 이용하여 동일한 에러가 있는지 찾기
    errorname = jsonData['errorname']
    errorclassname = jsonData['errorclassname']
    linenum = jsonData['linenum']

    print >> sys.stderr, 'appver:', jsonData['appversion'], 'osver:', jsonData[
        'osversion']
    print >> sys.stderr, '%s %s %s' % (errorname, errorclassname, linenum)

    #step2-0: Proguard 적용 확인
    appversion = jsonData['appversion']

    map_path = os.path.join(PROJECT_DIR, get_config('proguard_map_path'))
    map_path = os.path.join(map_path, projectElement.apikey)
    map_path = os.path.join(map_path, appversion)
    try:
        #Proguard가 적용된 프로젝트의 경우 Proguard Map파일을 이용하여 Parsing한다.
        mapElement = Proguardmap.objects.get(pid=projectElement,
                                             appversion=appversion)

        errorname = proguard_retrace_oneline(errorname, linenum, map_path,
                                             mapElement)
        errorclassname = proguard_retrace_oneline(errorclassname, linenum,
                                                  map_path, mapElement)
        callstack = proguard_retrace_callstack(jsonData['callstack'], map_path,
                                               mapElement)
    except ObjectDoesNotExist:
        #Proguard가 적용되지 않은 프로젝트의 경우 데이터를 그대로 사용함.
        mapElement = None
        callstack = jsonData['callstack']
        print 'no proguard mapfile'

    try:
        #동일 에러가 있는지 DB로부터 얻어온다.
        #동일 에러가 없을경우 exception루틴으로 간다.

        errorElement = Errors.objects.get(pid=projectElement,
                                          errorname=errorname,
                                          errorclassname=errorclassname,
                                          linenum=linenum)

        #새로온 인스턴스 정보로 시간 갱신
        #errorElement.lastdate = naive2aware(jsonData['datetime'])
        errorElement.callstack = callstack
        errorElement.lastdate = getUTCawaredatetime()
        errorElement.numofinstances += 1
        #errorElement.totalmemusage += jsonData['appmemtotal']
        errorElement.wifion += int(jsonData['wifion'])
        errorElement.gpson += int(jsonData['gpson'])
        errorElement.mobileon += int(jsonData['mobileon'])
        errorElement.totalmemusage += int(jsonData['appmemtotal'])
        errorElement.save()

        #통계에 사용할 DB갱신
        e, created = Appstatistics.objects.get_or_create(
            iderror=errorElement,
            appversion=jsonData['appversion'],
            defaults={'count': 1})
        if not created:
            e.count += 1
            e.save()
        e, created = Osstatistics.objects.get_or_create(
            iderror=errorElement,
            osversion=jsonData['osversion'],
            defaults={'count': 1})
        if not created:
            e.count += 1
            e.save()
        e, created = Devicestatistics.objects.get_or_create(
            iderror=errorElement,
            devicename=jsonData['device'],
            defaults={'count': 1})
        if not created:
            e.count += 1
            e.save()
        e, created = Countrystatistics.objects.get_or_create(
            iderror=errorElement,
            countryname=jsonData['country'],
            defaults={'count': 1})
        if not created:
            e.count += 1
            e.save()
        e, created = Activitystatistics.objects.get_or_create(
            iderror=errorElement,
            activityname=jsonData['lastactivity'],
            defaults={'count': 1})
        if not created:
            e.count += 1
            e.save()

    except ObjectDoesNotExist:
        #새로운 에러로 판별하여 DB 에러테이블에 데이터를 생성한다.
        autodetermine = 0  #deprecated
        errorElement = Errors(
            pid=projectElement,
            errorname=errorname,
            errorclassname=errorclassname,
            linenum=linenum,
            autodetermine=autodetermine,
            rank=int(
                jsonData['rank']
            ),  # Undesided = -1, unhandled = 0, critical = 1, major = 2, minor = 3, native = 4
            status=0,  # 0 = new, 1 = open, 2 = fixed, 3 = ignore
            createdate=getUTCawaredatetime(),
            lastdate=getUTCawaredatetime(),
            numofinstances=1,
            callstack=callstack,
            wifion=jsonData['wifion'],
            gpson=jsonData['gpson'],
            mobileon=jsonData['mobileon'],
            totalmemusage=jsonData['appmemtotal'],
            errorweight=10,
            recur=0,
        )
        errorElement.save()
        #통계용 데이터도 생성한다.
        Appstatistics.objects.create(iderror=errorElement,
                                     appversion=jsonData['appversion'],
                                     count=1)
        Osstatistics.objects.create(iderror=errorElement,
                                    osversion=jsonData['osversion'],
                                    count=1)
        Devicestatistics.objects.create(iderror=errorElement,
                                        devicename=jsonData['device'],
                                        count=1)
        Countrystatistics.objects.create(iderror=errorElement,
                                         countryname=jsonData['country'],
                                         count=1)
        Activitystatistics.objects.create(
            iderror=errorElement,
            activityname=jsonData['lastactivity'],
            count=1)
        #error score 계산 에러스코어 삭제
        #calc_errorScore(errorElement)
    #step3: 테그 저장
    if jsonData['tag']:
        #테그 데이터가 있다면 테그를 생성한다.
        tagstr = jsonData['tag']
        tagElement, created = Tags.objects.get_or_create(iderror=errorElement,
                                                         pid=projectElement,
                                                         tag=tagstr)

    #step4: 인스턴스 생성하기
    #1개의 에러에는 여러개이 인스턴스
    instanceElement = Instances(
        iderror=errorElement,
        ins_count=errorElement.numofinstances,
        sdkversion=jsonData['sdkversion'],
        appversion=jsonData['appversion'],
        osversion=jsonData['osversion'],
        kernelversion=jsonData['kernelversion'],
        appmemmax=jsonData['appmemmax'],
        appmemfree=jsonData['appmemfree'],
        appmemtotal=jsonData['appmemtotal'],
        country=jsonData['country'],
        datetime=getUTCawaredatetime(),
        locale=jsonData['locale'],
        mobileon=jsonData['mobileon'],
        gpson=jsonData['gpson'],
        wifion=jsonData['wifion'],
        device=jsonData['device'],
        rooted=jsonData['rooted'],
        scrheight=jsonData['scrheight'],
        scrwidth=jsonData['scrwidth'],
        scrorientation=jsonData['scrorientation'],
        sysmemlow=jsonData['sysmemlow'],
        log_path='',
        batterylevel=jsonData['batterylevel'],
        availsdcard=jsonData['availsdcard'],
        xdpi=jsonData['xdpi'],
        ydpi=jsonData['ydpi'],
        lastactivity=jsonData['lastactivity'],
        callstack=callstack,
    )
    # primary key가 Auto-incrementing이기 때문에 save한 후 primary key를 읽을 수 있다.
    instanceElement.save()

    #step5: 이벤트패스 생성
    #print 'here! ' + instanceElement.idinstance
    #instanceElement.update()
    print >> sys.stderr, 'instanceElement.idinstance', instanceElement.idinstance
    eventpath = jsonData['eventpaths']

    depth = 10
    for event in reversed(eventpath):
        temp_str = event['classname'] + '.' + event['methodname']
        temp_str = proguard_retrace_oneline(temp_str, event['linenum'],
                                            map_path, mapElement)
        flag = temp_str.rfind('.')
        classname = temp_str[0:flag]
        methodname = temp_str[flag + 1:]
        if not 'label' in event:  #event path에 label적용, 기존버전과 호환성을 확보하기위해 'label'초기화를 해줌 client ver 0.91 ->
            event['label'] = ""
        Eventpaths.objects.create(idinstance=instanceElement,
                                  iderror=errorElement,
                                  ins_count=errorElement.numofinstances,
                                  datetime=naive2aware(event['datetime']),
                                  classname=classname,
                                  methodname=methodname,
                                  linenum=event['linenum'],
                                  label=event['label'],
                                  depth=depth)
        depth -= 1

    #calc_eventpath(errorElement)
    return HttpResponse(json.dumps({'idinstance': instanceElement.idinstance}),
                        'application/json')
Example #10
0
def proguardmap_upload(request, apikey):
    print "proguardmap_upload", apikey

    result, msg, userElement, projectElement = validUserPjt(request.user, apikey)

    if not result:
        return HttpResponse(msg)
    print request.FILES

    appver = request.POST["appversion"]
    retdat = {"result": -1, "msg": "Failed to Upload File"}

    if request.method != "POST":
        retdat = {"result": -1, "msg": "Bad request"}
    elif len(appver) == 0:
        retdat = {"result": -1, "msg": "Invalid App version"}
    elif not "file" in request.FILES:
        retdat = {"result": -1, "msg": "You should select file"}
    else:
        file = request.FILES["file"]
        temp_fname = file._name

        temp_path = os.path.join(PROJECT_DIR, get_config("proguard_map_path"))
        if not os.path.isdir(temp_path):
            os.mkdir(temp_path)
        temp_path = os.path.join(temp_path, apikey)
        if not os.path.isdir(temp_path):
            os.mkdir(temp_path)
        temp_path = os.path.join(temp_path, appver)
        if not os.path.isdir(temp_path):
            os.mkdir(temp_path)

        fp = open(os.path.join(temp_path, temp_fname), "wb")
        for chunk in file.chunks():
            fp.write(chunk)
        fp.close()
        retdat = {"result": 0, "msg": "File successfully Uploaded"}

    if retdat["result"] == 0:
        try:
            mapElement = Proguardmap.objects.get(pid=projectElement, appversion=appver)
            if mapElement.filename != temp_fname:
                temp_path = os.path.join(PROJECT_DIR, get_config("proguard_map_path"))
                temp_path = os.path.join(temp_path, apikey)
                temp_path = os.path.join(temp_path, appver)
                os.remove(os.path.join(temp_path, mapElement.filename))
            mapElement.filename = temp_fname
            mapElement.uploadtime = getUTCawaredatetime()
            mapElement.save()
            retdat = {"result": 1, "msg": "File successfully re Uploaded"}
            print "mapping file overwrite"
        except ObjectDoesNotExist:
            print "new mapping file"
            mapElement = Proguardmap(
                pid=projectElement, appversion=appver, filename=temp_fname, uploadtime=getUTCawaredatetime()
            )
            mapElement.save()
        retdat["appversion"] = mapElement.appversion
        retdat["filename"] = mapElement.filename
        retdat["date"] = toTimezone(mapElement.uploadtime, projectElement.timezone).__format__("%Y.%m.%d")
        retdat["time"] = toTimezone(mapElement.uploadtime, projectElement.timezone).__format__("%H:%M")
    print retdat
    return HttpResponse(json.dumps(retdat), "application/json")