41 lines
1.6 KiB
TypeScript
41 lines
1.6 KiB
TypeScript
import axios from "axios";
|
|
|
|
/**
|
|
* Sends a heartbeat to the provided URL
|
|
* @param url The URL to send the heartbeat to
|
|
* @param debug Whether to log debug information
|
|
* @private
|
|
*/
|
|
export async function sendHeartbeat(url: string, performance?: number, debug: boolean = false) {
|
|
const useUrl = new URL(url);
|
|
const parsedURL = `${useUrl.origin}/${useUrl.pathname}?status=up&msg=OK${performance ? `&ping=${performance}` : ""}`;
|
|
try {
|
|
const response = await axios.get(parsedURL);
|
|
if (debug)
|
|
console.log(
|
|
`[eu.astrogd.uptime-kuma-push-monitor] (${new Date().toISOString()}) <${url}>: ${response.status} ${response.statusText}`
|
|
);
|
|
} catch (error) {
|
|
console.error(`[eu.astrogd.uptime-kuma-push-monitor] (${new Date().toISOString()}) <${url}>: ${error}`);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Sends a shutdown notification to the provided URL
|
|
* @param url The URL to send the notification to
|
|
* @param debug Whether to log debug information
|
|
* @private
|
|
*/
|
|
export async function sendDownNotification(url: string, msg: string = "Error",debug: boolean = false) {
|
|
const useUrl = new URL(url);
|
|
const parsedURL = `${useUrl.origin}/${useUrl.pathname}?status=DOWN&msg=${msg}`;
|
|
try {
|
|
const response = await axios.get(parsedURL);
|
|
if (debug)
|
|
console.log(
|
|
`[eu.astrogd.uptime-kuma-push-monitor] (${new Date().toISOString()}) <${url}>: ${response.status} ${response.statusText}`
|
|
);
|
|
} catch (error) {
|
|
console.error(`[eu.astrogd.uptime-kuma-push-monitor] (${new Date().toISOString()}) <${url}>: ${error}`);
|
|
}
|
|
} |