@oneuptime/common 14.0.91 → 14.0.92

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (90) hide show
  1. package/Models/DatabaseModels/AutoRemediationRule.js +1 -1
  2. package/Models/DatabaseModels/CodeRepository.d.mts +1 -0
  3. package/Models/DatabaseModels/CodeRepository.d.ts +1 -0
  4. package/Models/DatabaseModels/CodeRepository.js +69 -6
  5. package/Types/AI/CodeTask.d.mts +1 -0
  6. package/Types/AI/CodeTask.d.ts +1 -0
  7. package/Types/AI/TelemetryAiActivity.d.mts +1 -0
  8. package/Types/AI/TelemetryAiActivity.d.ts +1 -0
  9. package/Types/AI/TelemetryAiActivity.js +4 -0
  10. package/Types/CodeRepository/CodeRepositorySetting.d.mts +15 -0
  11. package/Types/CodeRepository/CodeRepositorySetting.d.ts +15 -0
  12. package/Types/CodeRepository/CodeRepositorySetting.js +49 -0
  13. package/Types/CodeRepository/CodeRepositorySetting.mjs +3 -0
  14. package/Types/Date.d.mts +10 -0
  15. package/Types/Date.d.ts +10 -0
  16. package/Types/Date.js +385 -98
  17. package/Types/DateLanguage.d.mts +67 -0
  18. package/Types/DateLanguage.d.ts +67 -0
  19. package/Types/DateLanguage.js +478 -0
  20. package/Types/DateLanguage.mjs +21 -0
  21. package/Types/Runner/CodeRepositoryRunner.d.mts +7 -0
  22. package/Types/Runner/CodeRepositoryRunner.d.ts +7 -0
  23. package/Types/Runner/CodeRepositoryRunner.js +60 -14
  24. package/Types/Runner/CodeRepositoryRunner.mjs +1 -0
  25. package/Types/SecurityEvent/OcsfProcessActivity.d.mts +25 -0
  26. package/Types/SecurityEvent/OcsfProcessActivity.d.ts +25 -0
  27. package/Types/SecurityEvent/OcsfProcessActivity.js +131 -0
  28. package/Types/SecurityEvent/OcsfProcessActivity.mjs +8 -0
  29. package/UI/Utils/TranslateTemplate.d.mts +73 -0
  30. package/UI/Utils/TranslateTemplate.d.ts +73 -0
  31. package/Utils/CronTab.d.mts +41 -3
  32. package/Utils/CronTab.d.ts +41 -3
  33. package/Utils/CronTab.js +112 -38
  34. package/Utils/Monitor/MonitorOverviewTargetUtil.d.mts +2 -0
  35. package/Utils/Monitor/MonitorOverviewTargetUtil.d.ts +2 -0
  36. package/Utils/Monitor/MonitorOverviewTargetUtil.js +13 -2
  37. package/Utils/SecurityEvent/Destinations/GoogleSecOpsUdmMapper.d.mts +5 -0
  38. package/Utils/SecurityEvent/Destinations/GoogleSecOpsUdmMapper.d.ts +5 -0
  39. package/Utils/SecurityEvent/Destinations/GoogleSecOpsUdmMapper.js +219 -58
  40. package/Utils/SecurityEvent/OcsfNormalizer.js +22 -13
  41. package/Utils/Slo/SloDuration.d.mts +1 -0
  42. package/Utils/Slo/SloDuration.d.ts +1 -0
  43. package/Utils/Slo/SloDuration.js +57 -8
  44. package/Utils/Slo/SloDuration.mjs +1 -0
  45. package/Utils/Suggestions/CodeFixSuggestion.d.mts +15 -0
  46. package/Utils/Suggestions/CodeFixSuggestion.d.ts +15 -0
  47. package/Utils/Suggestions/CodeFixSuggestion.js +62 -1
  48. package/Utils/Suggestions/CodeFixSuggestion.mjs +4 -0
  49. package/Utils/Suggestions/ProfileFixSuggestion.js +4 -0
  50. package/Utils/Suggestions/SuggestionBlocker.d.mts +8 -0
  51. package/Utils/Suggestions/SuggestionBlocker.d.ts +8 -0
  52. package/Utils/Suggestions/SuggestionBlocker.js +51 -0
  53. package/Utils/Suggestions/SuggestionBlocker.mjs +4 -0
  54. package/Utils/Suggestions/SuggestionOffer.d.mts +2 -1
  55. package/Utils/Suggestions/SuggestionOffer.d.ts +2 -1
  56. package/Utils/Suggestions/SuggestionOffer.js +5 -0
  57. package/Utils/Suggestions/TelemetryAiFixSuggestion.d.mts +2 -7
  58. package/Utils/Suggestions/TelemetryAiFixSuggestion.d.ts +2 -7
  59. package/Utils/Suggestions/TelemetryAiFixSuggestion.js +8 -36
  60. package/Utils/Suggestions/TelemetryImprovementSuggestion.d.mts +1 -0
  61. package/Utils/Suggestions/TelemetryImprovementSuggestion.d.ts +1 -0
  62. package/Utils/Suggestions/TelemetryImprovementSuggestion.js +1 -0
  63. package/Utils/Suggestions/TracePerformanceFixSuggestion.d.mts +6 -0
  64. package/Utils/Suggestions/TracePerformanceFixSuggestion.d.ts +6 -0
  65. package/Utils/Suggestions/TracePerformanceFixSuggestion.js +46 -5
  66. package/package.json +8 -1
  67. package/Utils/Monitor/MonitorCheckScheduleUtil.d.mts +0 -61
  68. package/Utils/Monitor/MonitorCheckScheduleUtil.d.ts +0 -61
  69. package/Utils/Monitor/MonitorCheckScheduleUtil.js +0 -476
  70. package/Utils/Monitor/MonitorCheckScheduleUtil.mjs +0 -3
  71. package/Utils/Monitor/MonitorOverviewFamily.d.mts +0 -39
  72. package/Utils/Monitor/MonitorOverviewFamily.d.ts +0 -39
  73. package/Utils/Monitor/MonitorOverviewFamily.js +0 -206
  74. package/Utils/Monitor/MonitorOverviewFamily.mjs +0 -4
  75. package/Utils/Monitor/MonitorOverviewPresentationUtil.d.mts +0 -189
  76. package/Utils/Monitor/MonitorOverviewPresentationUtil.d.ts +0 -189
  77. package/Utils/Monitor/MonitorOverviewPresentationUtil.js +0 -1480
  78. package/Utils/Monitor/MonitorOverviewPresentationUtil.mjs +0 -5
  79. package/Utils/Monitor/MonitorOverviewProbeUtil.d.mts +0 -112
  80. package/Utils/Monitor/MonitorOverviewProbeUtil.d.ts +0 -112
  81. package/Utils/Monitor/MonitorOverviewProbeUtil.js +0 -640
  82. package/Utils/Monitor/MonitorOverviewProbeUtil.mjs +0 -3
  83. package/Utils/Monitor/MonitorStatusHistoryUtil.d.mts +0 -27
  84. package/Utils/Monitor/MonitorStatusHistoryUtil.d.ts +0 -27
  85. package/Utils/Monitor/MonitorStatusHistoryUtil.js +0 -132
  86. package/Utils/Monitor/MonitorStatusHistoryUtil.mjs +0 -2
  87. package/Utils/Monitor/MonitorUptimeSummaryUtil.d.mts +0 -42
  88. package/Utils/Monitor/MonitorUptimeSummaryUtil.d.ts +0 -42
  89. package/Utils/Monitor/MonitorUptimeSummaryUtil.js +0 -468
  90. package/Utils/Monitor/MonitorUptimeSummaryUtil.mjs +0 -2
@@ -1,640 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- var __importDefault = (this && this.__importDefault) || function (mod) {
36
- return (mod && mod.__esModule) ? mod : { "default": mod };
37
- };
38
- Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.MonitorOverviewProbeHealth = void 0;
40
- const Probe_1 = require("../../Models/DatabaseModels/Probe");
41
- const MonitorType_1 = __importDefault(require("../../Types/Monitor/MonitorType"));
42
- const MonitorCheckScheduleUtil_1 = __importDefault(require("./MonitorCheckScheduleUtil"));
43
- const MonitorOverviewFamily_1 = __importStar(require("./MonitorOverviewFamily"));
44
- /*
45
- * Everything the monitor overview derives from the monitor's MonitorProbe
46
- * rows and its MonitorLog evaluations.
47
- *
48
- * Two timestamps are easy to confuse here:
49
- * - MonitorProbe.lastPingAt is when a probe CLAIMED the job (and is also set
50
- * when the row is created). It says nothing about whether a result came
51
- * back, so it is only used to notice that a newer result may be pending.
52
- * - lastMonitoringLog[stepId].monitoredAt is stamped by the server when a
53
- * result is ingested. That is "last checked".
54
- */
55
- var MonitorOverviewProbeHealth;
56
- (function (MonitorOverviewProbeHealth) {
57
- MonitorOverviewProbeHealth["Down"] = "Down";
58
- MonitorOverviewProbeHealth["Disconnected"] = "Disconnected";
59
- MonitorOverviewProbeHealth["Late"] = "Late";
60
- MonitorOverviewProbeHealth["NoResultYet"] = "NoResultYet";
61
- MonitorOverviewProbeHealth["Up"] = "Up";
62
- MonitorOverviewProbeHealth["Reported"] = "Reported";
63
- MonitorOverviewProbeHealth["TurnedOff"] = "TurnedOff";
64
- })(MonitorOverviewProbeHealth || (exports.MonitorOverviewProbeHealth = MonitorOverviewProbeHealth = {}));
65
- // The order the Probes card lists rows in: what needs attention first.
66
- const HEALTH_ORDER = {
67
- [MonitorOverviewProbeHealth.Down]: 0,
68
- [MonitorOverviewProbeHealth.Disconnected]: 1,
69
- [MonitorOverviewProbeHealth.Late]: 2,
70
- [MonitorOverviewProbeHealth.NoResultYet]: 3,
71
- [MonitorOverviewProbeHealth.Up]: 4,
72
- [MonitorOverviewProbeHealth.Reported]: 4,
73
- [MonitorOverviewProbeHealth.TurnedOff]: 5,
74
- };
75
- const toFiniteNumber = (value) => {
76
- return typeof value === "number" && Number.isFinite(value)
77
- ? value
78
- : undefined;
79
- };
80
- // An id that may be a string, an ObjectID or a typed JSON envelope.
81
- const toIdString = (value) => {
82
- if (typeof value === "string") {
83
- return value;
84
- }
85
- if (value && typeof value === "object") {
86
- const envelopeValue = value["value"];
87
- if (typeof envelopeValue === "string") {
88
- return envelopeValue;
89
- }
90
- const text = String(value);
91
- return text === "[object Object]" ? "" : text;
92
- }
93
- return "";
94
- };
95
- const clamp = (value, min, max) => {
96
- const whole = Number.isFinite(value) ? Math.floor(value) : min;
97
- return Math.min(max, Math.max(min, whole));
98
- };
99
- const getLogEntries = (monitorProbe, validStepIds) => {
100
- const log = monitorProbe.lastMonitoringLog;
101
- if (!log || typeof log !== "object") {
102
- return [];
103
- }
104
- return Object.entries(log)
105
- .filter((entry) => {
106
- return (Boolean(entry[1]) &&
107
- typeof entry[1] === "object" &&
108
- (validStepIds === null || validStepIds.has(entry[0])));
109
- })
110
- .map((entry) => {
111
- return [entry[0], entry[1]];
112
- });
113
- };
114
- // The newest result time in a row's log, across all its steps.
115
- const getNewestMonitoredAt = (monitorProbe) => {
116
- let newest = undefined;
117
- for (const entry of getLogEntries(monitorProbe, null)) {
118
- const monitoredAt = MonitorCheckScheduleUtil_1.default.parseDate(entry[1].monitoredAt);
119
- if (monitoredAt && (!newest || monitoredAt.getTime() > newest.getTime())) {
120
- newest = monitoredAt;
121
- }
122
- }
123
- return newest;
124
- };
125
- const getProbeKey = (monitorProbe) => {
126
- var _a;
127
- return ((_a = monitorProbe.probeId) === null || _a === void 0 ? void 0 : _a.toString()) || "";
128
- };
129
- const isReportingHealth = (health) => {
130
- return (health === MonitorOverviewProbeHealth.Up ||
131
- health === MonitorOverviewProbeHealth.Down ||
132
- health === MonitorOverviewProbeHealth.Reported);
133
- };
134
- /*
135
- * The probes whose schedule says when this monitor is next checked: the
136
- * ones that are reporting, or, before any has reported, the ones still
137
- * waiting for their first result. A disconnected or late probe's nextPingAt
138
- * only moves when that probe claims the check again, so it sinks further
139
- * into the past and says nothing about the probes still checking.
140
- */
141
- const getSchedulingRows = (enabledRows) => {
142
- const reportingRows = enabledRows.filter((row) => {
143
- return isReportingHealth(row.health);
144
- });
145
- if (reportingRows.length > 0) {
146
- return reportingRows;
147
- }
148
- return enabledRows.filter((row) => {
149
- return row.health === MonitorOverviewProbeHealth.NoResultYet;
150
- });
151
- };
152
- class MonitorOverviewProbeUtil {
153
- /*
154
- * The picker's probes, disabled ids and raw responses. Moved verbatim from
155
- * the old overview page, where it was pinned by source-text tests.
156
- */
157
- static toAttachedProbes(monitorProbes) {
158
- const probeMonitorResponses = [];
159
- const attachedProbes = [];
160
- const disabledProbeIds = [];
161
- for (let i = 0; i < (monitorProbes || []).length; i++) {
162
- const monitorProbe = monitorProbes[i];
163
- if (!monitorProbe) {
164
- continue;
165
- }
166
- if (!monitorProbe.probeId) {
167
- continue;
168
- }
169
- if (monitorProbe.probe) {
170
- const probe = monitorProbe.probe;
171
- /*
172
- * The relation select carries _id back on its own, but the join row
173
- * is the authority on which probe this is - and the picker keys its
174
- * options on that id.
175
- */
176
- probe._id = monitorProbe.probeId.toString();
177
- attachedProbes.push(probe);
178
- if (monitorProbe.isEnabled === false) {
179
- disabledProbeIds.push(monitorProbe.probeId.toString());
180
- }
181
- }
182
- if (!monitorProbe.lastMonitoringLog) {
183
- continue;
184
- }
185
- probeMonitorResponses.push(monitorProbe.lastMonitoringLog);
186
- }
187
- return {
188
- probes: attachedProbes,
189
- disabledProbeIds: disabledProbeIds,
190
- probeResponses: probeMonitorResponses,
191
- };
192
- }
193
- /*
194
- * Polls read the probe rows without lastMonitoringLog (synthetic results
195
- * carry screenshots). This lays the newest light fields over the last
196
- * full read's results. The rows are copied, never mutated.
197
- */
198
- static mergeProbeRows(data) {
199
- const fullByProbeId = new Map();
200
- for (const fullRow of data.fullRows || []) {
201
- const key = fullRow ? getProbeKey(fullRow) : "";
202
- if (key && !fullByProbeId.has(key)) {
203
- fullByProbeId.set(key, fullRow);
204
- }
205
- }
206
- return (data.lightRows || [])
207
- .filter((lightRow) => {
208
- return Boolean(lightRow);
209
- })
210
- .map((lightRow) => {
211
- const merged = Object.assign(Object.create(Object.getPrototypeOf(lightRow)), lightRow);
212
- const fullRow = fullByProbeId.get(getProbeKey(lightRow));
213
- if (fullRow === null || fullRow === void 0 ? void 0 : fullRow.lastMonitoringLog) {
214
- merged.lastMonitoringLog = fullRow.lastMonitoringLog;
215
- }
216
- return merged;
217
- });
218
- }
219
- /*
220
- * Whether a FULL probe read would show something the last one did not:
221
- * a probe was added, removed, switched on or off, or a probe has claimed
222
- * a check after the newest result we hold (so its result is on the way or
223
- * already in).
224
- *
225
- * A claim only counts while it can still produce a result we have not
226
- * seen, or the page would re-read every probe's full results on every
227
- * poll for a probe that never answers:
228
- * - a disconnected probe's claim is not a result on the way;
229
- * - `fullLoadedAt` is a cutoff, not simply the time of the last FULL read:
230
- * claims at or before it count as settled and are skipped. A read taken
231
- * after a claim saw the claim but not necessarily its result, so callers
232
- * pass a cutoff that only settles claims too old to still be answered
233
- * (useMonitorOverviewData's getSettledClaimCutoff);
234
- * - with `now`, a probe that has never reported is pending only while its
235
- * claim is younger than one cadence plus grace. lastPingAt is also
236
- * stamped when the row is created, so an old claim with no result is a
237
- * late probe (the Probes card shows it), not a result about to land.
238
- */
239
- static hasPendingProbeResults(data) {
240
- var _a;
241
- const lightRows = (data.lightRows || []).filter((row) => {
242
- return Boolean(row);
243
- });
244
- const fullRows = (data.fullRows || []).filter((row) => {
245
- return Boolean(row);
246
- });
247
- if (lightRows.length === 0) {
248
- return false;
249
- }
250
- const toPairs = (rows) => {
251
- return rows
252
- .map((row) => {
253
- return `${getProbeKey(row)}:${row.isEnabled === false ? "off" : "on"}`;
254
- })
255
- .sort()
256
- .join(",");
257
- };
258
- if (toPairs(lightRows) !== toPairs(fullRows)) {
259
- return true;
260
- }
261
- const fullByProbeId = new Map();
262
- for (const fullRow of fullRows) {
263
- fullByProbeId.set(getProbeKey(fullRow), fullRow);
264
- }
265
- const cadenceSeconds = data.cadenceSeconds !== undefined && Number.isFinite(data.cadenceSeconds)
266
- ? Math.max(0, data.cadenceSeconds)
267
- : MonitorCheckScheduleUtil_1.default.DEFAULT_CADENCE_SECONDS;
268
- const claimLifetimeMs = (cadenceSeconds +
269
- MonitorCheckScheduleUtil_1.default.getGraceSeconds(cadenceSeconds)) *
270
- 1000;
271
- for (const lightRow of lightRows) {
272
- if (lightRow.isEnabled === false) {
273
- continue;
274
- }
275
- if (((_a = lightRow.probe) === null || _a === void 0 ? void 0 : _a.connectionStatus) === Probe_1.ProbeConnectionStatus.Disconnected) {
276
- continue;
277
- }
278
- const claimedAt = MonitorCheckScheduleUtil_1.default.parseDate(lightRow.lastPingAt);
279
- if (!claimedAt) {
280
- continue;
281
- }
282
- if (data.fullLoadedAt &&
283
- claimedAt.getTime() <= data.fullLoadedAt.getTime()) {
284
- continue;
285
- }
286
- const fullRow = fullByProbeId.get(getProbeKey(lightRow));
287
- const newestResultAt = fullRow
288
- ? getNewestMonitoredAt(fullRow)
289
- : undefined;
290
- if (newestResultAt) {
291
- if (claimedAt.getTime() > newestResultAt.getTime()) {
292
- return true;
293
- }
294
- continue;
295
- }
296
- if (!data.now ||
297
- data.now.getTime() - claimedAt.getTime() <= claimLifetimeMs) {
298
- return true;
299
- }
300
- }
301
- return false;
302
- }
303
- /*
304
- * The ids of the monitor's current steps. A probe's lastMonitoringLog can
305
- * still hold results for steps that were deleted; those must not count.
306
- * Null when the steps are unknown, which means "do not filter".
307
- */
308
- static getValidStepIds(monitorSteps) {
309
- var _a, _b;
310
- const steps = (_a = monitorSteps === null || monitorSteps === void 0 ? void 0 : monitorSteps.data) === null || _a === void 0 ? void 0 : _a.monitorStepsInstanceArray;
311
- if (!Array.isArray(steps)) {
312
- return null;
313
- }
314
- const ids = new Set();
315
- for (const step of steps) {
316
- const id = (_b = step === null || step === void 0 ? void 0 : step.data) === null || _b === void 0 ? void 0 : _b.id;
317
- if (typeof id === "string" && id) {
318
- ids.add(id);
319
- }
320
- }
321
- return ids;
322
- }
323
- static getPrimaryStepId(monitorSteps) {
324
- var _a, _b, _c;
325
- const steps = (_a = monitorSteps === null || monitorSteps === void 0 ? void 0 : monitorSteps.data) === null || _a === void 0 ? void 0 : _a.monitorStepsInstanceArray;
326
- if (!Array.isArray(steps)) {
327
- return null;
328
- }
329
- const id = (_c = (_b = steps[0]) === null || _b === void 0 ? void 0 : _b.data) === null || _c === void 0 ? void 0 : _c.id;
330
- return typeof id === "string" && id ? id : null;
331
- }
332
- /*
333
- * `now` must be on the server's clock (see getCheckFreshness). With
334
- * `monitoringInterval`, a probe is late when the schedule's first run
335
- * after its result is further back than the grace, so a schedule with
336
- * gaps does not mark every probe late through the gap. `isScheduled`
337
- * false (monitoring is paused) means no probe is expected to check, so
338
- * none is late: each keeps the verdict of its last result.
339
- */
340
- static summarizeProbes(data) {
341
- var _a, _b, _c, _d, _e, _f;
342
- const isScheduled = data.isScheduled !== false;
343
- const rows = [];
344
- for (const monitorProbe of data.monitorProbes || []) {
345
- if (!monitorProbe) {
346
- continue;
347
- }
348
- const probeId = getProbeKey(monitorProbe);
349
- if (!probeId) {
350
- continue;
351
- }
352
- const latestResult = MonitorOverviewProbeUtil.getLatestResult({
353
- monitorProbe: monitorProbe,
354
- probeId: probeId,
355
- validStepIds: data.validStepIds,
356
- primaryStepId: data.primaryStepId,
357
- now: data.now,
358
- });
359
- const isEnabled = monitorProbe.isEnabled !== false;
360
- const connectionStatus = (_a = monitorProbe.probe) === null || _a === void 0 ? void 0 : _a.connectionStatus;
361
- let health = MonitorOverviewProbeHealth.Reported;
362
- if (!isEnabled) {
363
- health = MonitorOverviewProbeHealth.TurnedOff;
364
- }
365
- else if (connectionStatus === Probe_1.ProbeConnectionStatus.Disconnected) {
366
- health = MonitorOverviewProbeHealth.Disconnected;
367
- }
368
- else if (!(latestResult === null || latestResult === void 0 ? void 0 : latestResult.monitoredAt)) {
369
- health = MonitorOverviewProbeHealth.NoResultYet;
370
- }
371
- else if (isScheduled &&
372
- MonitorOverviewProbeUtil.isResultLate({
373
- monitoredAt: latestResult.monitoredAt,
374
- monitoringInterval: data.monitoringInterval,
375
- cadenceSeconds: data.cadenceSeconds,
376
- now: data.now,
377
- })) {
378
- health = MonitorOverviewProbeHealth.Late;
379
- }
380
- else if (latestResult.isOnline === false) {
381
- health = MonitorOverviewProbeHealth.Down;
382
- }
383
- else if (latestResult.isOnline === true) {
384
- health = MonitorOverviewProbeHealth.Up;
385
- }
386
- rows.push({
387
- probeId: probeId,
388
- name: ((_b = monitorProbe.probe) === null || _b === void 0 ? void 0 : _b.name) || "Unknown probe",
389
- iconFileId: ((_d = (_c = monitorProbe.probe) === null || _c === void 0 ? void 0 : _c.iconFileId) === null || _d === void 0 ? void 0 : _d.toString()) || undefined,
390
- isEnabled: isEnabled,
391
- isConnected: connectionStatus
392
- ? connectionStatus !== Probe_1.ProbeConnectionStatus.Disconnected
393
- : null,
394
- lastPingAt: MonitorCheckScheduleUtil_1.default.parseDate(monitorProbe.lastPingAt),
395
- nextPingAt: MonitorCheckScheduleUtil_1.default.parseDate(monitorProbe.nextPingAt),
396
- latestResult: latestResult,
397
- health: health,
398
- });
399
- }
400
- rows.sort((a, b) => {
401
- const byHealth = HEALTH_ORDER[a.health] - HEALTH_ORDER[b.health];
402
- if (byHealth !== 0) {
403
- return byHealth;
404
- }
405
- return a.name.localeCompare(b.name);
406
- });
407
- const enabledRows = rows.filter((row) => {
408
- return row.isEnabled;
409
- });
410
- let lastResultAt = undefined;
411
- let latestRow = undefined;
412
- const responseTimes = [];
413
- for (const row of enabledRows) {
414
- const monitoredAt = (_e = row.latestResult) === null || _e === void 0 ? void 0 : _e.monitoredAt;
415
- if (monitoredAt &&
416
- (!lastResultAt || monitoredAt.getTime() > lastResultAt.getTime())) {
417
- lastResultAt = monitoredAt;
418
- latestRow = row;
419
- }
420
- /*
421
- * "Latest" response time means now: a days-old reading from a probe
422
- * that has since disconnected or gone quiet would skew the range.
423
- */
424
- const responseTimeInMs = (_f = row.latestResult) === null || _f === void 0 ? void 0 : _f.responseTimeInMs;
425
- if (isReportingHealth(row.health) &&
426
- responseTimeInMs !== undefined &&
427
- responseTimeInMs > 0) {
428
- responseTimes.push(responseTimeInMs);
429
- }
430
- }
431
- let nextCheckAt = undefined;
432
- let latestNextCheckAt = undefined;
433
- for (const row of getSchedulingRows(enabledRows)) {
434
- const nextPingAt = row.nextPingAt;
435
- if (!nextPingAt) {
436
- continue;
437
- }
438
- if (nextPingAt.getTime() > data.now.getTime() &&
439
- (!nextCheckAt || nextPingAt.getTime() < nextCheckAt.getTime())) {
440
- nextCheckAt = nextPingAt;
441
- }
442
- if (!latestNextCheckAt ||
443
- nextPingAt.getTime() > latestNextCheckAt.getTime()) {
444
- latestNextCheckAt = nextPingAt;
445
- }
446
- }
447
- const countHealth = (health) => {
448
- return enabledRows.filter((row) => {
449
- return row.health === health;
450
- }).length;
451
- };
452
- return {
453
- rows: rows,
454
- attachedCount: rows.length,
455
- enabledCount: enabledRows.length,
456
- reportingCount: enabledRows.filter((row) => {
457
- return isReportingHealth(row.health);
458
- }).length,
459
- upCount: countHealth(MonitorOverviewProbeHealth.Up),
460
- downCount: countHealth(MonitorOverviewProbeHealth.Down),
461
- disabledCount: rows.length - enabledRows.length,
462
- disconnectedCount: rows.filter((row) => {
463
- return row.health === MonitorOverviewProbeHealth.Disconnected;
464
- }).length,
465
- lastResultAt: lastResultAt,
466
- nextCheckAt: nextCheckAt,
467
- latestNextCheckAt: latestNextCheckAt,
468
- latestResult: latestRow && latestRow.latestResult
469
- ? Object.assign(Object.assign({}, latestRow.latestResult), { probeName: latestRow.name }) : undefined,
470
- responseTime: MonitorOverviewProbeUtil.getResponseTime({
471
- responseTimes: responseTimes,
472
- totalCount: enabledRows.length,
473
- }),
474
- };
475
- }
476
- /*
477
- * The criteria verdicts behind each probe's latest result. They are only
478
- * in MonitorLog.logBody: the evaluationSummary on MonitorProbe's
479
- * lastMonitoringLog is copied before evaluation fills it, so it is always
480
- * empty. Logs must be sorted newest first; the first verdict per probe
481
- * wins.
482
- */
483
- static getEvaluationByProbe(logs) {
484
- const byProbeId = {};
485
- let latest = undefined;
486
- let latestAt = undefined;
487
- let latestLogBody = undefined;
488
- for (let i = 0; i < (logs || []).length; i++) {
489
- const log = logs[i];
490
- if (!log) {
491
- continue;
492
- }
493
- const time = MonitorCheckScheduleUtil_1.default.parseDate(log.time);
494
- if (i === 0) {
495
- latestAt = time;
496
- }
497
- const body = log.logBody;
498
- if (!body || typeof body !== "object") {
499
- continue;
500
- }
501
- if (i === 0 && !Array.isArray(body)) {
502
- latestLogBody = body;
503
- }
504
- const summary = body["evaluationSummary"];
505
- if (!MonitorOverviewProbeUtil.hasVerdict(summary)) {
506
- continue;
507
- }
508
- const probeId = toIdString(body["probeId"]);
509
- if (probeId && !byProbeId[probeId]) {
510
- byProbeId[probeId] = summary;
511
- }
512
- const at = time ||
513
- MonitorCheckScheduleUtil_1.default.parseDate(summary.evaluatedAt);
514
- if (!latest && at) {
515
- latest = {
516
- summary: summary,
517
- at: at,
518
- probeId: probeId || undefined,
519
- };
520
- }
521
- }
522
- const evaluation = {
523
- latest: latest,
524
- byProbeId: byProbeId,
525
- latestAt: latestAt,
526
- };
527
- if (latestLogBody) {
528
- evaluation.latestLogBody = latestLogBody;
529
- }
530
- return evaluation;
531
- }
532
- /*
533
- * How many MonitorLog rows to read. Probe checks need one verdict per
534
- * probe, and probes interleave, so twice the probe count (capped) is
535
- * enough to find each probe's newest. Scripted checks log their payloads,
536
- * so they read fewer. Everything else is evaluated centrally: one row.
537
- */
538
- static getEvaluationLogLimit(data) {
539
- if (MonitorOverviewFamily_1.default.getFamily(data.monitorType) !==
540
- MonitorOverviewFamily_1.MonitorOverviewFamily.ProbeCheck) {
541
- return 1;
542
- }
543
- if (data.monitorType === MonitorType_1.default.SyntheticMonitor ||
544
- data.monitorType === MonitorType_1.default.CustomJavaScriptCode) {
545
- return clamp(data.enabledProbeCount, 1, 10);
546
- }
547
- return clamp(2 * data.enabledProbeCount, 1, 20);
548
- }
549
- static isResultLate(data) {
550
- const lateness = MonitorCheckScheduleUtil_1.default.getResultLateness({
551
- lastResultAt: data.monitoredAt,
552
- monitoringInterval: data.monitoringInterval,
553
- cadenceSeconds: data.cadenceSeconds,
554
- now: data.now,
555
- });
556
- return lateness.lateSeconds > lateness.graceSeconds;
557
- }
558
- static hasVerdict(summary) {
559
- if (!summary || typeof summary !== "object") {
560
- return false;
561
- }
562
- const criteriaResults = summary.criteriaResults;
563
- const events = summary.events;
564
- return ((Array.isArray(criteriaResults) && criteriaResults.length > 0) ||
565
- (Array.isArray(events) && events.length > 0));
566
- }
567
- /*
568
- * The result a row reports: the first step's, when it has one, because
569
- * that is the step the hero describes; otherwise the newest result among
570
- * the monitor's current steps.
571
- */
572
- static getLatestResult(data) {
573
- var _a, _b, _c, _d;
574
- const entries = getLogEntries(data.monitorProbe, data.validStepIds);
575
- if (entries.length === 0) {
576
- return undefined;
577
- }
578
- let chosen = undefined;
579
- if (data.primaryStepId) {
580
- chosen = (_a = entries.find((entry) => {
581
- return entry[0] === data.primaryStepId;
582
- })) === null || _a === void 0 ? void 0 : _a[1];
583
- }
584
- if (!chosen) {
585
- let newestAt = -Infinity;
586
- for (const entry of entries) {
587
- const monitoredAt = MonitorCheckScheduleUtil_1.default.parseDate(entry[1].monitoredAt);
588
- const time = monitoredAt ? monitoredAt.getTime() : -Infinity;
589
- if (!chosen || time > newestAt) {
590
- chosen = entry[1];
591
- newestAt = time;
592
- }
593
- }
594
- }
595
- if (!chosen) {
596
- return undefined;
597
- }
598
- let monitoredAt = MonitorCheckScheduleUtil_1.default.parseDate(chosen.monitoredAt);
599
- // Clock skew between servers must not produce a check from the future.
600
- if (monitoredAt && monitoredAt.getTime() > data.now.getTime()) {
601
- monitoredAt = data.now;
602
- }
603
- const failureCause = typeof chosen.failureCause === "string" && chosen.failureCause.trim()
604
- ? chosen.failureCause.trim()
605
- : undefined;
606
- return {
607
- probeId: data.probeId,
608
- monitoredAt: monitoredAt,
609
- isOnline: typeof chosen.isOnline === "boolean" ? chosen.isOnline : undefined,
610
- responseTimeInMs: toFiniteNumber(chosen.responseTimeInMs),
611
- responseCode: toFiniteNumber(chosen.responseCode),
612
- failureCause: failureCause,
613
- sslExpiresAt: MonitorCheckScheduleUtil_1.default.parseDate((_b = chosen.sslResponse) === null || _b === void 0 ? void 0 : _b.expiresAt),
614
- isValidCertificate: typeof ((_c = chosen.sslResponse) === null || _c === void 0 ? void 0 : _c.isValidCertificate) === "boolean"
615
- ? chosen.sslResponse.isValidCertificate
616
- : undefined,
617
- domainExpiresAt: MonitorCheckScheduleUtil_1.default.parseDate((_d = chosen.domainResponse) === null || _d === void 0 ? void 0 : _d.expiresDate),
618
- };
619
- }
620
- static getResponseTime(data) {
621
- if (data.responseTimes.length === 0) {
622
- return null;
623
- }
624
- const sorted = [...data.responseTimes].sort((a, b) => {
625
- return a - b;
626
- });
627
- const middle = Math.floor(sorted.length / 2);
628
- const median = sorted.length % 2 === 0
629
- ? (sorted[middle - 1] + sorted[middle]) / 2
630
- : sorted[middle];
631
- return {
632
- medianMs: Math.round(median),
633
- minMs: Math.round(sorted[0]),
634
- maxMs: Math.round(sorted[sorted.length - 1]),
635
- respondedCount: sorted.length,
636
- totalCount: data.totalCount,
637
- };
638
- }
639
- }
640
- exports.default = MonitorOverviewProbeUtil;
@@ -1,3 +0,0 @@
1
- import commonJsModule from "./MonitorOverviewProbeUtil.js";
2
- export default commonJsModule.default;
3
- export const MonitorOverviewProbeHealth = commonJsModule.MonitorOverviewProbeHealth;
@@ -1,27 +0,0 @@
1
- import Color from "../../Types/Color.mjs";
2
- import MonitorStatusTimeline from "../../Models/DatabaseModels/MonitorStatusTimeline.mjs";
3
- export interface MonitorStatusChangeRow {
4
- id: string;
5
- statusName: string;
6
- statusColor: string | undefined;
7
- startsAt: Date;
8
- endsAt: Date | undefined;
9
- isOngoing: boolean;
10
- }
11
- export default class MonitorStatusHistoryUtil {
12
- static getStatusSince(data: {
13
- currentStatusId: string | undefined;
14
- latestRow: MonitorStatusTimeline | undefined;
15
- now: Date;
16
- }): Date | undefined;
17
- static hasStatusDrift(data: {
18
- currentStatusId: string | undefined;
19
- latestRow: MonitorStatusTimeline | undefined;
20
- }): boolean;
21
- static getStatusChangeRows(rows: Array<MonitorStatusTimeline>): Array<MonitorStatusChangeRow>;
22
- static getStatusFingerprint(data: {
23
- currentStatusId: string | undefined;
24
- latestRow: MonitorStatusTimeline | undefined;
25
- }): string;
26
- static normalizeColor(color: Color | string | undefined | null): string | undefined;
27
- }