fix issues

pull/342/head
vapao 2021-07-06 00:31:16 +08:00
parent 4c9975202b
commit 902cfbe89f
3 changed files with 5 additions and 5 deletions

View File

@ -18,7 +18,7 @@ logging.captureWarnings(True)
def site_check(url, limit): def site_check(url, limit):
try: try:
res = requests.get(url, timeout=10, verify=False) res = requests.get(url, timeout=10)
if limit: if limit:
duration = int(res.elapsed.total_seconds() * 1000) duration = int(res.elapsed.total_seconds() * 1000)
if duration > int(limit): if duration > int(limit):

View File

@ -39,8 +39,8 @@ class Detection(models.Model, ModelMixin):
updated_at = models.CharField(max_length=20, null=True) updated_at = models.CharField(max_length=20, null=True)
updated_by = models.ForeignKey(User, models.PROTECT, related_name='+', null=True) updated_by = models.ForeignKey(User, models.PROTECT, related_name='+', null=True)
def to_dict(self, *args, **kwargs): def to_view(self):
tmp = super().to_dict(*args, **kwargs) tmp = self.to_dict()
tmp['type_alias'] = self.get_type_display() tmp['type_alias'] = self.get_type_display()
tmp['notify_mode'] = json.loads(self.notify_mode) tmp['notify_mode'] = json.loads(self.notify_mode)
tmp['notify_grp'] = json.loads(self.notify_grp) tmp['notify_grp'] = json.loads(self.notify_grp)

View File

@ -14,7 +14,7 @@ class DetectionView(View):
def get(self, request): def get(self, request):
detections = Detection.objects.all() detections = Detection.objects.all()
groups = [x['group'] for x in detections.order_by('group').values('group').distinct()] groups = [x['group'] for x in detections.order_by('group').values('group').distinct()]
return json_response({'groups': groups, 'detections': [x.to_dict() for x in detections]}) return json_response({'groups': groups, 'detections': [x.to_view() for x in detections]})
def post(self, request): def post(self, request):
form, error = JsonParser( form, error = JsonParser(
@ -64,7 +64,7 @@ class DetectionView(View):
if form.is_active: if form.is_active:
task = Detection.objects.filter(pk=form.id).first() task = Detection.objects.filter(pk=form.id).first()
message = {'id': form.id, 'action': 'add'} message = {'id': form.id, 'action': 'add'}
message.update(task.to_dict(selects=('targets', 'extra', 'rate', 'type'))) message.update(task.to_dict(selects=('targets', 'extra', 'rate', 'type', 'threshold', 'quiet')))
else: else:
message = {'id': form.id, 'action': 'remove'} message = {'id': form.id, 'action': 'remove'}
rds_cli = get_redis_connection() rds_cli = get_redis_connection()