Skip to content

Commit

Permalink
feat:support GrowingIO
Browse files Browse the repository at this point in the history
1.release v2.0.0
2.Personal customized version of 爱问医生
  • Loading branch information
Pactortester committed Jan 10, 2021
1 parent 6486e29 commit 8b7e70c
Show file tree
Hide file tree
Showing 20 changed files with 446 additions and 69 deletions.
14 changes: 14 additions & 0 deletions PLAN.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
## 埋点适配计划

- [x] 诸葛 IO
- [x] 神策数据
- [X] GrowingIO 埋点数据
- [ ] 友盟
- [ ] C4J
- [ ] Mixpanel
- [ ] GA
- [ ] Ptmind Ptengine
- [ ] 国双 WebDissector
- [ ] 谷歌分析 Google Analytics


## 埋点数据上传API

- url
Expand Down
71 changes: 43 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,68 +2,63 @@

本项目由 [JetBranins](https://www.jetbrains.com/?from=garbevents) 赞助相关开发工具
<a href="https://www.jetbrains.com/?from=garbevents"><img src="https://github.com/Pactortester/garbevents/blob/master/images/jetbrains-variant-4.svg" width = "150" height = "150" div align=center /></a>
##
[![Build Status](https://travis-ci.com/Pactortester/garbevents.svg?branch=master)](https://travis-ci.com/Pactortester/garbevents) ![PyPI](https://img.shields.io/pypi/v/garbevents) ![PyPI - Python Version](https://img.shields.io/pypi/pyversions/garbevents) ![GitHub top language](https://img.shields.io/github/languages/top/Pactortester/garbevents) ![PyPI - Downloads](https://img.shields.io/pypi/dm/garbevents) ![GitHub stars](https://img.shields.io/github/stars/Pactortester/garbevents?style=social) ![https://blog.csdn.net/flower_drop](https://img.shields.io/badge/csdn-%40flower__drop-orange)


## 适配计划
##

- [x] 诸葛 IO
- [x] 神策数据
- [ ] GrowingIO 埋点数据
- [ ] ....
[![Build Status](https://travis-ci.com/Pactortester/garbevents.svg?branch=master)](https://travis-ci.com/Pactortester/garbevents) ![PyPI](https://img.shields.io/pypi/v/garbevents) ![PyPI - Python Version](https://img.shields.io/pypi/pyversions/garbevents) ![GitHub top language](https://img.shields.io/github/languages/top/Pactortester/garbevents) ![PyPI - Downloads](https://img.shields.io/pypi/dm/garbevents) ![GitHub stars](https://img.shields.io/github/stars/Pactortester/garbevents?style=social) ![https://blog.csdn.net/flower_drop](https://img.shields.io/badge/csdn-%40flower__drop-orange)

## 埋点适配计划

- [x] 诸葛 IO
- [x] 神策数据
- [X] GrowingIO 埋点数据
- [ ] 友盟
- [ ] C4J
- [ ] Mixpanel
- [ ] GA
- [ ] Ptmind Ptengine
- [ ] 国双 WebDissector
- [ ] 谷歌分析 Google Analytics
## Logo


![logo](https://github.com/Pactortester/garbevents/blob/master/images/garbevents.png)


## 安装


pip install garbevents


## 仓库地址:

## 仓库地址:

- github:https://github.com/Pactortester/garbevents.git
- pypi:https://pypi.org/project/garbevents/#history


## 社区地址


- testerhome:https://testerhome.com/opensource_projects/garbevents


## 适用场景


1. 使用 诸葛IO/神策数据 作为埋点收集工具的 。
2. 需要回归验证大批量埋点是否丢失的。
3. 使用本工具 自动抓取解析埋点信息数据校验埋点是否 丢失。


## 功能


1. 自动解析 移动端\桌面端\h5页面 触发的埋点信息,解密后生成 [now_data.txt]()
2. 去重后和已知埋点信息diff,保存文件 [lost_data.txt]()


## 使用


- 启动服务

1. 在cmd启动代理服务

```shell
mitmdump -p 8889 -s test_script.py
```

- 连接代理

1. cmd中运行ipconfig 找到自己的ip地址
2. 手机wifi高级选项,代理选择手动,添加代理服务器

Expand All @@ -72,29 +67,29 @@ ip:你的电脑ip, 端口:8889
```

- 下载证书

1. 在手机浏览器中打开网址 [mitm.it]()
2. 选择对应的证书下载安装

```shell
mitm.it
```

- 开始使用

1. 此时便可以在手机端操作触发埋点,控制台实时打印当前触发的埋点
2. 如果想查看丢失的埋点需要先在 ST.all_events 全局变量中传入全部埋点信息
3. 例如:ST.all_events = ['event_name_1', 'event_name_2']

## 命令


```shell
# 只打印所需日志
mitmdump -p 8889 -q -s test_script.py
```


## 诸葛IO Demo


```python
from garbevents.events import GetData
from garbevents.settings import Settings as ST
Expand All @@ -115,7 +110,6 @@ addons = [

## 神策数据 Demo


```python
from garbevents.sensors_events import GetData
from garbevents.settings import Settings as ST
Expand All @@ -132,16 +126,37 @@ addons = [
]
```

## GrowingIO Demo

```python
from garbevents.growingio_events import GetData
from garbevents.settings import Settings as ST

'mitmdump -p 8889 -s test_growingio_events.py'
# 埋点上传url
ST.url = 'https://wxapi.growingio.com'
# 报告生成路径
ST.report_path = 'report'
# 所有事件名称
ST.all_events = ['event_name_1', 'event_name_2']
addons = [
GetData()
]

```

## 运行截图

![](images/demo.png)

## 用法拓展

1. 结合UI自动化,嵌入到你的平台或者框架中,运行自动化脚本的同时,也测试了埋点。
2. 部署到公司服务器,给测试部门的同学用,助人为乐!!!

##
##

以上便是 garbevents 的基本用法介绍。

如果您有发现错误,或者您对 garbevents 有任何建议,欢迎到 [garbevents Issues](https://github.com/Pactortester/garbevents/issues) 发表,非常感谢您的支持。您的反馈和建议非常宝贵,希望您的参与能帮助 garbevents 做得更好。
如果您有发现错误,或者您对 garbevents 有任何建议,欢迎到 [garbevents Issues](https://github.com/Pactortester/garbevents/issues)
发表,非常感谢您的支持。您的反馈和建议非常宝贵,希望您的参与能帮助 garbevents 做得更好。
100 changes: 100 additions & 0 deletions build/lib/garbevents/custom_sensors_events.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
# -*- coding: utf-8 -*-
import gzip
import os
import urllib
import urllib.parse
import urllib.error
from pprint import pprint

import mitmproxy
from mitmproxy import http
from mitmproxy import ctx
import base64
import json
from garbevents.settings import Settings as ST


class GetData:
"""
Personal customized version of 爱问医生
A engine HTTP request class.
"""
events_list = []

@staticmethod
def chunks(arr, n):
"""
:param arr:
:param n:
:return:
"""
return [arr[i:i + n] for i in range(0, len(arr), n)]

@staticmethod
def gzip_decompress(data):
"""
解密上报数据
:param data:
:return:
"""
try:
return gzip.decompress(data)
except AttributeError:
from io import StringIO

buf = StringIO()
buf.write(data)
fd = gzip.GzipFile(fileobj=buf, mode="r")
fd.rewind()
value = fd.read()
fd.close()
return value

def request(self, flow: mitmproxy.http.HTTPFlow):
"""
代理服务数据分析
:param flow:
:return:
"""

request_data = flow.request
self.request_url = request_data.url

if ST.url in self.request_url:

ctx.log.info("Get the complete URL after splitting ====>{}".format(self.request_url.split('?')[0]))
api = self.request_url.split('?')[0].split('/')[3]
ctx.log.error("Get API address after splitting ====>{}".format(api))

request_content = str(self.request_url).split('&')[1].split('=')[1]
ctx.log.info("Get encrypted data after splitting ====>{}".format(request_content))

gzip_data = urllib.parse.unquote(request_content)
data_list = [json.loads(base64.b64decode(gzip_data).decode('utf8', errors='ignore'))]

for result_list in data_list:
ctx.log.error("Get JSON string after decrypting data ====>")
pprint(result_list)

try:
event = result_list["event"]
ctx.log.error("Get the event name after decrypting the data ====>{}".format(event))
self.events_list.append(event)
except KeyError:
ctx.log.warn("No events!")
event_list = list(set(self.events_list))

if not os.path.exists(ST.report_path):
os.mkdir(ST.report_path)
ctx.log.info(ST.report_path + 'Successfully created!')

file = open('{}/now_event.txt'.format(ST.report_path), 'w')
for line in event_list:
file.write(line + '\n')
ctx.log.warn("Current event name collection ====>{}".format(event_list))
lost_list = list(set(ST.all_events).difference(set(event_list)))
ctx.log.warn("Missing event name collection ====>{}".format(lost_list))
file = open('{}/lost_event.txt'.format(ST.report_path), 'w')
for line in lost_list:
file.write(line + '\n')
100 changes: 100 additions & 0 deletions build/lib/garbevents/growingio_events.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
# -*- coding: utf-8 -*-
import base64
import gzip
import os
import urllib
import urllib.parse
import urllib.error
from pprint import pprint

import mitmproxy
from mitmproxy import http
from mitmproxy import ctx
import json
from garbevents.settings import Settings as ST


class GetData:
"""
Personal customized version of GrowingIO
A garbevents HTTP request class.
"""
events_list = []

@staticmethod
def chunks(arr, n):
"""
:param arr:
:param n:
:return:
"""
return [arr[i:i + n] for i in range(0, len(arr), n)]

@staticmethod
def gzip_decompress(data):
"""
解密上报数据
:param data:
:return:
"""
try:
return gzip.decompress(data)
except AttributeError:
from io import StringIO

buf = StringIO()
buf.write(data)
fd = gzip.GzipFile(fileobj=buf, mode="r")
fd.rewind()
value = fd.read()
fd.close()
return value

def request(self, flow: mitmproxy.http.HTTPFlow):
"""
代理服务数据分析
:param flow:
:return:
"""

request_data = flow.request
self.request_url = request_data.url

if ST.url in self.request_url:

ctx.log.info("Get the complete URL after splitting ====>{}".format(self.request_url))
api = self.request_url.split('/')[3]
ctx.log.error("Get API address after splitting ====>{}".format(api))

request_content = flow.request.content.decode('utf8', errors='ignore')
ctx.log.info("Get encrypted data after splitting ====>{}".format(request_content))

gzip_data = urllib.parse.unquote(request_content)
data_list = json.loads(gzip_data)

for result_list in data_list:
ctx.log.error("Get JSON string after decrypting data ====>")
pprint(result_list)

try:
event = result_list["n"]
ctx.log.error("Get the event name after decrypting the data ====> {}".format(event))
self.events_list.append(event)
except KeyError:
ctx.log.warn("No events!")
event_list = list(set(self.events_list))

if not os.path.exists(ST.report_path):
os.mkdir(ST.report_path)
ctx.log.info(ST.report_path + 'Successfully created!')

file = open('{}/now_event.txt'.format(ST.report_path), 'w')
for line in event_list:
file.write(line + '\n')
ctx.log.warn("Current event name collection ====>{}".format(event_list))
lost_list = list(set(ST.all_events).difference(set(event_list)))
ctx.log.warn("Missing event name collection ====>{}".format(lost_list))
file = open('{}/lost_event.txt'.format(ST.report_path), 'w')
for line in lost_list:
file.write(line + '\n')
2 changes: 1 addition & 1 deletion build/lib/garbevents/sensors_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def request(self, flow: mitmproxy.http.HTTPFlow):

if ST.url in self.request_url:

ctx.log.info("url:-------->{}".format(self.request_url))
ctx.log.info("Get the complete URL after splitting ====>{}".format(self.request_url))
api = self.request_url.split('/')[3]
ctx.log.error("Get API address after splitting ====>{}".format(api))

Expand Down
Loading

0 comments on commit 8b7e70c

Please sign in to comment.