refactor(frontend): P1-P2 架构统一 — utils/hooks/api 模块化
P1: - utils/storage.ts、theme.ts、validate.ts + index 统一出口 - request/store/useTheme 接入 storage;清零 confirm/alert - PipelineManager、TerminalAuditTab 拆分子模块(<700行红线) P2: - api/monitor、api/deploy 子目录化 - hooks/api 扩展:servers/pipelines/alerts/audit/sessionCommands - PipelineManager、AuditOperationsTab 接入 TanStack Query
This commit is contained in:
1 parent
d19a03d427
commit
f45e203e21
196 files changed
+3228
-2018
No files matched your search
+2
-153
@@ -1,154 +1,3 @@
|
||||
// CI/CD 流水线/发布配置/凭证
|
||||
// 从 services/api.ts 拆分 — Q3 api.ts 模块化
|
||||
// CI/CD API — 子模块 re-export(保持 @/api 导入路径不变) // Logan.Li
|
||||
|
||||
import { http, type ListResponse } from '@/utils/request';
|
||||
|
||||
export const pipelineApi = {
|
||||
getPipelines: async (params?: { page?: number; page_size?: number }) => {
|
||||
return http.get<ListResponse>('/pipelines', params);
|
||||
},
|
||||
getPipelineDetail: async (id: number | string) => {
|
||||
return http.get(`/pipelines/${id}`);
|
||||
},
|
||||
createPipeline: async ( data: any) => {
|
||||
return http.post('/pipelines', data);
|
||||
},
|
||||
updatePipeline: async (id: number | string, data: any) => {
|
||||
return http.put(`/pipelines/${id}`, data);
|
||||
},
|
||||
deletePipeline: async (id: number | string) => {
|
||||
return http.delete(`/pipelines/${id}`);
|
||||
},
|
||||
triggerPipeline: async (id: number | string) => {
|
||||
return http.post(`/pipelines/${id}/trigger`);
|
||||
},
|
||||
getRuns: async (id: number | string) => {
|
||||
return http.get(`/pipelines/${id}/runs`);
|
||||
},
|
||||
// 运行控制
|
||||
stopRun: async (pipelineId: number | string, runId: number | string) => {
|
||||
return http.post(`/pipelines/${pipelineId}/runs/${runId}/stop`);
|
||||
},
|
||||
getRunLog: async (pipelineId: number | string, runId: number | string) => {
|
||||
return http.get(`/pipelines/${pipelineId}/runs/${runId}/log`);
|
||||
},
|
||||
// 成员管理
|
||||
getMembers: async (pipelineId: number | string) => {
|
||||
return http.get(`/pipelines/${pipelineId}/members`);
|
||||
},
|
||||
addMember: async (pipelineId: number | string, data: { username: string; role: string }) => {
|
||||
return http.post(`/pipelines/${pipelineId}/members`, data);
|
||||
},
|
||||
removeMember: async (pipelineId: number | string, memberId: number | string) => {
|
||||
return http.delete(`/pipelines/${pipelineId}/members/${memberId}`);
|
||||
},
|
||||
// 组授权
|
||||
assignGroup: async (pipelineId: number | string, data: { group_id: number; role: string }) => {
|
||||
return http.post(`/pipelines/${pipelineId}/groups`, data);
|
||||
},
|
||||
// 按 code 操作(列表页/详情页常用) // Logan.Li
|
||||
getByCode: (code: string) => http.get(`/pipelines/${code}`),
|
||||
getRunsByCode: (code: string, pageSize = 50) =>
|
||||
http.get<ListResponse>(`/pipelines/${code}/runs`, { page_size: pageSize }),
|
||||
triggerByCode: (code: string) => http.post(`/pipelines/${code}/trigger`, {}),
|
||||
stopRunByCode: (code: string, runId: number | string) =>
|
||||
http.post(`/pipelines/${code}/runs/${runId}/stop`, {}),
|
||||
batchDeleteRuns: (code: string, ids: number[]) =>
|
||||
http.post(`/pipelines/${code}/runs/batch-delete`, { ids }),
|
||||
getRunLogStream: (runId: number | string) => http.get(`/pipelines/runs/${runId}/log-stream`),
|
||||
getQueue: (code: string) => http.get(`/pipelines/${code}/queue`),
|
||||
removeFromQueue: (code: string, runId: number | string) =>
|
||||
http.delete(`/pipelines/${code}/queue/${runId}`),
|
||||
getWorkspace: (runId: number | string) => http.get(`/pipelines/runs/${runId}/workspace`),
|
||||
listRunFiles: (runId: number | string, path?: string) =>
|
||||
http.get(`/pipelines/runs/${runId}/files`, path ? { path } : undefined),
|
||||
};
|
||||
|
||||
// ==================== 应用发布 API ====================
|
||||
|
||||
export const releaseApi = {
|
||||
getReleases: async (params?: { page?: number; page_size?: number }) => {
|
||||
return http.get<ListResponse>('/releases', params);
|
||||
},
|
||||
createRelease: async ( data: any) => {
|
||||
return http.post('/releases', data);
|
||||
},
|
||||
approveRelease: async (id: number | string) => {
|
||||
return http.post(`/releases/${id}/approve`);
|
||||
},
|
||||
rejectRelease: async (id: number | string) => {
|
||||
return http.post(`/releases/${id}/reject`);
|
||||
},
|
||||
deployRelease: async (id: number | string) => {
|
||||
return http.post(`/releases/${id}/deploy`);
|
||||
},
|
||||
rollbackRelease: async (id: number | string) => {
|
||||
return http.post(`/releases/${id}/rollback`);
|
||||
},
|
||||
};
|
||||
|
||||
// ==================== 定时任务 API ====================
|
||||
|
||||
export const deployApi = {
|
||||
// Git 仓库认证
|
||||
getRepos: () => http.get<ListResponse>('/deploy/repos'),
|
||||
getRepo: (id: number | string) => http.get(`/deploy/repos/${id}`),
|
||||
createRepo: ( data: any) => http.post('/deploy/repos', data),
|
||||
updateRepo: (id: number | string, data: any) => http.put(`/deploy/repos/${id}`, data),
|
||||
deleteRepo: (id: number | string) => http.delete(`/deploy/repos/${id}`),
|
||||
// 镜像仓库认证
|
||||
getRegistries: () => http.get<ListResponse>('/deploy/registries'),
|
||||
getRegistry: (id: number | string) => http.get(`/deploy/registries/${id}`),
|
||||
createRegistry: ( data: any) => http.post('/deploy/registries', data),
|
||||
updateRegistry: (id: number | string, data: any) => http.put(`/deploy/registries/${id}`, data),
|
||||
deleteRegistry: (id: number | string) => http.delete(`/deploy/registries/${id}`),
|
||||
// 环境管理
|
||||
getEnvironments: () => http.get<ListResponse>('/deploy/environments'),
|
||||
createEnvironment: ( data: any) => http.post('/deploy/environments', data),
|
||||
updateEnvironment: (id: number | string, data: any) => http.put(`/deploy/environments/${id}`, data),
|
||||
deleteEnvironment: (id: number | string) => http.delete(`/deploy/environments/${id}`),
|
||||
// Item Role 权限管理 (Jenkins Role Strategy 风格)
|
||||
getItemRoles: () => http.get<ListResponse>('/admin/item-roles'),
|
||||
createItemRole: ( data: any) => http.post('/admin/item-roles', data),
|
||||
updateItemRole: (id: number | string, data: any) => http.put(`/admin/item-roles/${id}`, data),
|
||||
deleteItemRole: (id: number | string) => http.delete(`/admin/item-roles/${id}`),
|
||||
getUserItemRoles: (userId: number | string) => http.get(`/admin/users/${userId}/item-roles`),
|
||||
assignItemRole: (userId: number | string, data: { user_id: number; item_role_id: number }) => http.post(`/admin/users/${userId}/item-roles`, data),
|
||||
removeItemRole: (userId: number | string, roleId: number | string) => http.delete(`/admin/users/${userId}/item-roles/${roleId}`),
|
||||
// 用户组管理
|
||||
getGroups: () => http.get<ListResponse>('/deploy/groups'),
|
||||
createGroup: ( data: any) => http.post('/deploy/groups', data),
|
||||
updateGroup: (id: number | string, data: any) => http.put(`/deploy/groups/${id}`, data),
|
||||
deleteGroup: (id: number | string) => http.delete(`/deploy/groups/${id}`),
|
||||
getGroupMembers: (id: number | string) => http.get(`/deploy/groups/${id}/members`),
|
||||
addGroupMember: (id: number | string, data: { username: string }) => http.post(`/deploy/groups/${id}/members`, data),
|
||||
removeGroupMember: (id: number | string, memberId: number | string) => http.delete(`/deploy/groups/${id}/members/${memberId}`),
|
||||
// 工具配置 // Logan.Li
|
||||
getTools: () => http.get<ListResponse>('/deploy/tools'),
|
||||
getTool: (id: number | string) => http.get(`/deploy/tools/${id}`),
|
||||
updateTool: (id: number | string, data: any) => http.put(`/deploy/tools/${id}`, data),
|
||||
installTool: (id: number | string, version?: string) =>
|
||||
http.post(`/deploy/tools/${id}/install`, version ? { version } : {}),
|
||||
checkTool: (id: number | string) => http.post(`/deploy/tools/${id}/check`),
|
||||
getToolVersions: (id: number | string) => http.get(`/deploy/tools/${id}/versions`),
|
||||
};
|
||||
|
||||
// ==================== Ansible 自动化 API ====================
|
||||
|
||||
export const credentialApi = {
|
||||
list: (params?: { page?: number; page_size?: number; secret_type?: string; search?: string }) =>
|
||||
http.get<{ list: any[]; total: number }>('/credentials', params),
|
||||
get: (id: number | string) => http.get(`/credentials/${id}`),
|
||||
create: (data: Record<string, unknown>) => http.post('/credentials', data),
|
||||
update: (id: number | string, data: Record<string, unknown>) => http.put(`/credentials/${id}`, data),
|
||||
delete: (id: number | string) => http.delete(`/credentials/${id}`),
|
||||
toggleActive: (id: number | string, isActive: boolean) =>
|
||||
http.put(`/credentials/${id}`, { is_active: isActive }),
|
||||
};
|
||||
|
||||
// 服务器凭据关联 API
|
||||
|
||||
export const serverCredentialApi = {
|
||||
assign: (serverId: number | string, credentialId: number) =>
|
||||
http.post(`/servers/${serverId}/assign-credential`, { credential_id: credentialId }),
|
||||
};
|
||||
export * from './deploy/index';
|
||||
@@ -0,0 +1,47 @@
|
||||
// 部署配置:仓库 / 镜像 / 环境 / 组 / 工具 / Item Role // Logan.Li
|
||||
|
||||
import { http, type ListResponse } from '@/utils/request';
|
||||
|
||||
export const deployApi = {
|
||||
// Git 仓库认证
|
||||
getRepos: () => http.get<ListResponse>('/deploy/repos'),
|
||||
getRepo: (id: number | string) => http.get(`/deploy/repos/${id}`),
|
||||
createRepo: ( data: any) => http.post('/deploy/repos', data),
|
||||
updateRepo: (id: number | string, data: any) => http.put(`/deploy/repos/${id}`, data),
|
||||
deleteRepo: (id: number | string) => http.delete(`/deploy/repos/${id}`),
|
||||
// 镜像仓库认证
|
||||
getRegistries: () => http.get<ListResponse>('/deploy/registries'),
|
||||
getRegistry: (id: number | string) => http.get(`/deploy/registries/${id}`),
|
||||
createRegistry: ( data: any) => http.post('/deploy/registries', data),
|
||||
updateRegistry: (id: number | string, data: any) => http.put(`/deploy/registries/${id}`, data),
|
||||
deleteRegistry: (id: number | string) => http.delete(`/deploy/registries/${id}`),
|
||||
// 环境管理
|
||||
getEnvironments: () => http.get<ListResponse>('/deploy/environments'),
|
||||
createEnvironment: ( data: any) => http.post('/deploy/environments', data),
|
||||
updateEnvironment: (id: number | string, data: any) => http.put(`/deploy/environments/${id}`, data),
|
||||
deleteEnvironment: (id: number | string) => http.delete(`/deploy/environments/${id}`),
|
||||
// Item Role 权限管理 (Jenkins Role Strategy 风格)
|
||||
getItemRoles: () => http.get<ListResponse>('/admin/item-roles'),
|
||||
createItemRole: ( data: any) => http.post('/admin/item-roles', data),
|
||||
updateItemRole: (id: number | string, data: any) => http.put(`/admin/item-roles/${id}`, data),
|
||||
deleteItemRole: (id: number | string) => http.delete(`/admin/item-roles/${id}`),
|
||||
getUserItemRoles: (userId: number | string) => http.get(`/admin/users/${userId}/item-roles`),
|
||||
assignItemRole: (userId: number | string, data: { user_id: number; item_role_id: number }) => http.post(`/admin/users/${userId}/item-roles`, data),
|
||||
removeItemRole: (userId: number | string, roleId: number | string) => http.delete(`/admin/users/${userId}/item-roles/${roleId}`),
|
||||
// 用户组管理
|
||||
getGroups: () => http.get<ListResponse>('/deploy/groups'),
|
||||
createGroup: ( data: any) => http.post('/deploy/groups', data),
|
||||
updateGroup: (id: number | string, data: any) => http.put(`/deploy/groups/${id}`, data),
|
||||
deleteGroup: (id: number | string) => http.delete(`/deploy/groups/${id}`),
|
||||
getGroupMembers: (id: number | string) => http.get(`/deploy/groups/${id}/members`),
|
||||
addGroupMember: (id: number | string, data: { username: string }) => http.post(`/deploy/groups/${id}/members`, data),
|
||||
removeGroupMember: (id: number | string, memberId: number | string) => http.delete(`/deploy/groups/${id}/members/${memberId}`),
|
||||
// 工具配置
|
||||
getTools: () => http.get<ListResponse>('/deploy/tools'),
|
||||
getTool: (id: number | string) => http.get(`/deploy/tools/${id}`),
|
||||
updateTool: (id: number | string, data: any) => http.put(`/deploy/tools/${id}`, data),
|
||||
installTool: (id: number | string, version?: string) =>
|
||||
http.post(`/deploy/tools/${id}/install`, version ? { version } : {}),
|
||||
checkTool: (id: number | string) => http.post(`/deploy/tools/${id}/check`),
|
||||
getToolVersions: (id: number | string) => http.get(`/deploy/tools/${id}/versions`),
|
||||
};
|
||||
@@ -0,0 +1,19 @@
|
||||
// 凭据 / 服务器凭据关联 API // Logan.Li
|
||||
|
||||
import { http } from '@/utils/request';
|
||||
|
||||
export const credentialApi = {
|
||||
list: (params?: { page?: number; page_size?: number; secret_type?: string; search?: string }) =>
|
||||
http.get<{ list: any[]; total: number }>('/credentials', params),
|
||||
get: (id: number | string) => http.get(`/credentials/${id}`),
|
||||
create: (data: Record<string, unknown>) => http.post('/credentials', data),
|
||||
update: (id: number | string, data: Record<string, unknown>) => http.put(`/credentials/${id}`, data),
|
||||
delete: (id: number | string) => http.delete(`/credentials/${id}`),
|
||||
toggleActive: (id: number | string, isActive: boolean) =>
|
||||
http.put(`/credentials/${id}`, { is_active: isActive }),
|
||||
};
|
||||
|
||||
export const serverCredentialApi = {
|
||||
assign: (serverId: number | string, credentialId: number) =>
|
||||
http.post(`/servers/${serverId}/assign-credential`, { credential_id: credentialId }),
|
||||
};
|
||||
@@ -0,0 +1,6 @@
|
||||
// CI/CD API 聚合出口 // Logan.Li
|
||||
|
||||
export { pipelineApi } from './pipeline';
|
||||
export { releaseApi } from './release';
|
||||
export { deployApi } from './config';
|
||||
export { credentialApi, serverCredentialApi } from './credential';
|
||||
@@ -0,0 +1,64 @@
|
||||
// CI/CD 流水线 API // Logan.Li
|
||||
|
||||
import { http, type ListResponse } from '@/utils/request';
|
||||
|
||||
export const pipelineApi = {
|
||||
getPipelines: async (params?: { page?: number; page_size?: number }) => {
|
||||
return http.get<ListResponse>('/pipelines', params);
|
||||
},
|
||||
getPipelineDetail: async (id: number | string) => {
|
||||
return http.get(`/pipelines/${id}`);
|
||||
},
|
||||
createPipeline: async ( data: any) => {
|
||||
return http.post('/pipelines', data);
|
||||
},
|
||||
updatePipeline: async (id: number | string, data: any) => {
|
||||
return http.put(`/pipelines/${id}`, data);
|
||||
},
|
||||
deletePipeline: async (id: number | string) => {
|
||||
return http.delete(`/pipelines/${id}`);
|
||||
},
|
||||
triggerPipeline: async (id: number | string) => {
|
||||
return http.post(`/pipelines/${id}/trigger`);
|
||||
},
|
||||
getRuns: async (id: number | string) => {
|
||||
return http.get(`/pipelines/${id}/runs`);
|
||||
},
|
||||
// 运行控制
|
||||
stopRun: async (pipelineId: number | string, runId: number | string) => {
|
||||
return http.post(`/pipelines/${pipelineId}/runs/${runId}/stop`);
|
||||
},
|
||||
getRunLog: async (pipelineId: number | string, runId: number | string) => {
|
||||
return http.get(`/pipelines/${pipelineId}/runs/${runId}/log`);
|
||||
},
|
||||
// 成员管理
|
||||
getMembers: async (pipelineId: number | string) => {
|
||||
return http.get(`/pipelines/${pipelineId}/members`);
|
||||
},
|
||||
addMember: async (pipelineId: number | string, data: { username: string; role: string }) => {
|
||||
return http.post(`/pipelines/${pipelineId}/members`, data);
|
||||
},
|
||||
removeMember: async (pipelineId: number | string, memberId: number | string) => {
|
||||
return http.delete(`/pipelines/${pipelineId}/members/${memberId}`);
|
||||
},
|
||||
// 组授权
|
||||
assignGroup: async (pipelineId: number | string, data: { group_id: number; role: string }) => {
|
||||
return http.post(`/pipelines/${pipelineId}/groups`, data);
|
||||
},
|
||||
// 按 code 操作(列表页/详情页常用)
|
||||
getByCode: (code: string) => http.get(`/pipelines/${code}`),
|
||||
getRunsByCode: (code: string, pageSize = 50) =>
|
||||
http.get<ListResponse>(`/pipelines/${code}/runs`, { page_size: pageSize }),
|
||||
triggerByCode: (code: string) => http.post(`/pipelines/${code}/trigger`, {}),
|
||||
stopRunByCode: (code: string, runId: number | string) =>
|
||||
http.post(`/pipelines/${code}/runs/${runId}/stop`, {}),
|
||||
batchDeleteRuns: (code: string, ids: number[]) =>
|
||||
http.post(`/pipelines/${code}/runs/batch-delete`, { ids }),
|
||||
getRunLogStream: (runId: number | string) => http.get(`/pipelines/runs/${runId}/log-stream`),
|
||||
getQueue: (code: string) => http.get(`/pipelines/${code}/queue`),
|
||||
removeFromQueue: (code: string, runId: number | string) =>
|
||||
http.delete(`/pipelines/${code}/queue/${runId}`),
|
||||
getWorkspace: (runId: number | string) => http.get(`/pipelines/runs/${runId}/workspace`),
|
||||
listRunFiles: (runId: number | string, path?: string) =>
|
||||
http.get(`/pipelines/runs/${runId}/files`, path ? { path } : undefined),
|
||||
};
|
||||
@@ -0,0 +1,24 @@
|
||||
// 应用发布 API // Logan.Li
|
||||
|
||||
import { http, type ListResponse } from '@/utils/request';
|
||||
|
||||
export const releaseApi = {
|
||||
getReleases: async (params?: { page?: number; page_size?: number }) => {
|
||||
return http.get<ListResponse>('/releases', params);
|
||||
},
|
||||
createRelease: async ( data: any) => {
|
||||
return http.post('/releases', data);
|
||||
},
|
||||
approveRelease: async (id: number | string) => {
|
||||
return http.post(`/releases/${id}/approve`);
|
||||
},
|
||||
rejectRelease: async (id: number | string) => {
|
||||
return http.post(`/releases/${id}/reject`);
|
||||
},
|
||||
deployRelease: async (id: number | string) => {
|
||||
return http.post(`/releases/${id}/deploy`);
|
||||
},
|
||||
rollbackRelease: async (id: number | string) => {
|
||||
return http.post(`/releases/${id}/rollback`);
|
||||
},
|
||||
};
|
||||
+2
-221
@@ -1,222 +1,3 @@
|
||||
// 监控告警 (规则/通知/大屏/Prometheus/Zabbix)
|
||||
// 从 services/api.ts 拆分 — Q3 api.ts 模块化
|
||||
|
||||
import { http, type ListResponse } from '@/utils/request';
|
||||
|
||||
export const alertApi = {
|
||||
getAlerts: async (params?: { page?: number; page_size?: number; status?: string; severity?: string }) => {
|
||||
return http.get<ListResponse>('/alerts', params);
|
||||
},
|
||||
getRules: async () => {
|
||||
return http.get('/alerts/rules');
|
||||
},
|
||||
createRule: async ( data: any) => {
|
||||
return http.post('/alerts/rules', data);
|
||||
},
|
||||
updateRule: async (id: number | string, data: any) => {
|
||||
return http.put(`/alerts/rules/${id}`, data);
|
||||
},
|
||||
deleteRule: async (id: number | string) => {
|
||||
return http.delete(`/alerts/rules/${id}`);
|
||||
},
|
||||
batchDeleteRules: async (ids: number[]) => {
|
||||
return http.delete('/alerts/rules/batch-delete', { ids });
|
||||
},
|
||||
toggleRule: async (id: number | string) => {
|
||||
return http.post(`/alerts/rules/${id}/toggle`);
|
||||
},
|
||||
acknowledge: async (id: number | string) => {
|
||||
return http.post(`/alerts/${id}/ack`);
|
||||
},
|
||||
// 通知渠道管理
|
||||
getNotifyChannels: async () => {
|
||||
return http.get('/alerts/notify-channels');
|
||||
},
|
||||
createNotifyChannel: async ( data: any) => {
|
||||
return http.post('/alerts/notify-channels', data);
|
||||
},
|
||||
updateNotifyChannel: async (id: number | string, data: any) => {
|
||||
return http.put(`/alerts/notify-channels/${id}`, data);
|
||||
},
|
||||
deleteNotifyChannel: async (id: number | string) => {
|
||||
return http.delete(`/alerts/notify-channels/${id}`);
|
||||
},
|
||||
testNotifyChannel: async (id: number | string) => {
|
||||
return http.post(`/alerts/notify-channels/${id}/test`);
|
||||
},
|
||||
// 报警联系人
|
||||
getContacts: async () => {
|
||||
return http.get('/alerts/contacts');
|
||||
},
|
||||
createContact: async ( data: any) => {
|
||||
return http.post('/alerts/contacts', data);
|
||||
},
|
||||
updateContact: async (id: number | string, data: any) => {
|
||||
return http.put(`/alerts/contacts/${id}`, data);
|
||||
},
|
||||
deleteContact: async (id: number | string) => {
|
||||
return http.delete(`/alerts/contacts/${id}`);
|
||||
},
|
||||
// 报警联系组
|
||||
getContactGroups: async () => {
|
||||
return http.get('/alerts/contact-groups');
|
||||
},
|
||||
createContactGroup: async ( data: any) => {
|
||||
return http.post('/alerts/contact-groups', data);
|
||||
},
|
||||
updateContactGroup: async (id: number | string, data: any) => {
|
||||
return http.put(`/alerts/contact-groups/${id}`, data);
|
||||
},
|
||||
deleteContactGroup: async (id: number | string) => {
|
||||
return http.delete(`/alerts/contact-groups/${id}`);
|
||||
},
|
||||
};
|
||||
|
||||
// ==================== 流水线 API ====================
|
||||
|
||||
export const alertCenterApi = {
|
||||
getAlerts: async (params?: { page?: number; page_size?: number; status?: string; severity?: string }) => {
|
||||
return http.get<ListResponse>('/alerts', params);
|
||||
},
|
||||
getRules: async () => {
|
||||
return http.get('/alerts/rules');
|
||||
},
|
||||
getChannels: async () => {
|
||||
return http.get('/alerts/notify-channels');
|
||||
},
|
||||
acknowledge: async (id: number | string) => {
|
||||
return http.post(`/alerts/${id}/ack`);
|
||||
},
|
||||
resolve: async (id: number | string) => {
|
||||
return http.post(`/alerts/${id}/ack`);
|
||||
},
|
||||
// 告警静默规则 CRUD
|
||||
getSilences: async (params?: { status?: string }) => {
|
||||
return http.get<ListResponse>('/alerts/silences', params);
|
||||
},
|
||||
createSilence: async (data: Record<string, unknown>) => {
|
||||
return http.post('/alerts/silences', data);
|
||||
},
|
||||
updateSilence: async (id: number | string, data: Record<string, unknown>) => {
|
||||
return http.put(`/alerts/silences/${id}`, data);
|
||||
},
|
||||
deleteSilence: async (id: number | string) => {
|
||||
return http.delete(`/alerts/silences/${id}`);
|
||||
},
|
||||
toggleSilence: async (id: number | string) => {
|
||||
return http.post(`/alerts/silences/${id}/toggle`);
|
||||
},
|
||||
toggleRule: async (id: number | string) => {
|
||||
return http.post(`/alerts/rules/${id}/toggle`);
|
||||
},
|
||||
createRule: async ( data: any) => {
|
||||
return http.post('/alerts/rules', data);
|
||||
},
|
||||
deleteRule: async (id: number | string) => {
|
||||
return http.delete(`/alerts/rules/${id}`);
|
||||
},
|
||||
// 一键报警 — 后端批量创建默认规则
|
||||
quickSetup: async (type: string = 'ecs') => {
|
||||
return http.post('/alerts/quick-setup', { type });
|
||||
},
|
||||
};
|
||||
|
||||
// ==================== 站点拨测 API ====================
|
||||
|
||||
export const siteApi = {
|
||||
getStats: async () => {
|
||||
return http.get('/site/stats');
|
||||
},
|
||||
getTasks: async () => {
|
||||
return http.get<{ list: any[]; total: number }>('/site/tasks');
|
||||
},
|
||||
createTask: async (data: { name: string; url: string; type: string; frequency_sec?: number; timeout_sec?: number; expected_status_code?: number }) => {
|
||||
return http.post('/site/tasks', data);
|
||||
},
|
||||
deleteTask: async (id: number | string) => {
|
||||
return http.delete(`/site/tasks/${id}`);
|
||||
},
|
||||
toggleTask: async (id: number | string, enabled: boolean) => {
|
||||
return http.put(`/site/tasks/${id}`, { enabled });
|
||||
},
|
||||
};
|
||||
|
||||
// ==================== 链路追踪 API(暂无后端,返回空结果优雅降级) ====================
|
||||
|
||||
export const traceApi = {
|
||||
getTraces: async ( _params: any): Promise<{ data: any[]; total: number }> => ({ data: [], total: 0 }),
|
||||
getServices: async (_timeRange: string): Promise<{ data: any[]; total: number }> => ({ data: [], total: 0 }),
|
||||
getTraceDetail: async (_traceId: string): Promise<{ data: { spans: any[] } }> => ({ data: { spans: [] } }),
|
||||
};
|
||||
|
||||
// ==================== Grafana 仪表盘 API(暂无后端,返回空结果优雅降级) ====================
|
||||
|
||||
export const dashboardApi = {
|
||||
getDashboards: async (): Promise<{ data: any[]; total: number }> => ({ data: [], total: 0 }),
|
||||
getDatasources: async (): Promise<{ data: any[]; total: number }> => ({ data: [], total: 0 }),
|
||||
createDashboard: async ( _data: any) => ({ success: false }),
|
||||
updateDashboard: async (_id: number | string, _data: any) => ({ success: false }),
|
||||
deleteDashboard: async (_id: number | string) => ({ success: false }),
|
||||
createDatasource: async ( _data: any) => ({ success: false }),
|
||||
};
|
||||
|
||||
// ==================== Prometheus 数据源管理 API ==================== // Logan.Li
|
||||
|
||||
export const promDatasourceApi = {
|
||||
list: () => http.get('/prometheus-datasources'),
|
||||
get: (id: number | string) => http.get(`/prometheus-datasources/${id}`),
|
||||
create: ( data: any) => http.post('/prometheus-datasources', data),
|
||||
update: (id: number | string, data: any) => http.put(`/prometheus-datasources/${id}`, data),
|
||||
delete: (id: number | string) => http.delete(`/prometheus-datasources/${id}`),
|
||||
setDefault: (id: number | string) => http.post(`/prometheus-datasources/${id}/default`),
|
||||
testConnection: ( data: any) => http.post('/prometheus-datasources/test', data),
|
||||
};
|
||||
|
||||
// ==================== Zabbix 数据源管理 API ==================== // Logan.Li
|
||||
|
||||
export const zabbixDatasourceApi = {
|
||||
list: () => http.get('/zabbix-datasources'),
|
||||
get: (id: number | string) => http.get(`/zabbix-datasources/${id}`),
|
||||
create: ( data: any) => http.post('/zabbix-datasources', data),
|
||||
update: (id: number | string, data: any) => http.put(`/zabbix-datasources/${id}`, data),
|
||||
delete: (id: number | string) => http.delete(`/zabbix-datasources/${id}`),
|
||||
setDefault: (id: number | string) => http.post(`/zabbix-datasources/${id}/default`),
|
||||
testConnection: ( data: any) => http.post('/zabbix-datasources/test', data),
|
||||
};
|
||||
|
||||
// ==================== 指标探索 / 中间件监控 API ==================== // Logan.Li
|
||||
|
||||
export const metricsApi = {
|
||||
getTargets: (params?: Record<string, string | number | boolean | undefined>) =>
|
||||
http.get('/metrics/targets', params),
|
||||
getNames: () => http.get('/metrics/names'),
|
||||
query: (params: {
|
||||
target_id: string | number;
|
||||
metric_name: string;
|
||||
from: string;
|
||||
to: string;
|
||||
limit?: number;
|
||||
}) => http.get('/metrics/query', params),
|
||||
};
|
||||
|
||||
// ==================== SNMP 监控 API ==================== // Logan.Li
|
||||
|
||||
export const snmpApi = {
|
||||
getStats: () => http.get('/snmp/stats'),
|
||||
getDevices: () => http.get('/snmp/devices'),
|
||||
createDevice: (data: Record<string, unknown>) => http.post('/snmp/devices', data),
|
||||
deleteDevice: (id: number | string) => http.delete(`/snmp/devices/${id}`),
|
||||
};
|
||||
|
||||
// ==================== Prometheus / Zabbix 大屏代理 API ==================== // Logan.Li
|
||||
|
||||
export const prometheusProxyApi = {
|
||||
connect: (url: string) => http.post('/prometheus/connect', { url }),
|
||||
dashboard: (url: string, type: string) => http.post('/prometheus/dashboard', { url, type }),
|
||||
};
|
||||
|
||||
export const zabbixProxyApi = {
|
||||
connect: (url: string, username: string, password: string) =>
|
||||
http.post('/zabbix/connect', { url, username, password }),
|
||||
};
|
||||
// 监控告警 API — 子模块 re-export(保持 @/api 导入路径不变) // Logan.Li
|
||||
|
||||
export * from './monitor/index';
|
||||
@@ -0,0 +1,50 @@
|
||||
// 告警中心 / 静默规则 API // Logan.Li
|
||||
|
||||
import { http, type ListResponse } from '@/utils/request';
|
||||
|
||||
export const alertCenterApi = {
|
||||
getAlerts: async (params?: { page?: number; page_size?: number; status?: string; severity?: string }) => {
|
||||
return http.get<ListResponse>('/alerts', params);
|
||||
},
|
||||
getRules: async () => {
|
||||
return http.get('/alerts/rules');
|
||||
},
|
||||
getChannels: async () => {
|
||||
return http.get('/alerts/notify-channels');
|
||||
},
|
||||
acknowledge: async (id: number | string) => {
|
||||
return http.post(`/alerts/${id}/ack`);
|
||||
},
|
||||
resolve: async (id: number | string) => {
|
||||
return http.post(`/alerts/${id}/ack`);
|
||||
},
|
||||
// 告警静默规则 CRUD
|
||||
getSilences: async (params?: { status?: string }) => {
|
||||
return http.get<ListResponse>('/alerts/silences', params);
|
||||
},
|
||||
createSilence: async (data: Record<string, unknown>) => {
|
||||
return http.post('/alerts/silences', data);
|
||||
},
|
||||
updateSilence: async (id: number | string, data: Record<string, unknown>) => {
|
||||
return http.put(`/alerts/silences/${id}`, data);
|
||||
},
|
||||
deleteSilence: async (id: number | string) => {
|
||||
return http.delete(`/alerts/silences/${id}`);
|
||||
},
|
||||
toggleSilence: async (id: number | string) => {
|
||||
return http.post(`/alerts/silences/${id}/toggle`);
|
||||
},
|
||||
toggleRule: async (id: number | string) => {
|
||||
return http.post(`/alerts/rules/${id}/toggle`);
|
||||
},
|
||||
createRule: async ( data: any) => {
|
||||
return http.post('/alerts/rules', data);
|
||||
},
|
||||
deleteRule: async (id: number | string) => {
|
||||
return http.delete(`/alerts/rules/${id}`);
|
||||
},
|
||||
// 一键报警 — 后端批量创建默认规则
|
||||
quickSetup: async (type: string = 'ecs') => {
|
||||
return http.post('/alerts/quick-setup', { type });
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,72 @@
|
||||
// 告警规则 / 通知渠道 / 联系人 API // Logan.Li
|
||||
|
||||
import { http, type ListResponse } from '@/utils/request';
|
||||
|
||||
export const alertApi = {
|
||||
getAlerts: async (params?: { page?: number; page_size?: number; status?: string; severity?: string }) => {
|
||||
return http.get<ListResponse>('/alerts', params);
|
||||
},
|
||||
getRules: async () => {
|
||||
return http.get('/alerts/rules');
|
||||
},
|
||||
createRule: async ( data: any) => {
|
||||
return http.post('/alerts/rules', data);
|
||||
},
|
||||
updateRule: async (id: number | string, data: any) => {
|
||||
return http.put(`/alerts/rules/${id}`, data);
|
||||
},
|
||||
deleteRule: async (id: number | string) => {
|
||||
return http.delete(`/alerts/rules/${id}`);
|
||||
},
|
||||
batchDeleteRules: async (ids: number[]) => {
|
||||
return http.delete('/alerts/rules/batch-delete', { ids });
|
||||
},
|
||||
toggleRule: async (id: number | string) => {
|
||||
return http.post(`/alerts/rules/${id}/toggle`);
|
||||
},
|
||||
acknowledge: async (id: number | string) => {
|
||||
return http.post(`/alerts/${id}/ack`);
|
||||
},
|
||||
// 通知渠道管理
|
||||
getNotifyChannels: async () => {
|
||||
return http.get('/alerts/notify-channels');
|
||||
},
|
||||
createNotifyChannel: async ( data: any) => {
|
||||
return http.post('/alerts/notify-channels', data);
|
||||
},
|
||||
updateNotifyChannel: async (id: number | string, data: any) => {
|
||||
return http.put(`/alerts/notify-channels/${id}`, data);
|
||||
},
|
||||
deleteNotifyChannel: async (id: number | string) => {
|
||||
return http.delete(`/alerts/notify-channels/${id}`);
|
||||
},
|
||||
testNotifyChannel: async (id: number | string) => {
|
||||
return http.post(`/alerts/notify-channels/${id}/test`);
|
||||
},
|
||||
// 报警联系人
|
||||
getContacts: async () => {
|
||||
return http.get('/alerts/contacts');
|
||||
},
|
||||
createContact: async ( data: any) => {
|
||||
return http.post('/alerts/contacts', data);
|
||||
},
|
||||
updateContact: async (id: number | string, data: any) => {
|
||||
return http.put(`/alerts/contacts/${id}`, data);
|
||||
},
|
||||
deleteContact: async (id: number | string) => {
|
||||
return http.delete(`/alerts/contacts/${id}`);
|
||||
},
|
||||
// 报警联系组
|
||||
getContactGroups: async () => {
|
||||
return http.get('/alerts/contact-groups');
|
||||
},
|
||||
createContactGroup: async ( data: any) => {
|
||||
return http.post('/alerts/contact-groups', data);
|
||||
},
|
||||
updateContactGroup: async (id: number | string, data: any) => {
|
||||
return http.put(`/alerts/contact-groups/${id}`, data);
|
||||
},
|
||||
deleteContactGroup: async (id: number | string) => {
|
||||
return http.delete(`/alerts/contact-groups/${id}`);
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,23 @@
|
||||
// Prometheus / Zabbix 数据源管理 API // Logan.Li
|
||||
|
||||
import { http } from '@/utils/request';
|
||||
|
||||
export const promDatasourceApi = {
|
||||
list: () => http.get('/prometheus-datasources'),
|
||||
get: (id: number | string) => http.get(`/prometheus-datasources/${id}`),
|
||||
create: ( data: any) => http.post('/prometheus-datasources', data),
|
||||
update: (id: number | string, data: any) => http.put(`/prometheus-datasources/${id}`, data),
|
||||
delete: (id: number | string) => http.delete(`/prometheus-datasources/${id}`),
|
||||
setDefault: (id: number | string) => http.post(`/prometheus-datasources/${id}/default`),
|
||||
testConnection: ( data: any) => http.post('/prometheus-datasources/test', data),
|
||||
};
|
||||
|
||||
export const zabbixDatasourceApi = {
|
||||
list: () => http.get('/zabbix-datasources'),
|
||||
get: (id: number | string) => http.get(`/zabbix-datasources/${id}`),
|
||||
create: ( data: any) => http.post('/zabbix-datasources', data),
|
||||
update: (id: number | string, data: any) => http.put(`/zabbix-datasources/${id}`, data),
|
||||
delete: (id: number | string) => http.delete(`/zabbix-datasources/${id}`),
|
||||
setDefault: (id: number | string) => http.post(`/zabbix-datasources/${id}/default`),
|
||||
testConnection: ( data: any) => http.post('/zabbix-datasources/test', data),
|
||||
};
|
||||
@@ -0,0 +1,10 @@
|
||||
// Grafana 仪表盘 API(暂无后端,返回空结果优雅降级) // Logan.Li
|
||||
|
||||
export const dashboardApi = {
|
||||
getDashboards: async (): Promise<{ data: any[]; total: number }> => ({ data: [], total: 0 }),
|
||||
getDatasources: async (): Promise<{ data: any[]; total: number }> => ({ data: [], total: 0 }),
|
||||
createDashboard: async ( _data: any) => ({ success: false }),
|
||||
updateDashboard: async (_id: number | string, _data: any) => ({ success: false }),
|
||||
deleteDashboard: async (_id: number | string) => ({ success: false }),
|
||||
createDatasource: async ( _data: any) => ({ success: false }),
|
||||
};
|
||||
@@ -0,0 +1,9 @@
|
||||
// 监控告警 API 聚合出口 // Logan.Li
|
||||
|
||||
export { alertApi } from './alert';
|
||||
export { alertCenterApi } from './alert-center';
|
||||
export { siteApi } from './site';
|
||||
export { traceApi } from './trace';
|
||||
export { dashboardApi } from './grafana';
|
||||
export { promDatasourceApi, zabbixDatasourceApi } from './datasource';
|
||||
export { metricsApi, snmpApi, prometheusProxyApi, zabbixProxyApi } from './metrics';
|
||||
@@ -0,0 +1,33 @@
|
||||
// 指标探索 / SNMP / 大屏代理 API // Logan.Li
|
||||
|
||||
import { http } from '@/utils/request';
|
||||
|
||||
export const metricsApi = {
|
||||
getTargets: (params?: Record<string, string | number | boolean | undefined>) =>
|
||||
http.get('/metrics/targets', params),
|
||||
getNames: () => http.get('/metrics/names'),
|
||||
query: (params: {
|
||||
target_id: string | number;
|
||||
metric_name: string;
|
||||
from: string;
|
||||
to: string;
|
||||
limit?: number;
|
||||
}) => http.get('/metrics/query', params),
|
||||
};
|
||||
|
||||
export const snmpApi = {
|
||||
getStats: () => http.get('/snmp/stats'),
|
||||
getDevices: () => http.get('/snmp/devices'),
|
||||
createDevice: (data: Record<string, unknown>) => http.post('/snmp/devices', data),
|
||||
deleteDevice: (id: number | string) => http.delete(`/snmp/devices/${id}`),
|
||||
};
|
||||
|
||||
export const prometheusProxyApi = {
|
||||
connect: (url: string) => http.post('/prometheus/connect', { url }),
|
||||
dashboard: (url: string, type: string) => http.post('/prometheus/dashboard', { url, type }),
|
||||
};
|
||||
|
||||
export const zabbixProxyApi = {
|
||||
connect: (url: string, username: string, password: string) =>
|
||||
http.post('/zabbix/connect', { url, username, password }),
|
||||
};
|
||||
@@ -0,0 +1,21 @@
|
||||
// 站点拨测 API // Logan.Li
|
||||
|
||||
import { http } from '@/utils/request';
|
||||
|
||||
export const siteApi = {
|
||||
getStats: async () => {
|
||||
return http.get('/site/stats');
|
||||
},
|
||||
getTasks: async () => {
|
||||
return http.get<{ list: any[]; total: number }>('/site/tasks');
|
||||
},
|
||||
createTask: async (data: { name: string; url: string; type: string; frequency_sec?: number; timeout_sec?: number; expected_status_code?: number }) => {
|
||||
return http.post('/site/tasks', data);
|
||||
},
|
||||
deleteTask: async (id: number | string) => {
|
||||
return http.delete(`/site/tasks/${id}`);
|
||||
},
|
||||
toggleTask: async (id: number | string, enabled: boolean) => {
|
||||
return http.put(`/site/tasks/${id}`, { enabled });
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,7 @@
|
||||
// 链路追踪 API(暂无后端,返回空结果优雅降级) // Logan.Li
|
||||
|
||||
export const traceApi = {
|
||||
getTraces: async ( _params: any): Promise<{ data: any[]; total: number }> => ({ data: [], total: 0 }),
|
||||
getServices: async (_timeRange: string): Promise<{ data: any[]; total: number }> => ({ data: [], total: 0 }),
|
||||
getTraceDetail: async (_traceId: string): Promise<{ data: { spans: any[] } }> => ({ data: { spans: [] } }),
|
||||
};
|
||||
Reference in new issue
Block a user