mirror of https://github.com/openspug/spug
U api monitor update
parent
46015147cd
commit
00078d3098
|
@ -1,6 +1,7 @@
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from libs import ModelMixin, human_time
|
from libs import ModelMixin, human_time
|
||||||
from apps.account.models import User
|
from apps.account.models import User
|
||||||
|
import json
|
||||||
|
|
||||||
|
|
||||||
class Detection(models.Model, ModelMixin):
|
class Detection(models.Model, ModelMixin):
|
||||||
|
@ -24,6 +25,8 @@ class Detection(models.Model, ModelMixin):
|
||||||
threshold = models.IntegerField(default=3)
|
threshold = models.IntegerField(default=3)
|
||||||
quiet = models.IntegerField(default=24 * 60)
|
quiet = models.IntegerField(default=24 * 60)
|
||||||
fault_times = models.SmallIntegerField(default=0)
|
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_status = models.SmallIntegerField(choices=STATUS, null=True)
|
||||||
latest_run_time = models.CharField(max_length=20, null=True)
|
latest_run_time = models.CharField(max_length=20, null=True)
|
||||||
latest_fault_time = models.IntegerField(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 = super().to_dict(*args, **kwargs)
|
||||||
tmp['type_alias'] = self.get_type_display()
|
tmp['type_alias'] = self.get_type_display()
|
||||||
tmp['latest_status_alias'] = self.get_latest_status_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
|
return tmp
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
|
|
|
@ -21,9 +21,13 @@ class DetectionView(View):
|
||||||
Argument('desc', required=False),
|
Argument('desc', required=False),
|
||||||
Argument('rate', type=int, default=5),
|
Argument('rate', type=int, default=5),
|
||||||
Argument('threshold', type=int, default=3),
|
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)
|
).parse(request.body)
|
||||||
if error is None:
|
if error is None:
|
||||||
|
form.notify_grp = json.dumps(form.notify_grp)
|
||||||
|
form.notify_mode = json.dumps(form.notify_mode)
|
||||||
if form.id:
|
if form.id:
|
||||||
Detection.objects.filter(pk=form.id).update(
|
Detection.objects.filter(pk=form.id).update(
|
||||||
updated_at=human_time(),
|
updated_at=human_time(),
|
||||||
|
|
Loading…
Reference in New Issue