fix issue with sending probe-id

This commit is contained in:
Simon Larsen 2023-06-02 15:32:11 +01:00
parent e9af3e0b48
commit 639c4b13ae
No known key found for this signature in database
GPG Key ID: AB45983AA9C81CDE
3 changed files with 41 additions and 32 deletions

View File

@ -10,7 +10,7 @@ To begin with you need to create a custom probe in your Project Settings > Probe
To run a probe, please make sure you have docker installed. You can run custom probe by:
```
docker run --name oneuptime-probe -e PROBE_KEY=<probe-key> -e PROBE_ID=<probe-id> -e PROBE_API_URL=https://oneuptime.com/probe-api -d oneuptime/probe
docker run --name oneuptime-probe --network host -e PROBE_KEY=<probe-key> -e PROBE_ID=<probe-id> -e PROBE_API_URL=https://oneuptime.com/probe-api -d oneuptime/probe:release
```

View File

@ -23,42 +23,49 @@ RunCron(
// run a set timeout function randomly between 1 to 5 seconds, so same probes do not hit the server at the same time
setTimeout(async () => {
const result: HTTPResponse<JSONArray> | HTTPErrorResponse =
await API.fetch<JSONArray>(
HTTPMethod.POST,
URL.fromString(PROBE_API_URL.toString()).addRoute(
'/monitor/list'
),
ProbeAPIRequest.getDefaultRequestBody(),
{},
{}
try {
const monitorListUrl: URL = URL.fromString(
PROBE_API_URL.toString()
).addRoute('/monitor/list');
const result: HTTPResponse<JSONArray> | HTTPErrorResponse =
await API.fetch<JSONArray>(
HTTPMethod.POST,
monitorListUrl,
ProbeAPIRequest.getDefaultRequestBody(),
{},
{}
);
const monitors: Array<Monitor> = JSONFunctions.fromJSONArray(
result.data as JSONArray,
Monitor
);
const monitors: Array<Monitor> = JSONFunctions.fromJSONArray(
result.data as JSONArray,
Monitor
);
const monitoringPromises: Array<Promise<void>> = [];
const monitoringPromises: Array<Promise<void>> = [];
for (const monitor of monitors) {
const promise: Promise<void> = new Promise<void>(
(resolve: Function, reject: Function): void => {
MonitorUtil.probeMonitor(monitor)
.then(() => {
resolve();
})
.catch((err: Error) => {
logger.error(err);
reject(err);
});
}
);
for (const monitor of monitors) {
const promise: Promise<void> = new Promise<void>(
(resolve: Function, reject: Function): void => {
MonitorUtil.probeMonitor(monitor)
.then(() => {
resolve();
})
.catch((err: Error) => {
logger.error(err);
reject(err);
});
}
);
monitoringPromises.push(promise);
}
monitoringPromises.push(promise);
await Promise.allSettled(monitoringPromises);
} catch (err) {
logger.error('Error in fetching monitor list');
logger.error(err);
}
await Promise.allSettled(monitoringPromises);
}, Math.floor(Math.random() * 5000) + 1000);
}
);

View File

@ -6,7 +6,9 @@ export default class ProbeAPIRequest {
public static getDefaultRequestBody(): JSONObject {
return {
probeKey: PROBE_KEY,
probeId: LocalCache.getString('PROBE', 'PROBE_ID'),
probeId:
LocalCache.getString('PROBE', 'PROBE_ID') ||
process.env['PROBE_ID'],
};
}
}