mirror of
https://github.com/OneUptime/oneuptime.git
synced 2026-04-06 00:32:12 +02:00
- Improve extractHostnameAndPort and splitHostAndPort to handle IPv6 brackets, single-colon ports, and trimmed port values; return explicit result objects. - Normalize host/port parsing logic and ensure port values are trimmed before use. - Consolidate import formatting and split long method signatures for readability. - Minor formatting/whitespace cleanups in Probe Config, Alive, Register, Monitor, and NO_PROXY parsing.
59 lines
1.8 KiB
TypeScript
59 lines
1.8 KiB
TypeScript
import { PROBE_INGEST_URL } from "../Config";
|
|
import Register from "../Services/Register";
|
|
import ProbeAPIRequest from "../Utils/ProbeAPIRequest";
|
|
import URL from "Common/Types/API/URL";
|
|
import API from "Common/Utils/API";
|
|
import { EVERY_MINUTE } from "Common/Utils/CronTime";
|
|
import LocalCache from "Common/Server/Infrastructure/LocalCache";
|
|
import BasicCron from "Common/Server/Utils/BasicCron";
|
|
import logger from "Common/Server/Utils/Logger";
|
|
import HTTPResponse from "Common/Types/API/HTTPResponse";
|
|
import { JSONObject } from "Common/Types/JSON";
|
|
import ProxyConfig from "../Utils/ProxyConfig";
|
|
|
|
const InitJob: VoidFunction = (): void => {
|
|
BasicCron({
|
|
jobName: "Basic:Alive",
|
|
options: {
|
|
schedule: EVERY_MINUTE,
|
|
runOnStartup: false,
|
|
},
|
|
runFunction: async () => {
|
|
logger.debug("Checking if probe is alive...");
|
|
|
|
const probeId: string | undefined = LocalCache.getString(
|
|
"PROBE",
|
|
"PROBE_ID",
|
|
);
|
|
|
|
if (!probeId) {
|
|
logger.warn(
|
|
"Probe is not registered yet. Skipping alive check. Trying to register probe again...",
|
|
);
|
|
await Register.registerProbe();
|
|
return;
|
|
}
|
|
|
|
logger.debug("Probe ID: " + probeId.toString());
|
|
|
|
const aliveUrl: URL = URL.fromString(
|
|
PROBE_INGEST_URL.toString(),
|
|
).addRoute("/alive");
|
|
|
|
const result: HTTPResponse<JSONObject> = await API.post({
|
|
url: aliveUrl,
|
|
data: ProbeAPIRequest.getDefaultRequestBody(),
|
|
options: { ...ProxyConfig.getRequestProxyAgents(aliveUrl) },
|
|
});
|
|
|
|
if (result.isSuccess()) {
|
|
logger.debug("Probe update sent to server successfully.");
|
|
} else {
|
|
logger.error("Failed to send probe update to server.");
|
|
}
|
|
},
|
|
});
|
|
};
|
|
|
|
export default InitJob;
|