diff --git a/spug_api/apps/alarm/views.py b/spug_api/apps/alarm/views.py index 882a78d4..f52694cf 100644 --- a/spug_api/apps/alarm/views.py +++ b/spug_api/apps/alarm/views.py @@ -55,17 +55,20 @@ def delete(self, request): 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 5186d868..2125a134 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 e82d8037..6f76182f 100644 --- a/spug_api/libs/spug.py +++ b/spug_api/libs/spug.py @@ -161,6 +161,7 @@ def monitor_by_spug_push(self, targets): 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 516533c4..05fff888 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 (