/** * Copyright (c) OpenSpug Organization. https://github.com/openspug/spug * Copyright (c) * Released under the AGPL-3.0 License. */ import React, { useState } from 'react'; import { observer } from 'mobx-react'; import { ExclamationCircleOutlined } from '@ant-design/icons'; import { Modal, Form, Input, Select, Button, message } from 'antd'; import TemplateSelector from '../exec/task/TemplateSelector'; import HostSelector from 'pages/host/Selector'; import { LinkButton, ACEditor } from 'components'; import { http, cleanCommand } from 'libs'; import store from './store'; import lds from 'lodash'; const helpMap = { '1': '返回HTTP状态码200-399则判定为正常,其他为异常。', '4': '脚本执行退出状态码为 0 则判定为正常,其他为异常。' } export default observer(function () { const [loading, setLoading] = useState(false); const [showTmp, setShowTmp] = useState(false); function handleTest() { setLoading(true) const formData = lds.pick(store.record, ['type', 'targets', 'extra']) http.post('/api/monitor/test/', formData, {timeout: 120000}) .then(res => { if (res.is_success) { Modal.success({content: res.message}) } else { Modal.warning({content: res.message}) } }) .finally(() => setLoading(false)) } function handleChangeType(v) { store.record.type = v; store.record.targets = []; store.record.extra = undefined; } function handleAddGroup() { Modal.confirm({ icon: , title: '添加监控分组', content: (
store.record.group = e.target.value}/>
), onOk: () => { if (store.record.group) { store.groups.push(store.record.group); } }, }) } function canNext() { const {type, targets, extra, group} = store.record; const is_verify = name && group && targets.length; if (['2', '3', '4'].includes(type)) { return is_verify && extra } else { return is_verify } } function toNext() { const {type, extra} = store.record; if (!Number(extra) > 0) { if (type === '1' && extra) return message.error('请输入正确的响应时间') if (type === '2') return message.error('请输入正确的端口号') } store.page += 1; } function getStyle(t) { return t.includes(store.record.type) ? {} : {display: 'none'} } const {name, desc, type, targets, extra, group} = store.record; return (
store.record.name = e.target.value} placeholder="请输入监控名称"/> store.record.targets = v} placeholder="IP或域名,支持多个地址,每输入完成一个后按回车确认" notFoundContent={null}/> store.record.targets = ids}/> store.record.extra = e.target.value}/> store.record.extra = e.target.value}/> store.record.extra = e.target.value}/> setShowTmp(true)}>从模板添加}> store.record.extra = cleanCommand(e)}/> store.record.desc = e.target.value} placeholder="请输入备注信息"/> Tips: 仅测试第一个监控地址 {showTmp && store.record.extra = body} onCancel={() => setShowTmp(false)}/>} ) })