From 00078d309850d571aad4c5f97a335ff825f9c0b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9B=B7=E4=BA=8C=E7=8C=9B?= Date: Thu, 5 Dec 2019 23:08:37 +0800 Subject: [PATCH] U api monitor update --- spug_api/apps/monitor/models.py | 5 +++++ spug_api/apps/monitor/views.py | 6 +++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/spug_api/apps/monitor/models.py b/spug_api/apps/monitor/models.py index aa5221e..e3c07a6 100644 --- a/spug_api/apps/monitor/models.py +++ b/spug_api/apps/monitor/models.py @@ -1,6 +1,7 @@ from django.db import models from libs import ModelMixin, human_time from apps.account.models import User +import json class Detection(models.Model, ModelMixin): @@ -24,6 +25,8 @@ class Detection(models.Model, ModelMixin): threshold = models.IntegerField(default=3) quiet = models.IntegerField(default=24 * 60) fault_times = models.SmallIntegerField(default=0) + notify_mode = models.CharField(max_length=255) + notify_grp = models.CharField(max_length=255) latest_status = models.SmallIntegerField(choices=STATUS, null=True) latest_run_time = models.CharField(max_length=20, null=True) latest_fault_time = models.IntegerField(null=True) @@ -38,6 +41,8 @@ class Detection(models.Model, ModelMixin): tmp = super().to_dict(*args, **kwargs) tmp['type_alias'] = self.get_type_display() tmp['latest_status_alias'] = self.get_latest_status_display() + tmp['notify_mode'] = json.loads(self.notify_mode) + tmp['notify_grp'] = json.loads(self.notify_grp) return tmp def __repr__(self): diff --git a/spug_api/apps/monitor/views.py b/spug_api/apps/monitor/views.py index 4c32ccc..720a4ba 100644 --- a/spug_api/apps/monitor/views.py +++ b/spug_api/apps/monitor/views.py @@ -21,9 +21,13 @@ class DetectionView(View): Argument('desc', required=False), Argument('rate', type=int, default=5), Argument('threshold', type=int, default=3), - Argument('quiet', type=int, default=24 * 60) + Argument('quiet', type=int, default=24 * 60), + Argument('notify_grp', type=list, help='请选择报警联系组'), + Argument('notify_mode', type=list, help='请选择报警方式'), ).parse(request.body) if error is None: + form.notify_grp = json.dumps(form.notify_grp) + form.notify_mode = json.dumps(form.notify_mode) if form.id: Detection.objects.filter(pk=form.id).update( updated_at=human_time(),