From 3d83dbb1176aa064c4f73c4315258fbd0875ce54 Mon Sep 17 00:00:00 2001 From: vapao Date: Wed, 8 Nov 2023 18:08:43 +0800 Subject: [PATCH] =?UTF-8?q?#=20=E4=BB=BB=E5=8A=A1=E5=A4=B1=E8=B4=A5?= =?UTF-8?q?=E9=80=9A=E7=9F=A5=E9=9B=86=E6=88=90=E6=8E=A8=E9=80=81=E5=8A=A9?= =?UTF-8?q?=E6=89=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spug_api/apps/alarm/views.py | 7 ++- spug_api/apps/schedule/utils.py | 17 +++++++ spug_api/libs/spug.py | 1 + spug_web/src/pages/schedule/Step1.js | 66 ++++++++++++++++++---------- 4 files changed, 67 insertions(+), 24 deletions(-) diff --git a/spug_api/apps/alarm/views.py b/spug_api/apps/alarm/views.py index 882a78d..f52694c 100644 --- a/spug_api/apps/alarm/views.py +++ b/spug_api/apps/alarm/views.py @@ -55,17 +55,20 @@ class GroupView(View): class ContactView(View): - @auth('alarm.contact.view|alarm.group.view') + @auth('alarm.contact.view|alarm.group.view|schedule.schedule.add|schedule.schedule.edit') def get(self, request): form, error = JsonParser( Argument('with_push', required=False), + Argument('only_push', required=False), ).parse(request.GET) if error is None: response = [] - if form.with_push: + if form.with_push or form.only_push: push_key = AppSetting.get('spug_push_key') if push_key: response = get_contacts(push_key) + if form.only_push: + return json_response(response) for item in Contact.objects.all(): response.append(item.to_dict()) diff --git a/spug_api/apps/schedule/utils.py b/spug_api/apps/schedule/utils.py index 5186d86..2125a13 100644 --- a/spug_api/apps/schedule/utils.py +++ b/spug_api/apps/schedule/utils.py @@ -3,6 +3,8 @@ # Released under the AGPL-3.0 License. from libs.utils import human_datetime from libs.spug import Notification +from libs.push import push_server +from apps.setting.utils import AppSetting import json @@ -79,3 +81,18 @@ def _do_notify(task, mode, url, msg): } } Notification.handle_request(url, data, 'fs') + elif mode == '5': + spug_push_key = AppSetting.get_default('spug_push_key') + if not spug_push_key: + return + data = { + 'source': 'schedule', + 'token': spug_push_key, + 'targets': url, + 'dataset': { + 'name': task.name, + 'type': task.type, + 'message': msg or '请在任务计划执行历史中查看详情', + } + } + Notification.handle_request(f'{push_server}/spug/message/', data, 'spug') diff --git a/spug_api/libs/spug.py b/spug_api/libs/spug.py index e82d803..6f76182 100644 --- a/spug_api/libs/spug.py +++ b/spug_api/libs/spug.py @@ -161,6 +161,7 @@ class Notification: make_no_push_key_notify() return data = { + 'source': 'monitor', 'token': self.spug_push_key, 'targets': list(targets), 'dataset': { diff --git a/spug_web/src/pages/schedule/Step1.js b/spug_web/src/pages/schedule/Step1.js index 516533c..05fff88 100644 --- a/spug_web/src/pages/schedule/Step1.js +++ b/spug_web/src/pages/schedule/Step1.js @@ -1,16 +1,25 @@ -import React, { useState } from 'react'; -import { observer } from 'mobx-react'; -import { Form, Input, Select, Modal, Button, Radio } from 'antd'; -import { ExclamationCircleOutlined } from '@ant-design/icons'; -import { LinkButton, ACEditor } from 'components'; +import React, {useState, useEffect} from 'react'; +import {observer} from 'mobx-react'; +import {Form, Input, Select, Modal, Button, Radio} from 'antd'; +import {ExclamationCircleOutlined} from '@ant-design/icons'; +import {LinkButton, ACEditor} from 'components'; import TemplateSelector from '../exec/task/TemplateSelector'; -import { cleanCommand } from 'libs'; +import {cleanCommand, http} from 'libs'; import store from './store'; export default observer(function () { const [form] = Form.useForm(); const [showTmp, setShowTmp] = useState(false); const [command, setCommand] = useState(store.record.command || ''); + const [rstValue, setRstValue] = useState({}); + const [contacts, setContacts] = useState([]); + + useEffect(() => { + const {mode, value} = store.record.rst_notify + setRstValue({[mode]: value}) + http.get('/api/alarm/contact/?only_push=1') + .then(res => setContacts(res)) + }, []); function handleAddZone() { let type; @@ -39,8 +48,10 @@ export default observer(function () { } function handleNext() { - store.page += 1; + const notifyMode = store.record.rst_notify.mode + store.record.rst_notify.value = rstValue[notifyMode] Object.assign(store.record, form.getFieldsValue(), {command: cleanCommand(command)}) + store.page += 1; } function handleSelect(tpl) { @@ -67,6 +78,7 @@ export default observer(function () { modePlaceholder = '请输入' } + const notifyMode = store.record.rst_notify.mode return (
@@ -104,21 +116,31 @@ export default observer(function () { 钉钉收不到通知? )}> - store.record.rst_notify.value = e.target.value} - addonBefore={( - - )} - disabled={store.record.rst_notify.mode === '0'} - placeholder={modePlaceholder}/> + + + + setRstValue(Object.assign({}, rstValue, {[notifyMode]: e.target.value}))} + disabled={notifyMode === '0'} + placeholder={modePlaceholder}/> +