mirror of https://github.com/openspug/spug
U 细化报警服务异常通知
parent
3d75a2c5ac
commit
d47c17914c
|
@ -15,15 +15,13 @@ notify_source = 'info-circle'
|
||||||
|
|
||||||
def _parse_args(grp):
|
def _parse_args(grp):
|
||||||
spug_key = AppSetting.get_default('spug_key')
|
spug_key = AppSetting.get_default('spug_key')
|
||||||
if not spug_key:
|
|
||||||
Notify.make_notify(notify_source, '1', '发送报警信息失败', '未配置报警服务调用凭据,请在系统管理/系统设置/报警服务设置中配置。')
|
|
||||||
return None, None
|
|
||||||
return spug_key, sum([json.loads(x.contacts) for x in Group.objects.filter(id__in=grp)], [])
|
return spug_key, sum([json.loads(x.contacts) for x in Group.objects.filter(id__in=grp)], [])
|
||||||
|
|
||||||
|
|
||||||
def notify_by_wx(event, subject, n_grp):
|
def notify_by_wx(event, subject, n_grp):
|
||||||
spug_key, u_ids = _parse_args(n_grp)
|
spug_key, u_ids = _parse_args(n_grp)
|
||||||
if u_ids is None:
|
if not spug_key:
|
||||||
|
Notify.make_notify(notify_source, '1', '发送报警信息失败', '未配置报警服务调用凭据,请在系统管理/系统设置/报警服务设置中配置。')
|
||||||
return
|
return
|
||||||
users = set(x.wx_token for x in Contact.objects.filter(id__in=u_ids, wx_token__isnull=False))
|
users = set(x.wx_token for x in Contact.objects.filter(id__in=u_ids, wx_token__isnull=False))
|
||||||
if users:
|
if users:
|
||||||
|
@ -34,12 +32,12 @@ def notify_by_wx(event, subject, n_grp):
|
||||||
'users': list(users)
|
'users': list(users)
|
||||||
}
|
}
|
||||||
requests.post(f'{spug_server}/apis/notify/wx/', json=data)
|
requests.post(f'{spug_server}/apis/notify/wx/', json=data)
|
||||||
|
else:
|
||||||
|
Notify.make_notify(notify_source, '1', '发送报警信息失败', '未找到可用的通知对象,请确保设置了相关报警联系人的微信Token。')
|
||||||
|
|
||||||
|
|
||||||
def notify_by_email(event, subject, grp):
|
def notify_by_email(event, subject, grp):
|
||||||
spug_key, u_ids = _parse_args(grp)
|
spug_key, u_ids = _parse_args(grp)
|
||||||
if u_ids is None:
|
|
||||||
return
|
|
||||||
users = set(x.email for x in Contact.objects.filter(id__in=u_ids, email__isnull=False))
|
users = set(x.email for x in Contact.objects.filter(id__in=u_ids, email__isnull=False))
|
||||||
if users:
|
if users:
|
||||||
mail_service = json.loads(AppSetting.get_default('mail_service', '{}'))
|
mail_service = json.loads(AppSetting.get_default('mail_service', '{}'))
|
||||||
|
@ -48,7 +46,7 @@ def notify_by_email(event, subject, grp):
|
||||||
subject = f'{event_map[event]}-{subject}'
|
subject = f'{event_map[event]}-{subject}'
|
||||||
mail = Mail(**mail_service)
|
mail = Mail(**mail_service)
|
||||||
mail.send_text_mail(users, subject, f'{subject}\r\n\r\n自动发送,请勿回复。')
|
mail.send_text_mail(users, subject, f'{subject}\r\n\r\n自动发送,请勿回复。')
|
||||||
else:
|
elif spug_key:
|
||||||
data = {
|
data = {
|
||||||
'token': spug_key,
|
'token': spug_key,
|
||||||
'event': event,
|
'event': event,
|
||||||
|
@ -56,11 +54,16 @@ def notify_by_email(event, subject, grp):
|
||||||
'users': list(users)
|
'users': list(users)
|
||||||
}
|
}
|
||||||
requests.post(f'{spug_server}/apis/notify/mail/', json=data)
|
requests.post(f'{spug_server}/apis/notify/mail/', json=data)
|
||||||
|
else:
|
||||||
|
Notify.make_notify(notify_source, '1', '发送报警信息失败', '未配置报警服务调用凭据,请在系统管理/系统设置/报警服务设置中配置。')
|
||||||
|
else:
|
||||||
|
Notify.make_notify(notify_source, '1', '发送报警信息失败', '未找到可用的通知对象,请确保设置了相关报警联系人的邮件地址。')
|
||||||
|
|
||||||
|
|
||||||
def notify_by_dd(event, subject, grp):
|
def notify_by_dd(event, subject, grp):
|
||||||
spug_key, u_ids = _parse_args(grp)
|
spug_key, u_ids = _parse_args(grp)
|
||||||
if u_ids is None:
|
if not spug_key:
|
||||||
|
Notify.make_notify(notify_source, '1', '发送报警信息失败', '未配置报警服务调用凭据,请在系统管理/系统设置/报警服务设置中配置。')
|
||||||
return
|
return
|
||||||
users = set(x.ding for x in Contact.objects.filter(id__in=u_ids, email__isnull=False))
|
users = set(x.ding for x in Contact.objects.filter(id__in=u_ids, email__isnull=False))
|
||||||
if users:
|
if users:
|
||||||
|
@ -80,3 +83,5 @@ def notify_by_dd(event, subject, grp):
|
||||||
}
|
}
|
||||||
for url in users:
|
for url in users:
|
||||||
requests.post(url, json=data)
|
requests.post(url, json=data)
|
||||||
|
else:
|
||||||
|
Notify.make_notify(notify_source, '1', '发送报警信息失败', '未找到可用的通知对象,请确保设置了相关报警联系人的钉钉。')
|
||||||
|
|
Loading…
Reference in New Issue