add monitor type

This commit is contained in:
Simon Larsen 2023-05-03 13:15:03 +01:00
parent 74d57bbc27
commit ba1e5487c2
No known key found for this signature in database
GPG Key ID: AB45983AA9C81CDE
4 changed files with 102 additions and 2 deletions

View File

@ -5,9 +5,9 @@ enum MonitorType {
Website = 'Website',
API = 'API',
Ping = 'Ping',
// Kubernetes = 'Kubernetes',
Kubernetes = 'Kubernetes',
IP = 'IP',
// IncomingRequest = 'IncomingRequest',
IncomingRequest = 'IncomingRequest',
}
export default MonitorType;

View File

@ -9,6 +9,12 @@ import MonitorStatusTimelineService from './MonitorStatusTimelineService';
import ObjectID from 'Common/Types/ObjectID';
import DatabaseCommonInteractionProps from 'Common/Types/Database/DatabaseCommonInteractionProps';
import MonitorStatusTimeline from 'Model/Models/MonitorStatusTimeline';
import ProbeService from './ProbeService';
import { LIMIT_PER_PROJECT } from 'Common/Types/Database/LimitMax';
import MonitorProbe from 'Model/Models/MonitorProbe';
import OneUptimeDate from 'Common/Types/Date';
import MonitorProbeService from './MonitorProbeService';
import MonitorType from 'Common/Types/Monitor/MonitorType';
export class Service extends DatabaseService<Model> {
public constructor(postgresDatabase?: PostgresDatabase) {
@ -69,9 +75,68 @@ export class Service extends DatabaseService<Model> {
createdItem.currentMonitorStatusId,
onCreate.createBy.props
);
if(createdItem.monitorType && (createdItem.monitorType === MonitorType.API || createdItem.monitorType === MonitorType.IncomingRequest || createdItem.monitorType === MonitorType.Website || createdItem.monitorType === MonitorType.Ping || createdItem.monitorType === MonitorType.IP)) {
await this.addDefaultProbesToMonitor(createdItem.projectId, createdItem.id);
}
return createdItem;
}
public async addDefaultProbesToMonitor(projectId: ObjectID, monitorId: ObjectID) {
const globalProbes = await ProbeService.findBy({
query: {
isGlobalProbe: true,
shouldAutoEnableProbeOnNewMonitors: true
},
select: {
_id: true
},
skip: 0,
limit: LIMIT_PER_PROJECT,
props: {
isRoot: true
}
});
const projectProbes = await ProbeService.findBy({
query: {
isGlobalProbe: false,
shouldAutoEnableProbeOnNewMonitors: true,
projectId: projectId
},
select: {
_id: true
},
skip: 0,
limit: LIMIT_PER_PROJECT,
props: {
isRoot: true
}
})
const totalProbes = [...globalProbes, ...projectProbes];
for (const probe of totalProbes) {
const monitorProbe: MonitorProbe = new MonitorProbe();
monitorProbe.monitorId = monitorId;
monitorProbe.probeId = probe.id!;
monitorProbe.projectId = projectId;
monitorProbe.isEnabled = true;
monitorProbe.lastPingAt = OneUptimeDate.getCurrentDate();
monitorProbe.nextPingAt = OneUptimeDate.getCurrentDate();
await MonitorProbeService.create({
data: monitorProbe,
props: {
isRoot: true
}
});
}
}
public async changeMonitorStatus(
projectId: ObjectID,
monitorIds: Array<ObjectID>,

View File

@ -427,4 +427,38 @@ export default class Probe extends BaseModel {
default: false,
})
public isGlobalProbe?: boolean = undefined;
@ColumnAccessControl({
create: [
Permission.ProjectOwner,
Permission.ProjectAdmin,
Permission.ProjectMember,
Permission.CanCreateProjectStatusPage,
],
read: [
Permission.ProjectOwner,
Permission.ProjectAdmin,
Permission.ProjectMember,
Permission.CanReadProjectStatusPage,
],
update: [
Permission.ProjectOwner,
Permission.ProjectAdmin,
Permission.ProjectMember,
Permission.CanEditProjectStatusPage,
],
})
@TableColumn({
isDefaultValueColumn: true,
required: true,
type: TableColumnType.Boolean,
})
@Column({
type: ColumnType.Boolean,
nullable: false,
unique: false,
default: false,
})
public shouldAutoEnableProbeOnNewMonitors?: boolean = undefined;
}

View File

@ -75,6 +75,7 @@ router.post(
newProbe.name = data['probeName'] as string;
newProbe.description = data['probeDescription'] as string;
newProbe.lastAlive = OneUptimeDate.getCurrentDate();
newProbe.shouldAutoEnableProbeOnNewMonitors = true;
newProbe = await ProbeService.create({
data: newProbe,