|
@@ -7,7 +7,8 @@ from django.views.generic.base import View
|
|
|
from Object.ResponseObject import ResponseObject
|
|
|
from Object.TokenObject import TokenObject
|
|
|
from Service.CommonService import CommonService
|
|
|
-from Model.models import Device_Info, RequestRecordModel, iotdeviceInfoModel, Access_Log, DeviceLogModel, LogModel
|
|
|
+from Model.models import Device_Info, RequestRecordModel, iotdeviceInfoModel, Access_Log, DeviceLogModel, LogModel, \
|
|
|
+ AppLogModel
|
|
|
from Ansjer.config import REGION_NAME, ACCESS_KEY_ID, SECRET_ACCESS_KEY, LOG_BUCKET
|
|
|
|
|
|
|
|
@@ -48,6 +49,8 @@ class LogManagementView(View):
|
|
|
# 操作日志
|
|
|
elif operation == 'getOperationLogList':
|
|
|
return self.getOperationLogList(request_dict, response)
|
|
|
+ elif operation == 'getAppLogList': # 获取app日志
|
|
|
+ return self.getAppLogList(request_dict, response)
|
|
|
else:
|
|
|
return response.json(404)
|
|
|
|
|
@@ -127,8 +130,7 @@ class LogManagementView(View):
|
|
|
'thing_name',
|
|
|
'thing_groups',
|
|
|
'add_time',
|
|
|
- 'update_time')[
|
|
|
- (page - 1) * line:page * line]
|
|
|
+ 'update_time')[(page - 1) * line:page * line]
|
|
|
else:
|
|
|
total = iotdeviceInfoModel.objects.filter().count()
|
|
|
iot_device_info_qs = iotdeviceInfoModel.objects.filter().values(
|
|
@@ -137,8 +139,7 @@ class LogManagementView(View):
|
|
|
'thing_name',
|
|
|
'thing_groups',
|
|
|
'add_time',
|
|
|
- 'update_time')[
|
|
|
- (page - 1) * line:page * line]
|
|
|
+ 'update_time')[(page - 1) * line:page * line]
|
|
|
|
|
|
iot_device_info_list = CommonService.qs_to_list(iot_device_info_qs)
|
|
|
# 获取序列号的uid
|
|
@@ -165,7 +166,7 @@ class LogManagementView(View):
|
|
|
|
|
|
try:
|
|
|
msg = eval(msg)
|
|
|
- identification_code = thing_name[thing_name.rindex('_')+1:]
|
|
|
+ identification_code = thing_name[thing_name.rindex('_') + 1:]
|
|
|
if not CommonService.req_publish_mqtt_msg(identification_code, topic_name, msg):
|
|
|
return response.json(10044)
|
|
|
return response.json(0)
|
|
@@ -198,12 +199,13 @@ class LogManagementView(View):
|
|
|
return response.json(0)
|
|
|
total = access_log_qs.count()
|
|
|
access_log_qs = access_log_qs.order_by('-time').values(
|
|
|
- 'user', 'operation', 'ip', 'status', 'content', 'time')[
|
|
|
- (page - 1) * line:page * line]
|
|
|
+ 'user', 'operation', 'ip', 'status', 'content', 'time')[(page - 1) * line:page * line]
|
|
|
else:
|
|
|
total = Access_Log.objects.count()
|
|
|
access_log_qs = Access_Log.objects.filter().order_by('-time').values('user',
|
|
|
- 'operation', 'ip', 'status', 'content', 'time')[(page - 1) * line:page * line]
|
|
|
+ 'operation', 'ip', 'status',
|
|
|
+ 'content', 'time')[
|
|
|
+ (page - 1) * line:page * line]
|
|
|
access_log_list = CommonService.qs_to_list(access_log_qs)
|
|
|
return response.json(0, {'list': access_log_list, 'total': total})
|
|
|
except Exception as e:
|
|
@@ -251,7 +253,7 @@ class LogManagementView(View):
|
|
|
for device_log in device_log_list:
|
|
|
obj = device_log['serial_number'] if device_log['serial_number'] else device_log['uid']
|
|
|
obj = 'device_log/' + obj + \
|
|
|
- '/{}'.format(device_log['filename'])
|
|
|
+ '/{}'.format(device_log['filename'])
|
|
|
download_url = aws_s3_client.generate_presigned_url(
|
|
|
ClientMethod='get_object',
|
|
|
Params={
|
|
@@ -287,10 +289,66 @@ class LogManagementView(View):
|
|
|
count = log_qs.count()
|
|
|
log_qs = log_qs.values(
|
|
|
'operation', 'url', 'content', 'ip', 'time')[
|
|
|
- (page - 1) * line:page * line]
|
|
|
+ (page - 1) * line:page * line]
|
|
|
log_list = list(log_qs)
|
|
|
return response.json(
|
|
|
0, {'list': log_list, 'total': count})
|
|
|
except Exception as e:
|
|
|
print(e)
|
|
|
return response.json(500, repr(e))
|
|
|
+
|
|
|
+ def getAppLogList(self, request_dict, response):
|
|
|
+ """
|
|
|
+ 获取App日志信息
|
|
|
+ @param request_dict:请求参数
|
|
|
+ @param response:响应对象
|
|
|
+ @request_dict userID:用户ID
|
|
|
+ @request_dict uid:uid
|
|
|
+ @return:
|
|
|
+ """
|
|
|
+ userName = request_dict.get('userName', None)
|
|
|
+ uid = request_dict.get('uid', None)
|
|
|
+ pageNo = request_dict.get('pageNo', None)
|
|
|
+ pageSize = request_dict.get('pageSize', None)
|
|
|
+
|
|
|
+ if not all([pageNo, pageSize]):
|
|
|
+ return response.json(444)
|
|
|
+ page = int(pageNo)
|
|
|
+ line = int(pageSize)
|
|
|
+ try:
|
|
|
+ app_log_qs = AppLogModel.objects.all()
|
|
|
+ if userName:
|
|
|
+ app_log_qs = app_log_qs.filter(user__username=userName)
|
|
|
+ elif uid:
|
|
|
+ app_log_qs = app_log_qs.filter(uid=uid)
|
|
|
+ count = app_log_qs.count()
|
|
|
+ log_qs = app_log_qs.values(
|
|
|
+ 'user__username', 'uid', 'average_delay', 'status', 'filename', 'add_time', 'user_id').order_by(
|
|
|
+ '-add_time')[(page - 1) * line:page * line]
|
|
|
+ app_log_list = CommonService.qs_to_list(log_qs)
|
|
|
+ # 添加下载链接
|
|
|
+ aws_s3_client = boto3.client(
|
|
|
+ 's3',
|
|
|
+ region_name=REGION_NAME,
|
|
|
+ aws_access_key_id=ACCESS_KEY_ID,
|
|
|
+ aws_secret_access_key=SECRET_ACCESS_KEY,
|
|
|
+ config=botocore.client.Config(signature_version='s3v4'),
|
|
|
+ )
|
|
|
+ for app_log in app_log_list:
|
|
|
+ filename = app_log['filename']
|
|
|
+ if not filename.endswith('.txt'):
|
|
|
+ filename += ".txt"
|
|
|
+ obj = 'app_log/' + app_log['user_id'] + '/{}'.format(filename)
|
|
|
+ appLog_url = aws_s3_client.generate_presigned_url(
|
|
|
+ ClientMethod='get_object',
|
|
|
+ Params={
|
|
|
+ 'Bucket': LOG_BUCKET,
|
|
|
+ 'Key': obj
|
|
|
+ },
|
|
|
+ ExpiresIn=3600
|
|
|
+ )
|
|
|
+ app_log['appLog_url'] = appLog_url
|
|
|
+ return response.json(0, {'list': app_log_list, 'total': count})
|
|
|
+ except Exception as e:
|
|
|
+ print(e)
|
|
|
+ return response.json(500, repr(e))
|