mirror of
https://github.com/crocofied/CoreControl.git
synced 2025-12-17 15:36:50 +00:00
76 lines
2.6 KiB
TypeScript
76 lines
2.6 KiB
TypeScript
import { useState, useEffect, useCallback } from "react";
|
|
import axios, { AxiosError } from "axios";
|
|
|
|
interface MonitoringSettings {
|
|
frequency: number;
|
|
checksUntilOffline: number;
|
|
}
|
|
|
|
interface ApiResponse<T> {
|
|
data?: T;
|
|
error?: string;
|
|
}
|
|
|
|
const useMonitoring = () => {
|
|
const getGeneralApplicationMonitoringSettings = async (): Promise<ApiResponse<MonitoringSettings>> => {
|
|
try {
|
|
const response = await axios.get<MonitoringSettings>('/api/monitoring/applications/get_general');
|
|
return { data: response.data };
|
|
} catch (error) {
|
|
const axiosError = error as AxiosError<{ error: string }>;
|
|
return {
|
|
error: axiosError.response?.data?.error || 'Failed to fetch application monitoring settings'
|
|
};
|
|
}
|
|
};
|
|
|
|
const getGeneralServerMonitoringSettings = async (): Promise<ApiResponse<MonitoringSettings>> => {
|
|
try {
|
|
const response = await axios.get<MonitoringSettings>('/api/monitoring/servers/get_general');
|
|
return { data: response.data };
|
|
} catch (error) {
|
|
const axiosError = error as AxiosError<{ error: string }>;
|
|
return {
|
|
error: axiosError.response?.data?.error || 'Failed to fetch server monitoring settings'
|
|
};
|
|
}
|
|
};
|
|
|
|
const editGeneralApplicationMonitoringSettings = async (
|
|
settings: MonitoringSettings
|
|
): Promise<ApiResponse<void>> => {
|
|
try {
|
|
await axios.post('/api/monitoring/applications/edit_general', settings);
|
|
return { data: undefined };
|
|
} catch (error) {
|
|
const axiosError = error as AxiosError<{ error: string }>;
|
|
return {
|
|
error: axiosError.response?.data?.error || 'Failed to update application monitoring settings'
|
|
};
|
|
}
|
|
};
|
|
|
|
const editGeneralServerMonitoringSettings = async (
|
|
settings: MonitoringSettings
|
|
): Promise<ApiResponse<void>> => {
|
|
try {
|
|
await axios.post('/api/monitoring/servers/edit_general', settings);
|
|
return { data: undefined };
|
|
} catch (error) {
|
|
const axiosError = error as AxiosError<{ error: string }>;
|
|
return {
|
|
error: axiosError.response?.data?.error || 'Failed to update server monitoring settings'
|
|
};
|
|
}
|
|
};
|
|
|
|
return {
|
|
getGeneralApplicationMonitoringSettings,
|
|
getGeneralServerMonitoringSettings,
|
|
editGeneralApplicationMonitoringSettings,
|
|
editGeneralServerMonitoringSettings
|
|
};
|
|
};
|
|
|
|
export default useMonitoring;
|