mirror of
https://github.com/crocofied/CoreControl.git
synced 2025-12-29 16:14:43 +00:00
Monitoring Settings enhancements
This commit is contained in:
@@ -1,62 +1,75 @@
|
||||
import { useState, useEffect, useCallback } from "react";
|
||||
import axios from "axios";
|
||||
import axios, { AxiosError } from "axios";
|
||||
|
||||
interface MonitoringSettings {
|
||||
frequency: number;
|
||||
checksUntilOffline: number;
|
||||
}
|
||||
|
||||
interface ApiResponse<T> {
|
||||
data?: T;
|
||||
error?: string;
|
||||
}
|
||||
|
||||
const useMonitoring = () => {
|
||||
const getGeneralApplicationMonitoringSettings = (): Promise<any> | string => {
|
||||
return axios.get('/api/monitoring/applications/get_general')
|
||||
.then((response) => {
|
||||
if(response.data) {
|
||||
return response.data
|
||||
} else {
|
||||
return
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
return error.response.data.error
|
||||
});
|
||||
}
|
||||
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 = (): Promise<any> | string => {
|
||||
return axios.get('/api/monitoring/servers/get_general')
|
||||
.then((response) => {
|
||||
if(response.data) {
|
||||
return response.data
|
||||
} else {
|
||||
return
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
return error.response.data.error
|
||||
});
|
||||
}
|
||||
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 = (settings: MonitoringSettings): Promise<any> | string => {
|
||||
return axios.post('/api/monitoring/applications/edit_general', settings)
|
||||
.then((response) => {
|
||||
return response.data
|
||||
})
|
||||
.catch((error) => {
|
||||
return error.response.data.error
|
||||
});
|
||||
}
|
||||
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 = (settings: MonitoringSettings): Promise<any> | string => {
|
||||
return axios.post('/api/monitoring/servers/edit_general', settings)
|
||||
.then((response) => {
|
||||
return response.data
|
||||
})
|
||||
.catch((error) => {
|
||||
return error.response.data.error
|
||||
});
|
||||
}
|
||||
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 };
|
||||
return {
|
||||
getGeneralApplicationMonitoringSettings,
|
||||
getGeneralServerMonitoringSettings,
|
||||
editGeneralApplicationMonitoringSettings,
|
||||
editGeneralServerMonitoringSettings
|
||||
};
|
||||
};
|
||||
|
||||
export default useMonitoring;
|
||||
|
||||
Reference in New Issue
Block a user