fixes and improvements
This commit is contained in:
@@ -15,6 +15,12 @@ import type {
|
||||
MonitoringStatus,
|
||||
MonitoringMetrics,
|
||||
DiskSpace,
|
||||
SSHKey,
|
||||
SSHKeyInput,
|
||||
SSHKeyGenerated,
|
||||
SavedTask,
|
||||
SavedTaskInput,
|
||||
SavedTaskRun,
|
||||
MonitoringMachine,
|
||||
MonitoringMachineInput,
|
||||
MonitoringMachineAction,
|
||||
@@ -200,11 +206,84 @@ export const restartCollector = (machineId?: string) =>
|
||||
|
||||
export const fetchMonitoringSettings = () =>
|
||||
get<MonitoringMachine[]>("/api/settings/machines");
|
||||
export const fetchSSHKeys = () => get<SSHKey[]>("/api/settings/ssh-keys");
|
||||
export const generateSSHKey = (payload: {
|
||||
name: string;
|
||||
passphrase: string;
|
||||
notes: string;
|
||||
bits?: number;
|
||||
}) => post<SSHKeyGenerated>("/api/settings/ssh-keys/generate", payload);
|
||||
export const fetchMonitoringMachineActions = (machineId: string, limit = 10) =>
|
||||
get<{ items: MonitoringMachineAction[]; total: number }>(
|
||||
`/api/monitoring/machines/${encodeURIComponent(machineId)}/actions`,
|
||||
{ limit: String(limit) },
|
||||
);
|
||||
export const saveSSHKey = (key: SSHKeyInput) =>
|
||||
fetch(
|
||||
buildUrl(
|
||||
key.id
|
||||
? `/api/settings/ssh-keys/${encodeURIComponent(key.id)}`
|
||||
: "/api/settings/ssh-keys",
|
||||
),
|
||||
{
|
||||
method: key.id ? "PUT" : "POST",
|
||||
headers: buildHeaders(true),
|
||||
body: JSON.stringify(key),
|
||||
},
|
||||
).then(async (response) => {
|
||||
if (!response.ok) {
|
||||
throw new Error(`${response.status}: ${await readErrorDetail(response)}`);
|
||||
}
|
||||
return response.json() as Promise<SSHKey>;
|
||||
});
|
||||
export const deleteSSHKey = (keyId: string) =>
|
||||
del<{ status: string }>(
|
||||
`/api/settings/ssh-keys/${encodeURIComponent(keyId)}`,
|
||||
);
|
||||
|
||||
export const fetchSavedTasks = () => get<SavedTask[]>("/api/tasks");
|
||||
export const fetchSavedTaskRuns = (taskId: string, limit = 10) =>
|
||||
get<{ items: SavedTaskRun[]; total: number }>(
|
||||
`/api/tasks/${encodeURIComponent(taskId)}/runs`,
|
||||
{
|
||||
limit: String(limit),
|
||||
},
|
||||
);
|
||||
export const saveTask = (task: SavedTaskInput) =>
|
||||
fetch(
|
||||
buildUrl(
|
||||
task.id ? `/api/tasks/${encodeURIComponent(task.id)}` : "/api/tasks",
|
||||
),
|
||||
{
|
||||
method: task.id ? "PUT" : "POST",
|
||||
headers: buildHeaders(true),
|
||||
body: JSON.stringify(task),
|
||||
},
|
||||
).then(async (response) => {
|
||||
if (!response.ok) {
|
||||
throw new Error(`${response.status}: ${await readErrorDetail(response)}`);
|
||||
}
|
||||
return response.json() as Promise<SavedTask>;
|
||||
});
|
||||
export const deleteTask = (taskId: string) =>
|
||||
del<{ status: string }>(`/api/tasks/${encodeURIComponent(taskId)}`);
|
||||
export const runTask = (taskId: string, machineId?: string) =>
|
||||
post<{
|
||||
task_id: string;
|
||||
task_name: string;
|
||||
machine_id: string;
|
||||
machine_name: string;
|
||||
task_type: string;
|
||||
exit_status: number;
|
||||
stdout: string;
|
||||
stderr: string;
|
||||
}>(
|
||||
machineId
|
||||
? `/api/tasks/run?machine_id=${encodeURIComponent(machineId)}`
|
||||
: "/api/tasks/run",
|
||||
{ task_id: taskId },
|
||||
);
|
||||
|
||||
export const saveMonitoringMachine = (machine: MonitoringMachineInput) =>
|
||||
fetch(
|
||||
buildUrl(
|
||||
|
||||
Reference in New Issue
Block a user