mirror of
https://github.com/OneUptime/oneuptime.git
synced 2026-04-06 00:32:12 +02:00
fix bugs
This commit is contained in:
@@ -10,6 +10,8 @@ import HTTPMethod from 'Common/Types/API/HTTPMethod';
|
||||
import ProbeAPIRequest from '../../Utils/ProbeAPIRequest';
|
||||
import MonitorUtil from '../../Utils/Monitors/Monitor';
|
||||
import logger from 'CommonServer/Utils/Logger';
|
||||
import JSONFunctions from 'Common/Types/JSONFunctions';
|
||||
import { JSONArray } from 'Common/Types/JSON';
|
||||
|
||||
RunCron(
|
||||
'Monitor: Fetch List and monitor',
|
||||
@@ -18,8 +20,8 @@ RunCron(
|
||||
runOnStartup: false,
|
||||
},
|
||||
async () => {
|
||||
const result: HTTPResponse<Array<Monitor>> | HTTPErrorResponse =
|
||||
await API.fetch<Array<Monitor>>(
|
||||
const result: HTTPResponse<JSONArray> | HTTPErrorResponse =
|
||||
await API.fetch<JSONArray>(
|
||||
HTTPMethod.POST,
|
||||
URL.fromString(PROBE_API_URL.toString()).addRoute(
|
||||
'/monitor/list'
|
||||
@@ -29,7 +31,10 @@ RunCron(
|
||||
{}
|
||||
);
|
||||
|
||||
const monitors: Array<Monitor> = result.data as Array<Monitor>;
|
||||
const monitors: Array<Monitor> = JSONFunctions.fromJSONArray(
|
||||
result.data as JSONArray,
|
||||
Monitor
|
||||
);
|
||||
|
||||
const monitoringPromises: Array<Promise<void>> = [];
|
||||
|
||||
|
||||
@@ -44,7 +44,10 @@ export default class MonitorUtil {
|
||||
URL.fromString(PROBE_API_URL.toString()).addRoute(
|
||||
'/probe/response/ingest'
|
||||
),
|
||||
ProbeAPIRequest.getDefaultRequestBody(),
|
||||
{
|
||||
...ProbeAPIRequest.getDefaultRequestBody(),
|
||||
probeMonitorResponse: result as any,
|
||||
},
|
||||
{},
|
||||
{}
|
||||
);
|
||||
|
||||
@@ -82,6 +82,10 @@ router.post(
|
||||
// update the lastMonitoredAt field of the monitors
|
||||
|
||||
for (const monitorProbe of monitorProbes) {
|
||||
if (!monitorProbe.monitor) {
|
||||
continue;
|
||||
}
|
||||
|
||||
await MonitorProbeService.updateOneById({
|
||||
id: monitorProbe.id!,
|
||||
data: {
|
||||
@@ -96,11 +100,13 @@ router.post(
|
||||
});
|
||||
}
|
||||
|
||||
const monitors: Array<Monitor> = monitorProbes.map(
|
||||
(monitorProbe: MonitorProbe) => {
|
||||
const monitors: Array<Monitor> = monitorProbes
|
||||
.map((monitorProbe: MonitorProbe) => {
|
||||
return monitorProbe.monitor!;
|
||||
}
|
||||
);
|
||||
})
|
||||
.filter((monitor: Monitor) => {
|
||||
return Boolean(monitor);
|
||||
});
|
||||
|
||||
// return the list of monitors to be monitored
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ import ProbeMonitorResponse from 'Common/Types/Probe/ProbeMonitorResponse';
|
||||
import ProbeApiIngestResponse from 'Common/Types/Probe/ProbeApiIngestResponse';
|
||||
import BadDataException from 'Common/Types/Exception/BadDataException';
|
||||
import ProbeMonitorResponseService from '../Service/ProbeMonitorResponse';
|
||||
import JSONFunctions from 'Common/Types/JSONFunctions';
|
||||
|
||||
const router: ExpressRouter = Express.getRouter();
|
||||
|
||||
@@ -23,7 +24,9 @@ router.post(
|
||||
): Promise<void> => {
|
||||
try {
|
||||
const probeResponse: ProbeMonitorResponse =
|
||||
req.body['probeMonitorResponse'];
|
||||
JSONFunctions.deserialize(
|
||||
req.body['probeMonitorResponse']
|
||||
) as any;
|
||||
|
||||
if (!probeResponse) {
|
||||
return Response.sendErrorResponse(
|
||||
|
||||
@@ -6,6 +6,7 @@ import App from 'CommonServer/Utils/StartServer';
|
||||
import AliveAPI from './API/Alive';
|
||||
import RegisterAPI from './API/Register';
|
||||
import MonitorAPI from './API/Monitor';
|
||||
import ProbeAPI from './API/Probe';
|
||||
|
||||
import Redis from 'CommonServer/Infrastructure/Redis';
|
||||
|
||||
@@ -16,6 +17,7 @@ const APP_NAME: string = 'probe-api';
|
||||
app.use([`/${APP_NAME}`, '/'], AliveAPI);
|
||||
app.use([`/${APP_NAME}`, '/'], RegisterAPI);
|
||||
app.use([`/${APP_NAME}`, '/'], MonitorAPI);
|
||||
app.use([`/${APP_NAME}`, '/'], ProbeAPI);
|
||||
|
||||
const init: Function = async (): Promise<void> => {
|
||||
try {
|
||||
|
||||
@@ -34,7 +34,6 @@ export default class ProbeMonitorResponseService {
|
||||
};
|
||||
|
||||
// fetch monitor
|
||||
|
||||
const monitor: Monitor | null = await MonitorService.findOneById({
|
||||
id: probeMonitorResponse.monitorId,
|
||||
select: {
|
||||
|
||||
Reference in New Issue
Block a user