import http from '@/api'; import { ResPage } from '@/api/interface'; import { Alert } from '../interface/alert'; import { deepCopy } from '@/utils/misc'; import { GlobalStore } from '@/store'; const alertConfigHiddenTypes = ['sms']; const resolveAlertConfigExcludeTypes = (excludeTypes: string[] = []) => { const globalStore = GlobalStore(); const types = new Set(excludeTypes); if (globalStore.isIntl || globalStore.isEE || !globalStore.isProductPro) { alertConfigHiddenTypes.forEach((type) => types.add(type)); } return Array.from(types); }; export const SearchAlerts = (req: Alert.AlertSearch, currentNode?: string) => { return http.post>( `/alert/search`, req, undefined, currentNode ? { CurrentNode: currentNode } : undefined, ); }; export const CreateAlert = (req: Alert.AlertCreateReq) => { let request = deepCopy(req) as Alert.AlertCreateReq; return http.post(`/alert`, request); }; export const UpdateAlert = (req: Alert.AlertUpdateReq) => { return http.post(`/alert/update`, req); }; export const DeleteAlert = (req: Alert.DelReq) => { return http.post(`/alert/del`, req); }; export const UpdateAlertStatus = (req: Alert.AlertUpdateStatusReq) => { return http.post(`/alert/status`, req); }; export const ListDisks = () => { return http.get(`/alert/disks/list`); }; export const SearchAlertLogs = (req: Alert.AlertLogSearch, currentNode?: string) => { return http.post>( `/alert/logs/search`, req, undefined, currentNode ? { CurrentNode: currentNode } : undefined, ); }; export const CleanAlertLogs = () => { return http.post(`/alert/logs/clean`); }; export const ListClams = () => { return http.get(`/alert/clams/list`); }; export const ListCronJob = (req: Alert.CronJobReq) => { return http.post(`/alert/cronjob/list`, req); }; export const ListAlertConfigs = (req: Alert.AlertConfigFilterReq = {}, currentNode?: string) => { const request = { ...req, excludeTypes: resolveAlertConfigExcludeTypes(req.excludeTypes), }; return http.post( `/alert/config/info`, request, undefined, currentNode ? { CurrentNode: currentNode } : undefined, ); }; export const PageAlertConfigs = (req: Alert.AlertConfigPageReq, currentNode?: string) => { const request = { ...req, excludeTypes: resolveAlertConfigExcludeTypes(req.excludeTypes), }; return http.post>( `/alert/config/search`, request, undefined, currentNode ? { CurrentNode: currentNode } : undefined, ); }; export const DeleteAlertConfig = (req: Alert.DelReq) => { return http.post(`/alert/config/del`, req); }; export const UpdateAlertConfig = (req: Alert.AlertConfigUpdateReq) => { return http.post(`/alert/config/update`, req); }; export const UpdateAlertConfigStatus = (req: Alert.AlertConfigStatusReq) => { return http.post(`/alert/config/status`, req); }; export const TestAlertConfig = (req: Alert.AlertConfigTest) => { return http.post(`/alert/config/test`, req); }; export const TestCustomAlertConfig = (req: Alert.AlertConfigCustomTest) => { return http.post(`/alert/config/test`, req); }; export const SyncAlertInfo = (req: Alert.AlertLogId) => { return http.post(`/xpack/alert/logs/sync`, req); }; export const SyncAlertAll = () => { return http.post(`/xpack/alert/logs/sync/all`); }; export const SyncOfflineAlert = () => { return http.post(`/core/xpack/alert/offline/sync`); };