mirror of
https://github.com/crocofied/CoreControl.git
synced 2025-12-17 15:36:50 +00:00
63 lines
1.9 KiB
TypeScript
63 lines
1.9 KiB
TypeScript
import { useState, useEffect, useCallback } from "react";
|
|
import axios from "axios";
|
|
|
|
interface MonitoringSettings {
|
|
frequency: number;
|
|
checksUntilOffline: number;
|
|
}
|
|
|
|
|
|
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 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 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 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
|
|
});
|
|
}
|
|
|
|
return { getGeneralApplicationMonitoringSettings, getGeneralServerMonitoringSettings, editGeneralApplicationMonitoringSettings, editGeneralServerMonitoringSettings };
|
|
};
|
|
|
|
export default useMonitoring;
|