UNPKG

896 BPlain TextView Raw
1import * as bcrypt from "bcrypt-nodejs";
2import * as crypto from "crypto";
3import * as mongoose from "mongoose";
4import { ObjectId } from "mongodb";
5
6const sourceSchema = new mongoose.Schema({
7 Endpoint: { type: String, unique: true },
8 Interval: { type: Number, default: 60 * 1000 },
9 IsActive: { type: Boolean, default: false },
10 Thresholds: [
11 {
12 Name: { type: String },
13 Formula: { type: String },
14 Message: { type: String },
15 Type: { type: String, enum: ["goal", "critical"], default: "critical" },
16 ComputedFormula: { type: String }
17 }
18 ]
19}, { timestamps: true });
20
21/**
22 * pre save source middleware.
23 */
24sourceSchema.pre("save", function save(next) {
25 const source: any = this;
26 if (!source.Thresholds) source.Thresholds = [];
27 next();
28});
29
30const Source = mongoose.model("Source", sourceSchema);
31
32export { Source };
33