@oneuptime/common 14.0.91 → 14.0.93

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 (174) hide show
  1. package/Models/DatabaseModels/Alert.js +8 -1
  2. package/Models/DatabaseModels/AlertEpisodeMember.d.mts +1 -0
  3. package/Models/DatabaseModels/AlertEpisodeMember.d.ts +1 -0
  4. package/Models/DatabaseModels/AlertEpisodeMember.js +50 -0
  5. package/Models/DatabaseModels/AutoRemediationRule.js +1 -1
  6. package/Models/DatabaseModels/CodeRepository.d.mts +1 -0
  7. package/Models/DatabaseModels/CodeRepository.d.ts +1 -0
  8. package/Models/DatabaseModels/CodeRepository.js +69 -6
  9. package/Models/DatabaseModels/IncidentEpisodeMember.d.mts +1 -0
  10. package/Models/DatabaseModels/IncidentEpisodeMember.d.ts +1 -0
  11. package/Models/DatabaseModels/IncidentEpisodeMember.js +50 -0
  12. package/Models/DatabaseModels/IncomingCallPolicy.js +1 -1
  13. package/Models/DatabaseModels/LlmProvider.js +1 -1
  14. package/Models/DatabaseModels/MonitorTemplate.js +10 -4
  15. package/Models/DatabaseModels/NetworkDeviceDiscoveryScan.js +13 -13
  16. package/Models/DatabaseModels/OnCallDutyPolicy.js +1 -1
  17. package/Models/DatabaseModels/ScheduledMaintenanceReminderRule.js +1 -1
  18. package/Models/DatabaseModels/StatusPage.d.mts +2 -0
  19. package/Models/DatabaseModels/StatusPage.d.ts +2 -0
  20. package/Models/DatabaseModels/StatusPage.js +100 -0
  21. package/Types/AI/CodeTask.d.mts +1 -0
  22. package/Types/AI/CodeTask.d.ts +1 -0
  23. package/Types/AI/TelemetryAiActivity.d.mts +1 -0
  24. package/Types/AI/TelemetryAiActivity.d.ts +1 -0
  25. package/Types/AI/TelemetryAiActivity.js +4 -0
  26. package/Types/CodeRepository/CodeRepositorySetting.d.mts +15 -0
  27. package/Types/CodeRepository/CodeRepositorySetting.d.ts +15 -0
  28. package/Types/CodeRepository/CodeRepositorySetting.js +49 -0
  29. package/Types/CodeRepository/CodeRepositorySetting.mjs +3 -0
  30. package/Types/Database/BlankColumnValue.d.mts +6 -0
  31. package/Types/Database/BlankColumnValue.d.ts +6 -0
  32. package/Types/Database/BlankColumnValue.js +77 -0
  33. package/Types/Database/BlankColumnValue.mjs +4 -0
  34. package/Types/Date.d.mts +10 -0
  35. package/Types/Date.d.ts +10 -0
  36. package/Types/Date.js +385 -98
  37. package/Types/DateLanguage.d.mts +67 -0
  38. package/Types/DateLanguage.d.ts +67 -0
  39. package/Types/DateLanguage.js +478 -0
  40. package/Types/DateLanguage.mjs +21 -0
  41. package/Types/Email/EmailTemplateType.d.mts +1 -0
  42. package/Types/Email/EmailTemplateType.d.ts +1 -0
  43. package/Types/Email/EmailTemplateType.js +1 -0
  44. package/Types/IncomingCall/IncomingCallPolicyRepeat.d.mts +6 -0
  45. package/Types/IncomingCall/IncomingCallPolicyRepeat.d.ts +6 -0
  46. package/Types/IncomingCall/IncomingCallPolicyRepeat.js +41 -14
  47. package/Types/IncomingCall/IncomingCallPolicyRepeat.mjs +3 -0
  48. package/Types/Monitor/CriteriaFilter.d.mts +1 -0
  49. package/Types/Monitor/CriteriaFilter.d.ts +1 -0
  50. package/Types/Monitor/CriteriaFilter.js +9 -0
  51. package/Types/Monitor/DatabaseMetricCatalog.js +2 -2
  52. package/Types/Monitor/KubernetesEventAlertTemplates.d.mts +20 -0
  53. package/Types/Monitor/KubernetesEventAlertTemplates.d.ts +20 -0
  54. package/Types/Monitor/KubernetesEventAlertTemplates.js +232 -0
  55. package/Types/Monitor/KubernetesEventAlertTemplates.mjs +8 -0
  56. package/Types/Monitor/MonitorType.js +12 -2
  57. package/Types/Monitor/Recommendation/MonitorRecommendationCatalog.js +27 -2
  58. package/Types/Monitor/Recommendation/MonitorRecommendationUtil.d.mts +1 -0
  59. package/Types/Monitor/Recommendation/MonitorRecommendationUtil.d.ts +1 -0
  60. package/Types/Monitor/Recommendation/MonitorRecommendationUtil.js +31 -1
  61. package/Types/Monitor/SnmpMonitor/NetworkDeviceAlertPack.d.mts +3 -1
  62. package/Types/Monitor/SnmpMonitor/NetworkDeviceAlertPack.d.ts +3 -1
  63. package/Types/Monitor/SnmpMonitor/NetworkDeviceAlertPack.js +3 -2
  64. package/Types/Monitor/SnmpMonitor/SnmpMonitorResponse.d.mts +1 -0
  65. package/Types/Monitor/SnmpMonitor/SnmpMonitorResponse.d.ts +1 -0
  66. package/Types/NotificationSetting/NotificationEmailRollupCategory.js +2 -0
  67. package/Types/NotificationSetting/NotificationEmailRollupPolicy.js +10 -3
  68. package/Types/NotificationSetting/NotificationSettingEventType.d.mts +1 -0
  69. package/Types/NotificationSetting/NotificationSettingEventType.d.ts +1 -0
  70. package/Types/NotificationSetting/NotificationSettingEventType.js +7 -0
  71. package/Types/OnCallDutyPolicy/OnCallDutyPolicyRepeat.d.mts +7 -0
  72. package/Types/OnCallDutyPolicy/OnCallDutyPolicyRepeat.d.ts +7 -0
  73. package/Types/OnCallDutyPolicy/OnCallDutyPolicyRepeat.js +51 -0
  74. package/Types/OnCallDutyPolicy/OnCallDutyPolicyRepeat.mjs +4 -0
  75. package/Types/Reminder/ScheduledMaintenanceReminderNeverReminds.d.mts +8 -0
  76. package/Types/Reminder/ScheduledMaintenanceReminderNeverReminds.d.ts +8 -0
  77. package/Types/Reminder/ScheduledMaintenanceReminderNeverReminds.js +55 -0
  78. package/Types/Reminder/ScheduledMaintenanceReminderNeverReminds.mjs +5 -0
  79. package/Types/Runner/CodeRepositoryRunner.d.mts +7 -0
  80. package/Types/Runner/CodeRepositoryRunner.d.ts +7 -0
  81. package/Types/Runner/CodeRepositoryRunner.js +60 -14
  82. package/Types/Runner/CodeRepositoryRunner.mjs +1 -0
  83. package/Types/SecurityEvent/OcsfProcessActivity.d.mts +25 -0
  84. package/Types/SecurityEvent/OcsfProcessActivity.d.ts +25 -0
  85. package/Types/SecurityEvent/OcsfProcessActivity.js +131 -0
  86. package/Types/SecurityEvent/OcsfProcessActivity.mjs +8 -0
  87. package/Types/Workflow/Templates.js +2 -5
  88. package/UI/Utils/TranslateTemplate.d.mts +73 -0
  89. package/UI/Utils/TranslateTemplate.d.ts +73 -0
  90. package/Utils/ColorContrast.d.mts +3 -0
  91. package/Utils/ColorContrast.d.ts +3 -0
  92. package/Utils/ColorContrast.js +41 -3
  93. package/Utils/ColorContrast.mjs +2 -0
  94. package/Utils/CronTab.d.mts +41 -3
  95. package/Utils/CronTab.d.ts +41 -3
  96. package/Utils/CronTab.js +112 -38
  97. package/Utils/Incident/WhoOpenedItRootCause.d.mts +2 -0
  98. package/Utils/Incident/WhoOpenedItRootCause.d.ts +2 -0
  99. package/Utils/Incident/WhoOpenedItRootCause.js +50 -0
  100. package/Utils/Incident/WhoOpenedItRootCause.mjs +3 -0
  101. package/Utils/Monitor/MonitorOverviewTargetUtil.d.mts +2 -0
  102. package/Utils/Monitor/MonitorOverviewTargetUtil.d.ts +2 -0
  103. package/Utils/Monitor/MonitorOverviewTargetUtil.js +13 -2
  104. package/Utils/Monitor/SyntheticMonitorStepsUtil.d.mts +18 -0
  105. package/Utils/Monitor/SyntheticMonitorStepsUtil.d.ts +18 -0
  106. package/Utils/Monitor/SyntheticMonitorStepsUtil.js +129 -0
  107. package/Utils/Monitor/SyntheticMonitorStepsUtil.mjs +4 -0
  108. package/Utils/Rules/RuleRunSummary.d.mts +1 -0
  109. package/Utils/Rules/RuleRunSummary.d.ts +1 -0
  110. package/Utils/Rules/RuleRunSummary.js +19 -1
  111. package/Utils/Rules/RuleRunSummary.mjs +1 -0
  112. package/Utils/SecurityEvent/Destinations/GoogleSecOpsUdmMapper.d.mts +5 -0
  113. package/Utils/SecurityEvent/Destinations/GoogleSecOpsUdmMapper.d.ts +5 -0
  114. package/Utils/SecurityEvent/Destinations/GoogleSecOpsUdmMapper.js +219 -58
  115. package/Utils/SecurityEvent/OcsfNormalizer.js +22 -13
  116. package/Utils/Slo/SloDuration.d.mts +1 -0
  117. package/Utils/Slo/SloDuration.d.ts +1 -0
  118. package/Utils/Slo/SloDuration.js +57 -8
  119. package/Utils/Slo/SloDuration.mjs +1 -0
  120. package/Utils/Sms/Gsm7Text.js +9 -1
  121. package/Utils/Sms/OnCallPageSms.d.mts +2 -0
  122. package/Utils/Sms/OnCallPageSms.d.ts +2 -0
  123. package/Utils/Sms/OnCallPageSms.js +19 -2
  124. package/Utils/Sms/OnCallPageSms.mjs +1 -0
  125. package/Utils/Sms/SubscriberSms.d.mts +2 -0
  126. package/Utils/Sms/SubscriberSms.d.ts +2 -0
  127. package/Utils/Sms/SubscriberSms.js +35 -0
  128. package/Utils/Sms/SubscriberSms.mjs +3 -0
  129. package/Utils/Suggestions/CodeFixSuggestion.d.mts +15 -0
  130. package/Utils/Suggestions/CodeFixSuggestion.d.ts +15 -0
  131. package/Utils/Suggestions/CodeFixSuggestion.js +62 -1
  132. package/Utils/Suggestions/CodeFixSuggestion.mjs +4 -0
  133. package/Utils/Suggestions/ProfileFixSuggestion.js +4 -0
  134. package/Utils/Suggestions/SuggestionBlocker.d.mts +8 -0
  135. package/Utils/Suggestions/SuggestionBlocker.d.ts +8 -0
  136. package/Utils/Suggestions/SuggestionBlocker.js +51 -0
  137. package/Utils/Suggestions/SuggestionBlocker.mjs +4 -0
  138. package/Utils/Suggestions/SuggestionOffer.d.mts +2 -1
  139. package/Utils/Suggestions/SuggestionOffer.d.ts +2 -1
  140. package/Utils/Suggestions/SuggestionOffer.js +5 -0
  141. package/Utils/Suggestions/TelemetryAiFixSuggestion.d.mts +2 -7
  142. package/Utils/Suggestions/TelemetryAiFixSuggestion.d.ts +2 -7
  143. package/Utils/Suggestions/TelemetryAiFixSuggestion.js +8 -36
  144. package/Utils/Suggestions/TelemetryImprovementSuggestion.d.mts +1 -0
  145. package/Utils/Suggestions/TelemetryImprovementSuggestion.d.ts +1 -0
  146. package/Utils/Suggestions/TelemetryImprovementSuggestion.js +1 -0
  147. package/Utils/Suggestions/TracePerformanceFixSuggestion.d.mts +6 -0
  148. package/Utils/Suggestions/TracePerformanceFixSuggestion.d.ts +6 -0
  149. package/Utils/Suggestions/TracePerformanceFixSuggestion.js +46 -5
  150. package/package.json +8 -1
  151. package/Utils/Monitor/MonitorCheckScheduleUtil.d.mts +0 -61
  152. package/Utils/Monitor/MonitorCheckScheduleUtil.d.ts +0 -61
  153. package/Utils/Monitor/MonitorCheckScheduleUtil.js +0 -476
  154. package/Utils/Monitor/MonitorCheckScheduleUtil.mjs +0 -3
  155. package/Utils/Monitor/MonitorOverviewFamily.d.mts +0 -39
  156. package/Utils/Monitor/MonitorOverviewFamily.d.ts +0 -39
  157. package/Utils/Monitor/MonitorOverviewFamily.js +0 -206
  158. package/Utils/Monitor/MonitorOverviewFamily.mjs +0 -4
  159. package/Utils/Monitor/MonitorOverviewPresentationUtil.d.mts +0 -189
  160. package/Utils/Monitor/MonitorOverviewPresentationUtil.d.ts +0 -189
  161. package/Utils/Monitor/MonitorOverviewPresentationUtil.js +0 -1480
  162. package/Utils/Monitor/MonitorOverviewPresentationUtil.mjs +0 -5
  163. package/Utils/Monitor/MonitorOverviewProbeUtil.d.mts +0 -112
  164. package/Utils/Monitor/MonitorOverviewProbeUtil.d.ts +0 -112
  165. package/Utils/Monitor/MonitorOverviewProbeUtil.js +0 -640
  166. package/Utils/Monitor/MonitorOverviewProbeUtil.mjs +0 -3
  167. package/Utils/Monitor/MonitorStatusHistoryUtil.d.mts +0 -27
  168. package/Utils/Monitor/MonitorStatusHistoryUtil.d.ts +0 -27
  169. package/Utils/Monitor/MonitorStatusHistoryUtil.js +0 -132
  170. package/Utils/Monitor/MonitorStatusHistoryUtil.mjs +0 -2
  171. package/Utils/Monitor/MonitorUptimeSummaryUtil.d.mts +0 -42
  172. package/Utils/Monitor/MonitorUptimeSummaryUtil.d.ts +0 -42
  173. package/Utils/Monitor/MonitorUptimeSummaryUtil.js +0 -468
  174. package/Utils/Monitor/MonitorUptimeSummaryUtil.mjs +0 -2
@@ -1,1480 +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.MONITOR_LOG_MINIMUM_RETENTION_SECONDS = exports.isMonitorOverviewActionCallToAction = exports.MonitorOverviewRunState = void 0;
40
- const Date_1 = __importDefault(require("../../Types/Date"));
41
- const CriteriaFilter_1 = require("../../Types/Monitor/CriteriaFilter");
42
- const MonitorType_1 = __importDefault(require("../../Types/Monitor/MonitorType"));
43
- const SloDuration_1 = require("../Slo/SloDuration");
44
- const MonitorCheckScheduleUtil_1 = __importStar(require("./MonitorCheckScheduleUtil"));
45
- const MonitorOverviewCriteriaUtil_1 = __importDefault(require("./MonitorOverviewCriteriaUtil"));
46
- const MonitorOverviewFamily_1 = __importStar(require("./MonitorOverviewFamily"));
47
- const MonitorStatusHistoryUtil_1 = __importDefault(require("./MonitorStatusHistoryUtil"));
48
- const ProbeStatusMonitorUtil_1 = __importDefault(require("./ProbeStatusMonitorUtil"));
49
- const MonitorOverviewTargetUtil_1 = __importDefault(require("./MonitorOverviewTargetUtil"));
50
- /*
51
- * The monitor overview's hero, facts, pulse and section switches, decided in
52
- * one pure function so every per-type and per-state rule is unit-tested
53
- * without React.
54
- *
55
- * The rule it is built around: never claim health that was not measured. A
56
- * paused monitor, one nobody is checking, one with no criteria and one still
57
- * waiting for its first result are never shown as Good, and never lead with
58
- * the stored status name (which only describes the last thing that was
59
- * recorded). Unknown is never rendered as zero.
60
- */
61
- var MonitorOverviewRunState;
62
- (function (MonitorOverviewRunState) {
63
- MonitorOverviewRunState["Manual"] = "Manual";
64
- MonitorOverviewRunState["Paused"] = "Paused";
65
- MonitorOverviewRunState["NotChecking"] = "NotChecking";
66
- MonitorOverviewRunState["NotConfigured"] = "NotConfigured";
67
- MonitorOverviewRunState["AwaitingFirstData"] = "AwaitingFirstData";
68
- MonitorOverviewRunState["Overdue"] = "Overdue";
69
- MonitorOverviewRunState["Running"] = "Running";
70
- })(MonitorOverviewRunState || (exports.MonitorOverviewRunState = MonitorOverviewRunState = {}));
71
- // Whether the hero's call to action is done in place (a button).
72
- const isMonitorOverviewActionCallToAction = (callToAction) => {
73
- return callToAction.actionKey !== undefined;
74
- };
75
- exports.isMonitorOverviewActionCallToAction = isMonitorOverviewActionCallToAction;
76
- const MAX_FACTS = 4;
77
- /*
78
- * ServerMonitor/CheckOnlineStatus judges an agent that has not reported for
79
- * three minutes, counting from creation when it never has.
80
- */
81
- const AGENT_MISSING_MINUTES = 3;
82
- const PAUSED_EXPLANATION = {
83
- archived: "No checks run while the monitor is archived, so the status stays at the last one recorded. It opens no incidents or alerts and is hidden from monitor lists and status pages.",
84
- disabled: "No checks run while monitoring is off, so the status stays at the last one recorded.",
85
- incident: "Checks resume when the incident that paused this monitor is resolved.",
86
- maintenance: "Checks resume automatically when the maintenance event ends.",
87
- };
88
- const MANUAL_EXPLANATION = "Manual monitor: OneUptime runs no checks. The status changes when someone sets it, or when an incident or scheduled maintenance event changes it.";
89
- /*
90
- * What an empty evaluation log says once the monitor is older than the
91
- * log keeps rows (MONITOR_LOG_MINIMUM_RETENTION_SECONDS): not "never".
92
- */
93
- const NOT_EVALUATED_IN_LOG_TEXT = "Not evaluated in the last day";
94
- const pluralize = (count, singular, plural) => {
95
- return `${count} ${count === 1 ? singular : plural}`;
96
- };
97
- const lowerFirst = (text) => {
98
- return text ? text.charAt(0).toLowerCase() + text.slice(1) : text;
99
- };
100
- const secondsSince = (now, then) => {
101
- return Math.max(0, Math.floor((now.getTime() - then.getTime()) / 1000));
102
- };
103
- const HOUR_MS = 3600 * 1000;
104
- const DAY_MS = 24 * HOUR_MS;
105
- const DAY_SECONDS = 24 * 3600;
106
- /*
107
- * The evaluation log (MonitorLog) keeps each row for at least
108
- * MonitorLogUtil.DEFAULT_RETENTION_DAYS, one day, unless an admin has
109
- * raised GlobalConfig.monitorLogRetentionInDays. So an empty log proves
110
- * only that nothing was evaluated in the last day and, for a monitor
111
- * younger than that, that nothing ever was. The copy that says "in the
112
- * last day" follows this.
113
- */
114
- exports.MONITOR_LOG_MINIMUM_RETENTION_SECONDS = DAY_SECONDS;
115
- /*
116
- * A row can also outlive that by up to about a day: the TTL ("retentionDate
117
- * DELETE", ttl_only_drop_parts) drops a whole daily partition
118
- * (toYYYYMMDD(time)) only once its newest row has expired too. So a run
119
- * between two days and one day ago may or may not still be in the log, and
120
- * its absence proves nothing. An empty log is therefore judged from one day
121
- * ago, the guaranteed retention: a schedule that was due after that point
122
- * would still have its row, so Stale from there really means a missed run.
123
- * Judging from the two-day maximum instead flagged gapped schedules
124
- * (weekday business hours) as overdue every weekend.
125
- */
126
- // "3 hours", or "20 minutes" under an hour. Never "0 minutes".
127
- const describeUnderADay = (ms) => {
128
- const hours = Math.floor(ms / HOUR_MS);
129
- if (hours >= 1) {
130
- return pluralize(hours, "hour", "hours");
131
- }
132
- return pluralize(Math.max(1, Math.floor(ms / 60000)), "minute", "minutes");
133
- };
134
- /*
135
- * Calendar days from `earlier` to `later` in the zone dates are printed in.
136
- * Only called for times at least a day apart, so it is at least 1 (a
137
- * 25-hour daylight-saving day could otherwise make it 0).
138
- */
139
- const getCalendarDaysBetween = (earlier, later) => {
140
- const timezone = Date_1.default.getCurrentTimezone();
141
- const days = Math.round((Date_1.default.getStartOfDay(later, timezone).getTime() -
142
- Date_1.default.getStartOfDay(earlier, timezone).getTime()) /
143
- DAY_MS);
144
- return Math.max(1, days);
145
- };
146
- const isFutureOf = (date, now) => {
147
- return Boolean(date && date.getTime() > now.getTime());
148
- };
149
- class MonitorOverviewPresentationUtil {
150
- static build(input) {
151
- const context = MonitorOverviewPresentationUtil.getContext(input);
152
- const hero = MonitorOverviewPresentationUtil.getHero(input, context);
153
- return Object.assign(Object.assign({ family: context.family, runState: context.runState }, hero), { moreActions: MonitorOverviewPresentationUtil.getMoreActions(context), pulse: MonitorOverviewPresentationUtil.getPulse(input, context), freshness: context.freshness.freshness, isNeverReported: MonitorOverviewPresentationUtil.isNeverReported(context), facts: MonitorOverviewPresentationUtil.getFacts(input, context), target: MonitorOverviewTargetUtil_1.default.getTarget({
154
- monitorType: input.monitorType,
155
- monitorSteps: input.monitorSteps,
156
- serverHostname: input.agent.hostname,
157
- }), sections: MonitorOverviewPresentationUtil.getSections(context) });
158
- }
159
- /*
160
- * What the hero's More actions (⋯) menu offers. A manual monitor's status
161
- * is whatever a person sets, so changing it is there - kept behind the
162
- * menu rather than drawn as the hero's call to action. Every other monitor
163
- * sets its own status from its checks, and its next check would undo a
164
- * change made by hand, so it gets no menu (its history is still edited on
165
- * the Status Timeline page).
166
- */
167
- static getMoreActions(data) {
168
- return data.runState === MonitorOverviewRunState.Manual
169
- ? ["changeStatus"]
170
- : [];
171
- }
172
- /*
173
- * First match wins: Manual, Paused, NotChecking (probe checks only),
174
- * NotConfigured, AwaitingFirstData, Overdue, Running.
175
- */
176
- static getRunState(input) {
177
- return MonitorOverviewPresentationUtil.getContext(input).runState;
178
- }
179
- /*
180
- * What the uptime tiles must add about time the status timeline counts
181
- * but nothing measured: its open row keeps the last status while
182
- * monitoring is paused, while nothing checks, and before the first check
183
- * completes. A manual monitor has no checks to pause, so it never gets
184
- * one.
185
- */
186
- static getUptimeCaveat(presentation) {
187
- if (presentation.family === MonitorOverviewFamily_1.MonitorOverviewFamily.Manual) {
188
- return null;
189
- }
190
- switch (presentation.runState) {
191
- case MonitorOverviewRunState.Paused:
192
- return "paused";
193
- case MonitorOverviewRunState.NotChecking:
194
- case MonitorOverviewRunState.NotConfigured:
195
- return "not-checking";
196
- case MonitorOverviewRunState.Overdue:
197
- return presentation.isNeverReported ? "no-results" : null;
198
- default:
199
- return null;
200
- }
201
- }
202
- static getStatusTone(status) {
203
- if (!status) {
204
- return "neutral";
205
- }
206
- // Offline first: a status flagged both ways must never read as good.
207
- if (status.isOfflineState) {
208
- return "danger";
209
- }
210
- if (status.isOperationalState) {
211
- return "good";
212
- }
213
- return "warning";
214
- }
215
- static getExpiryFact(data) {
216
- const label = data.key === "certificate-expiry"
217
- ? "Certificate expires"
218
- : "Domain expires";
219
- const secondary = data.expiresAt
220
- ? Date_1.default.getDateAsUserFriendlyLocalFormattedString(data.expiresAt, true)
221
- : undefined;
222
- if (data.isValidCertificate === false) {
223
- return {
224
- key: data.key,
225
- label: label,
226
- value: "Not valid",
227
- secondary: secondary,
228
- tone: "danger",
229
- };
230
- }
231
- if (!data.expiresAt) {
232
- return { key: data.key, label: label, value: "—", isMuted: true };
233
- }
234
- const msLeft = data.expiresAt.getTime() - data.now.getTime();
235
- /*
236
- * Within a day either way, hours say it exactly. Beyond that, days are
237
- * counted on the calendar of the zone the date below is printed in, so
238
- * "in 2 days" and the printed date agree: 36 hours from noon is two
239
- * calendar days away, not the one day a floor would give.
240
- */
241
- if (msLeft < 0) {
242
- return {
243
- key: data.key,
244
- label: label,
245
- value: -msLeft < DAY_MS
246
- ? `Expired ${describeUnderADay(-msLeft)} ago`
247
- : `Expired ${pluralize(getCalendarDaysBetween(data.expiresAt, data.now), "day", "days")} ago`,
248
- secondary: secondary,
249
- tone: "danger",
250
- };
251
- }
252
- if (msLeft < DAY_MS) {
253
- return {
254
- key: data.key,
255
- label: label,
256
- value: `Expires in ${describeUnderADay(msLeft)}`,
257
- secondary: secondary,
258
- tone: "danger",
259
- };
260
- }
261
- // The tone keeps counting whole days left, as it always has.
262
- const wholeDays = Math.floor(msLeft / DAY_MS);
263
- let tone = "neutral";
264
- if (wholeDays <= 7) {
265
- tone = "danger";
266
- }
267
- else if (wholeDays <= 30) {
268
- tone = "warning";
269
- }
270
- return {
271
- key: data.key,
272
- label: label,
273
- value: `in ${pluralize(getCalendarDaysBetween(data.now, data.expiresAt), "day", "days")}`,
274
- secondary: secondary,
275
- tone: tone,
276
- };
277
- }
278
- static getContext(input) {
279
- const layout = MonitorOverviewFamily_1.default.getLayout(input.monitorType);
280
- const family = layout.family;
281
- const cadenceSeconds = MonitorCheckScheduleUtil_1.default.resolveCadenceSeconds({
282
- monitoringInterval: input.monitoringInterval,
283
- from: input.now,
284
- });
285
- const intervalText = MonitorCheckScheduleUtil_1.default.describeInterval(input.monitoringInterval);
286
- const stepCount = MonitorOverviewCriteriaUtil_1.default.getStepCount(input.monitorSteps);
287
- const networkDeviceId = MonitorOverviewCriteriaUtil_1.default.getNetworkDeviceId(input.monitorSteps);
288
- const watchedProbeCount = family === MonitorOverviewFamily_1.MonitorOverviewFamily.ProbeStatus
289
- ? ProbeStatusMonitorUtil_1.default.getWatchedProbeIds(input.monitorSteps).length
290
- : 0;
291
- const isPaused = Boolean(input.pause.isArchived) ||
292
- input.pause.isDisabled ||
293
- input.pause.byManualIncident ||
294
- input.pause.byScheduledMaintenance;
295
- const isProbeCheck = family === MonitorOverviewFamily_1.MonitorOverviewFamily.ProbeCheck;
296
- /*
297
- * The server keeps these flags on the Monitor row; the probe rows, when
298
- * they could be read, say the same thing sooner.
299
- */
300
- const isNoProbeEnabled = isProbeCheck &&
301
- (input.probeFlags.isNoProbeEnabled ||
302
- (input.probes !== null && input.probes.enabledCount === 0));
303
- const isAllProbesDisconnected = isProbeCheck &&
304
- (input.probeFlags.isAllProbesDisconnected ||
305
- (input.probes !== null &&
306
- input.probes.enabledCount > 0 &&
307
- input.probes.disconnectedCount === input.probes.enabledCount));
308
- const isNotChecking = isNoProbeEnabled || isAllProbesDisconnected;
309
- const evaluationStatus = MonitorOverviewPresentationUtil.getEvaluationStatus(input);
310
- const evaluationLog = MonitorOverviewPresentationUtil.readEvaluationLog({
311
- input: input,
312
- family: family,
313
- evaluationStatus: evaluationStatus,
314
- });
315
- const isScheduled = !isPaused && !isNotChecking;
316
- const telemetry = MonitorOverviewPresentationUtil.isTelemetryFamily(family)
317
- ? MonitorOverviewPresentationUtil.getTelemetryTiming({
318
- input: input,
319
- evaluationLog: evaluationLog,
320
- cadenceSeconds: cadenceSeconds,
321
- isScheduled: isScheduled,
322
- })
323
- : null;
324
- const freshness = telemetry
325
- ? telemetry.freshness
326
- : MonitorOverviewPresentationUtil.getFreshness({
327
- input: input,
328
- family: family,
329
- cadenceSeconds: cadenceSeconds,
330
- isScheduled: isScheduled,
331
- });
332
- let runState = MonitorOverviewRunState.Running;
333
- if (family === MonitorOverviewFamily_1.MonitorOverviewFamily.Manual) {
334
- runState = MonitorOverviewRunState.Manual;
335
- }
336
- else if (isPaused) {
337
- runState = MonitorOverviewRunState.Paused;
338
- }
339
- else if (isNotChecking) {
340
- runState = MonitorOverviewRunState.NotChecking;
341
- }
342
- else if (stepCount === 0 ||
343
- (family === MonitorOverviewFamily_1.MonitorOverviewFamily.NetworkDevice && !networkDeviceId) ||
344
- // Nothing to evaluate: the server skips a step that watches no probe.
345
- (family === MonitorOverviewFamily_1.MonitorOverviewFamily.ProbeStatus && watchedProbeCount === 0)) {
346
- runState = MonitorOverviewRunState.NotConfigured;
347
- }
348
- else if (MonitorOverviewPresentationUtil.isAwaitingFirstData({
349
- input: input,
350
- family: family,
351
- freshness: freshness.freshness,
352
- evaluationLog: evaluationLog,
353
- telemetry: telemetry,
354
- })) {
355
- runState = MonitorOverviewRunState.AwaitingFirstData;
356
- }
357
- else if (freshness.freshness === MonitorCheckScheduleUtil_1.MonitorCheckFreshness.Stale) {
358
- runState = MonitorOverviewRunState.Overdue;
359
- }
360
- return {
361
- family: family,
362
- layout: layout,
363
- cadenceSeconds: cadenceSeconds,
364
- intervalText: intervalText,
365
- intervalPhrase: lowerFirst(intervalText),
366
- stepCount: stepCount,
367
- networkDeviceId: networkDeviceId,
368
- watchedProbeCount: watchedProbeCount,
369
- isPaused: isPaused,
370
- isNoProbeEnabled: isNoProbeEnabled,
371
- isAllProbesDisconnected: isAllProbesDisconnected,
372
- isNotChecking: isNotChecking,
373
- evaluationStatus: evaluationStatus,
374
- evaluationLog: evaluationLog,
375
- telemetry: telemetry,
376
- freshness: freshness,
377
- runState: runState,
378
- hasPushVerdict: runState === MonitorOverviewRunState.AwaitingFirstData &&
379
- MonitorOverviewPresentationUtil.hasPushVerdict({
380
- input: input,
381
- family: family,
382
- }),
383
- };
384
- }
385
- /*
386
- * Without an explicit status (callers from before evaluationStatus), a
387
- * time means the log was read; its absence says nothing.
388
- */
389
- static getEvaluationStatus(input) {
390
- if (input.evaluationStatus) {
391
- return input.evaluationStatus;
392
- }
393
- return input.latestEvaluationAt ? "loaded" : null;
394
- }
395
- static isTelemetryFamily(family) {
396
- return (family === MonitorOverviewFamily_1.MonitorOverviewFamily.TelemetrySignal ||
397
- family === MonitorOverviewFamily_1.MonitorOverviewFamily.Infrastructure);
398
- }
399
- /*
400
- * An empty log means "never evaluated" only while it would still hold
401
- * every evaluation the monitor could have had. Past that, its rows may
402
- * simply have expired.
403
- */
404
- static readEvaluationLog(data) {
405
- const input = data.input;
406
- if (data.evaluationStatus !== "loaded") {
407
- return "unread";
408
- }
409
- if (input.latestEvaluationAt) {
410
- return "evaluated";
411
- }
412
- const isYoungerThanLog = !input.createdAt ||
413
- input.now.getTime() - input.createdAt.getTime() <
414
- exports.MONITOR_LOG_MINIMUM_RETENTION_SECONDS * 1000;
415
- /*
416
- * The telemetry worker stamps a monitor each time it queues an
417
- * evaluation, so one it has never stamped has never been evaluated,
418
- * however old it is.
419
- */
420
- const isNeverQueued = MonitorOverviewPresentationUtil.isTelemetryFamily(data.family) &&
421
- !input.telemetry.lastScheduledAt &&
422
- !input.telemetry.lastEvaluatedAt;
423
- return isYoungerThanLog || isNeverQueued ? "never" : "expired";
424
- }
425
- /*
426
- * With a row in the evaluation log, its time. Without the log, the
427
- * scheduler's stamp, named for what it is. With a log that is empty only
428
- * because its rows expired, the log still says nothing was evaluated in
429
- * the last day: that is overdue when the schedule should have left a row
430
- * there, and otherwise (a weekly schedule, say) expected, so the stamp is
431
- * all there is, as without the log.
432
- */
433
- static getTelemetryTiming(data) {
434
- const input = data.input;
435
- const scheduledAt = input.telemetry.lastScheduledAt || input.telemetry.lastEvaluatedAt;
436
- const judge = (lastResultAt, createdAt) => {
437
- return MonitorCheckScheduleUtil_1.default.getCheckFreshness({
438
- isScheduled: data.isScheduled,
439
- isKnown: true,
440
- lastResultAt: lastResultAt,
441
- nextCheckAt: input.telemetry.nextEvaluationAt,
442
- cadenceSeconds: data.cadenceSeconds,
443
- createdAt: createdAt,
444
- now: input.now,
445
- monitoringInterval: input.monitoringInterval,
446
- });
447
- };
448
- const fromScheduler = () => {
449
- return {
450
- lastAt: scheduledAt,
451
- isScheduledTime: true,
452
- isMissingFromLog: false,
453
- freshness: judge(scheduledAt, input.createdAt),
454
- };
455
- };
456
- switch (data.evaluationLog) {
457
- case "evaluated":
458
- return {
459
- lastAt: input.latestEvaluationAt,
460
- isScheduledTime: false,
461
- isMissingFromLog: false,
462
- freshness: judge(input.latestEvaluationAt, input.createdAt),
463
- };
464
- case "never":
465
- return {
466
- lastAt: undefined,
467
- isScheduledTime: false,
468
- isMissingFromLog: false,
469
- freshness: judge(undefined, input.createdAt),
470
- };
471
- case "expired": {
472
- // The log only reads as expired for a monitor with a creation time.
473
- const createdAt = input.createdAt || input.now;
474
- const horizonStart = new Date(Math.max(createdAt.getTime(), input.now.getTime() - exports.MONITOR_LOG_MINIMUM_RETENTION_SECONDS * 1000));
475
- if (judge(undefined, horizonStart).freshness !==
476
- MonitorCheckScheduleUtil_1.MonitorCheckFreshness.Stale) {
477
- return fromScheduler();
478
- }
479
- /*
480
- * How long ago the last evaluation ran, and so how late the next
481
- * one is, is unknown: the log only says it was before the last day.
482
- */
483
- return {
484
- lastAt: undefined,
485
- isScheduledTime: false,
486
- isMissingFromLog: true,
487
- freshness: {
488
- freshness: MonitorCheckScheduleUtil_1.MonitorCheckFreshness.Stale,
489
- overdueSeconds: null,
490
- resultAgeSeconds: null,
491
- },
492
- };
493
- }
494
- default:
495
- return fromScheduler();
496
- }
497
- }
498
- /*
499
- * A push monitor's missing-signal check counts from creation when nothing
500
- * has arrived yet, so the server judges it once this window has passed.
501
- * Null when its criteria have no such check.
502
- */
503
- static getPushMissingMinutes(data) {
504
- const monitorSteps = data.input.monitorSteps;
505
- if (data.family === MonitorOverviewFamily_1.MonitorOverviewFamily.Agent) {
506
- return MonitorOverviewCriteriaUtil_1.default.hasFilterOn({
507
- monitorSteps: monitorSteps,
508
- checkOn: CriteriaFilter_1.CheckOn.IsOnline,
509
- })
510
- ? AGENT_MISSING_MINUTES
511
- : null;
512
- }
513
- if (data.family !== MonitorOverviewFamily_1.MonitorOverviewFamily.Heartbeat) {
514
- return null;
515
- }
516
- return MonitorOverviewCriteriaUtil_1.default.getMissingSignalMinutes({
517
- monitorSteps: monitorSteps,
518
- checkOn: data.input.monitorType === MonitorType_1.default.IncomingEmail
519
- ? CriteriaFilter_1.CheckOn.EmailReceivedAt
520
- : CriteriaFilter_1.CheckOn.IncomingRequest,
521
- });
522
- }
523
- static hasPushVerdict(data) {
524
- if (data.family !== MonitorOverviewFamily_1.MonitorOverviewFamily.Heartbeat &&
525
- data.family !== MonitorOverviewFamily_1.MonitorOverviewFamily.Agent) {
526
- return false;
527
- }
528
- if (MonitorOverviewPresentationUtil.isJudgedStatus(data.input)) {
529
- return true;
530
- }
531
- const minutes = MonitorOverviewPresentationUtil.getPushMissingMinutes(data);
532
- const createdAt = data.input.createdAt;
533
- return (minutes !== null &&
534
- createdAt !== undefined &&
535
- data.input.now.getTime() - createdAt.getTime() > minutes * 60 * 1000);
536
- }
537
- /*
538
- * A status that is not operational was set by something: for a push
539
- * monitor that never reported, the server's missing-signal check.
540
- */
541
- static isJudgedStatus(input) {
542
- const tone = MonitorOverviewPresentationUtil.getStatusTone(input.currentStatus);
543
- return tone === "danger" || tone === "warning";
544
- }
545
- /*
546
- * Freshness is only judged for the families that run on a schedule we can
547
- * see: probe checks here, and the worker-evaluated telemetry and
548
- * infrastructure monitors in getTelemetryTiming. Push-based monitors
549
- * decide "missing" in their own criteria.
550
- */
551
- static getFreshness(data) {
552
- var _a, _b, _c;
553
- const input = data.input;
554
- if (data.family === MonitorOverviewFamily_1.MonitorOverviewFamily.ProbeCheck) {
555
- return MonitorCheckScheduleUtil_1.default.getCheckFreshness({
556
- isScheduled: data.isScheduled,
557
- isKnown: input.probes !== null,
558
- lastResultAt: (_a = input.probes) === null || _a === void 0 ? void 0 : _a.lastResultAt,
559
- /*
560
- * Behind schedule only when every probe that is checking is: a
561
- * summary from before latestNextCheckAt existed has only the
562
- * earliest.
563
- */
564
- nextCheckAt: ((_b = input.probes) === null || _b === void 0 ? void 0 : _b.latestNextCheckAt) || ((_c = input.probes) === null || _c === void 0 ? void 0 : _c.nextCheckAt),
565
- cadenceSeconds: data.cadenceSeconds,
566
- createdAt: input.createdAt,
567
- now: input.now,
568
- monitoringInterval: input.monitoringInterval,
569
- });
570
- }
571
- return MonitorCheckScheduleUtil_1.default.getCheckFreshness({
572
- isScheduled: false,
573
- isKnown: true,
574
- lastResultAt: undefined,
575
- nextCheckAt: undefined,
576
- cadenceSeconds: data.cadenceSeconds,
577
- createdAt: input.createdAt,
578
- now: input.now,
579
- });
580
- }
581
- static isAwaitingFirstData(data) {
582
- var _a;
583
- const input = data.input;
584
- switch (data.family) {
585
- case MonitorOverviewFamily_1.MonitorOverviewFamily.ProbeCheck:
586
- return (input.probes !== null &&
587
- input.probes.enabledCount > 0 &&
588
- data.freshness === MonitorCheckScheduleUtil_1.MonitorCheckFreshness.AwaitingFirstResult);
589
- case MonitorOverviewFamily_1.MonitorOverviewFamily.Heartbeat:
590
- return input.monitorType === MonitorType_1.default.IncomingEmail
591
- ? !input.email.lastReceivedAt
592
- : !input.heartbeat.lastReceivedAt;
593
- case MonitorOverviewFamily_1.MonitorOverviewFamily.Agent:
594
- return !input.agent.lastReportAt;
595
- case MonitorOverviewFamily_1.MonitorOverviewFamily.TelemetrySignal:
596
- case MonitorOverviewFamily_1.MonitorOverviewFamily.Infrastructure:
597
- /*
598
- * Without the evaluation log, the scheduler's stamp is all there
599
- * is. With it, "waiting" needs a log that says nothing was ever
600
- * evaluated, and, like a probe check, lasts only while the monitor
601
- * is young: past that, no evaluation is overdue (6b).
602
- */
603
- if (data.evaluationLog === "unread") {
604
- return !((_a = data.telemetry) === null || _a === void 0 ? void 0 : _a.lastAt);
605
- }
606
- return (data.evaluationLog === "never" &&
607
- data.freshness === MonitorCheckScheduleUtil_1.MonitorCheckFreshness.AwaitingFirstResult);
608
- case MonitorOverviewFamily_1.MonitorOverviewFamily.NetworkDevice:
609
- /*
610
- * A device is evaluated on its polls and traps, which leave no
611
- * trace on the monitor row: only an empty log that would still hold
612
- * every evaluation says none has happened yet. For an older
613
- * monitor, it says only that none happened in the last day.
614
- */
615
- return data.evaluationLog === "never";
616
- case MonitorOverviewFamily_1.MonitorOverviewFamily.ProbeStatus:
617
- // Its evaluations leave a trace only in the log, as a device's do.
618
- return data.evaluationLog === "never";
619
- default:
620
- // Manual monitors are never evaluated.
621
- return false;
622
- }
623
- }
624
- static getHero(input, context) {
625
- const status = input.currentStatus;
626
- const statusTone = MonitorOverviewPresentationUtil.getStatusTone(status);
627
- const lastKnownStatus = status
628
- ? `Last recorded status: ${status.name}`
629
- : undefined;
630
- // The badge and headline for the states that lead with the status.
631
- const statusBadge = status
632
- ? {
633
- text: status.name,
634
- tone: statusTone,
635
- statusColor: MonitorStatusHistoryUtil_1.default.normalizeColor(status.color),
636
- }
637
- : { text: "Unknown status", tone: "neutral" };
638
- const statusHeadline = status
639
- ? { text: status.name, since: input.statusSince }
640
- : { text: "No status recorded yet" };
641
- switch (context.runState) {
642
- /*
643
- * No call to action: changing the status is in the hero's More actions
644
- * (⋯) menu, beside Refresh (getMoreActions).
645
- */
646
- case MonitorOverviewRunState.Manual:
647
- return {
648
- tone: statusTone,
649
- badge: statusBadge,
650
- secondaryBadges: [{ text: "Manual", tone: "neutral" }],
651
- headline: statusHeadline,
652
- explanation: MANUAL_EXPLANATION,
653
- };
654
- case MonitorOverviewRunState.Paused: {
655
- const secondaryBadges = [];
656
- /*
657
- * Pausing does not fix a probe problem, and the problem is still
658
- * there when monitoring resumes, so it stays visible.
659
- */
660
- if (context.isNoProbeEnabled) {
661
- secondaryBadges.push({ text: "Probes Not Enabled", tone: "danger" });
662
- }
663
- else if (context.isAllProbesDisconnected) {
664
- secondaryBadges.push({
665
- text: "Probes Disconnected",
666
- tone: "danger",
667
- });
668
- }
669
- /*
670
- * Archived before Disabled: it is the reason that also explains why
671
- * the monitor is missing from the lists, and unarchiving is the step
672
- * that brings it back (a disabled monitor then still needs enabling).
673
- */
674
- if (input.pause.isArchived) {
675
- return {
676
- tone: "neutral",
677
- badge: { text: "Archived", tone: "neutral" },
678
- secondaryBadges: secondaryBadges,
679
- headline: { text: "Monitoring is off because it is archived" },
680
- explanation: PAUSED_EXPLANATION.archived,
681
- lastKnownStatus: lastKnownStatus,
682
- callToAction: { text: "Open settings", linkKey: "settings" },
683
- };
684
- }
685
- /*
686
- * Someone turned monitoring off: the hero turns it back on in place,
687
- * where it used to send the reader to Settings to find the switch.
688
- */
689
- if (input.pause.isDisabled) {
690
- return {
691
- tone: "neutral",
692
- badge: { text: "Disabled", tone: "neutral" },
693
- secondaryBadges: secondaryBadges,
694
- headline: { text: "Monitoring is turned off" },
695
- explanation: PAUSED_EXPLANATION.disabled,
696
- lastKnownStatus: lastKnownStatus,
697
- callToAction: {
698
- text: "Turn monitoring on",
699
- actionKey: "turnMonitoringOn",
700
- },
701
- };
702
- }
703
- if (input.pause.byManualIncident) {
704
- return {
705
- tone: "neutral",
706
- badge: { text: "Paused", tone: "neutral" },
707
- secondaryBadges: secondaryBadges,
708
- headline: { text: "Monitoring is paused by an incident" },
709
- explanation: PAUSED_EXPLANATION.incident,
710
- lastKnownStatus: lastKnownStatus,
711
- callToAction: { text: "View incidents", linkKey: "incidents" },
712
- };
713
- }
714
- return {
715
- tone: "neutral",
716
- badge: { text: "Paused", tone: "neutral" },
717
- secondaryBadges: secondaryBadges,
718
- headline: { text: "Monitoring is paused for scheduled maintenance" },
719
- explanation: PAUSED_EXPLANATION.maintenance,
720
- lastKnownStatus: lastKnownStatus,
721
- };
722
- }
723
- case MonitorOverviewRunState.NotChecking:
724
- return MonitorOverviewPresentationUtil.getNotCheckingHero({
725
- input: input,
726
- context: context,
727
- lastKnownStatus: lastKnownStatus,
728
- });
729
- case MonitorOverviewRunState.NotConfigured: {
730
- const isMissingDevice = context.family === MonitorOverviewFamily_1.MonitorOverviewFamily.NetworkDevice &&
731
- context.stepCount > 0;
732
- if (context.family === MonitorOverviewFamily_1.MonitorOverviewFamily.ProbeStatus &&
733
- context.stepCount > 0) {
734
- return {
735
- tone: "neutral",
736
- badge: { text: "Not set up", tone: "neutral" },
737
- secondaryBadges: [],
738
- headline: { text: "This monitor watches no probes" },
739
- explanation: "Pick the probes it watches. It opens an incident when one of them disconnects.",
740
- callToAction: { text: "Pick probes", linkKey: "criteria" },
741
- };
742
- }
743
- return {
744
- tone: "neutral",
745
- badge: { text: "Not set up", tone: "neutral" },
746
- secondaryBadges: [],
747
- headline: {
748
- text: isMissingDevice
749
- ? "No network device is selected"
750
- : "This monitor has no criteria yet",
751
- },
752
- explanation: isMissingDevice
753
- ? "Choose the device this monitor alerts on."
754
- : "Add criteria to tell this monitor what to check.",
755
- callToAction: {
756
- text: isMissingDevice ? "Choose a device" : "Set up criteria",
757
- linkKey: "criteria",
758
- },
759
- };
760
- }
761
- case MonitorOverviewRunState.AwaitingFirstData:
762
- return MonitorOverviewPresentationUtil.getAwaitingHero({
763
- input: input,
764
- context: context,
765
- lastKnownStatus: lastKnownStatus,
766
- });
767
- case MonitorOverviewRunState.Overdue: {
768
- const isProbeCheck = context.family === MonitorOverviewFamily_1.MonitorOverviewFamily.ProbeCheck;
769
- /*
770
- * Nothing has ever been measured (6b), so the stored status is only
771
- * the default the monitor was created with: it is not the headline,
772
- * and it has not "held" for any length of time.
773
- */
774
- const isNeverReported = MonitorOverviewPresentationUtil.isNeverReported(context);
775
- return {
776
- // A late check cannot vouch for "good"; danger stays danger.
777
- tone: statusTone === "danger" ? "danger" : "warning",
778
- badge: isNeverReported
779
- ? { text: "No results yet", tone: "warning" }
780
- : statusBadge,
781
- secondaryBadges: [{ text: "Checks overdue", tone: "warning" }],
782
- headline: isNeverReported
783
- ? {
784
- text: isProbeCheck
785
- ? "No check has completed yet"
786
- : "No evaluation has completed yet",
787
- }
788
- : statusHeadline,
789
- explanation: MonitorOverviewPresentationUtil.getOverdueExplanation({
790
- input: input,
791
- context: context,
792
- }),
793
- lastKnownStatus: isNeverReported ? lastKnownStatus : undefined,
794
- callToAction: isProbeCheck
795
- ? { text: "Check probes", linkKey: "probes" }
796
- : undefined,
797
- };
798
- }
799
- default: {
800
- const running = {
801
- tone: statusTone,
802
- badge: statusBadge,
803
- secondaryBadges: [],
804
- headline: statusHeadline,
805
- };
806
- /*
807
- * A device's polling interval is not known here, so a quiet log is
808
- * not called overdue, but the status is not presented as fresh
809
- * either.
810
- */
811
- if (context.family === MonitorOverviewFamily_1.MonitorOverviewFamily.NetworkDevice &&
812
- context.evaluationLog === "expired") {
813
- running.explanation =
814
- "No poll or trap from this device has been evaluated in the last day, so the status shown is the last one recorded.";
815
- }
816
- /*
817
- * Evaluated every minute, so a day with nothing in the log means
818
- * there was nothing to evaluate: every probe it watches was deleted.
819
- */
820
- if (context.family === MonitorOverviewFamily_1.MonitorOverviewFamily.ProbeStatus &&
821
- context.evaluationLog === "expired") {
822
- running.explanation =
823
- "Not evaluated in the last day. The probes this monitor watches may have been deleted: pick probes again under Criteria. The status shown is the last one recorded.";
824
- running.callToAction = {
825
- text: "Pick probes",
826
- linkKey: "criteria",
827
- };
828
- }
829
- return running;
830
- }
831
- }
832
- }
833
- static getNotCheckingHero(data) {
834
- const probes = data.input.probes;
835
- if (!data.context.isNoProbeEnabled) {
836
- return {
837
- tone: "danger",
838
- badge: { text: "Probes Disconnected", tone: "danger" },
839
- secondaryBadges: [],
840
- headline: { text: "Every probe checking this monitor is disconnected" },
841
- explanation: "Checks stopped when the probes lost their connection. The status shown is the last one recorded.",
842
- lastKnownStatus: data.lastKnownStatus,
843
- callToAction: { text: "Check probes", linkKey: "probes" },
844
- };
845
- }
846
- const badge = {
847
- text: "Probes Not Enabled",
848
- tone: "danger",
849
- };
850
- // Unknown probes must never be described as "no probes attached".
851
- if (probes === null) {
852
- return {
853
- tone: "danger",
854
- badge: badge,
855
- secondaryBadges: [],
856
- headline: { text: "Nothing is checking this monitor" },
857
- explanation: "No probe is enabled for this monitor, so no checks run.",
858
- lastKnownStatus: data.lastKnownStatus,
859
- callToAction: { text: "Manage probes", linkKey: "probes" },
860
- };
861
- }
862
- if (probes.attachedCount === 0) {
863
- return {
864
- tone: "danger",
865
- badge: badge,
866
- secondaryBadges: [],
867
- headline: { text: "No probes are attached to this monitor" },
868
- explanation: "Add a probe to start checking this resource.",
869
- lastKnownStatus: data.lastKnownStatus,
870
- callToAction: { text: "Add a probe", linkKey: "probes" },
871
- };
872
- }
873
- return {
874
- tone: "danger",
875
- badge: badge,
876
- secondaryBadges: [],
877
- headline: { text: "Every probe is turned off for this monitor" },
878
- explanation: `${probes.attachedCount === 1
879
- ? "1 probe is"
880
- : `${probes.attachedCount} probes are`} attached but switched off, so nothing is checking this resource.`,
881
- lastKnownStatus: data.lastKnownStatus,
882
- callToAction: { text: "Manage probes", linkKey: "probes" },
883
- };
884
- }
885
- static getAwaitingHero(data) {
886
- var _a;
887
- const input = data.input;
888
- const context = data.context;
889
- let headline = "Waiting for the first evaluation";
890
- let explanation = `This monitor is evaluated ${context.intervalPhrase} once saved.`;
891
- let hasSetup = false;
892
- // What has never arrived, for a push monitor the server has judged.
893
- let missingSince = null;
894
- if (context.family === MonitorOverviewFamily_1.MonitorOverviewFamily.ProbeCheck) {
895
- const enabledCount = ((_a = input.probes) === null || _a === void 0 ? void 0 : _a.enabledCount) || 0;
896
- headline = "Waiting for the first check";
897
- explanation = `${enabledCount === 1 ? "1 probe checks" : `${enabledCount} probes check`} this ${context.intervalPhrase}. The first result usually arrives within a few minutes.`;
898
- }
899
- else if (context.family === MonitorOverviewFamily_1.MonitorOverviewFamily.NetworkDevice) {
900
- headline = "Waiting for the first poll";
901
- explanation =
902
- "No poll or trap from this device has been evaluated yet. Check that a probe is assigned to poll it.";
903
- }
904
- else if (context.family === MonitorOverviewFamily_1.MonitorOverviewFamily.ProbeStatus) {
905
- explanation =
906
- "This monitor checks the probes it watches every minute. The first result arrives within a minute or two.";
907
- }
908
- else if (input.monitorType === MonitorType_1.default.IncomingRequest) {
909
- headline = "Waiting for the first heartbeat";
910
- explanation =
911
- "Send a GET or POST request to this monitor's heartbeat URL to start tracking it.";
912
- hasSetup = true;
913
- missingSince = "No heartbeat has arrived";
914
- }
915
- else if (input.monitorType === MonitorType_1.default.IncomingEmail) {
916
- headline = "Waiting for the first email";
917
- explanation =
918
- "Send an email to this monitor's address to start tracking it.";
919
- hasSetup = true;
920
- missingSince = "No email has arrived";
921
- }
922
- else if (context.family === MonitorOverviewFamily_1.MonitorOverviewFamily.Agent) {
923
- headline = "Waiting for the agent to report";
924
- explanation = "Install the server agent to start sending reports.";
925
- hasSetup = true;
926
- missingSince = "The agent has not reported";
927
- }
928
- const callToAction = hasSetup
929
- ? { text: "Setup instructions", linkKey: "documentation" }
930
- : undefined;
931
- const status = input.currentStatus;
932
- /*
933
- * The server judges a push monitor that never reported as if its last
934
- * signal arrived at creation, so it can be Offline, with an incident
935
- * open, while the page is still "waiting". Lead with that verdict's
936
- * tone and keep the setup steps: sending the first signal is still the
937
- * fix.
938
- */
939
- if (missingSince !== null &&
940
- status &&
941
- MonitorOverviewPresentationUtil.isJudgedStatus(input)) {
942
- const statusTone = MonitorOverviewPresentationUtil.getStatusTone(status);
943
- return {
944
- tone: statusTone,
945
- badge: { text: "Waiting for data", tone: "info" },
946
- secondaryBadges: [{ text: status.name, tone: statusTone }],
947
- headline: {
948
- text: input.createdAt
949
- ? `${missingSince} since this monitor was created ${(0, SloDuration_1.formatDurationCompact)(secondsSince(input.now, input.createdAt))} ago`
950
- : headline,
951
- },
952
- explanation: explanation,
953
- callToAction: callToAction,
954
- };
955
- }
956
- return {
957
- tone: "info",
958
- badge: { text: "Waiting for data", tone: "info" },
959
- secondaryBadges: [],
960
- headline: { text: headline },
961
- explanation: explanation,
962
- lastKnownStatus: data.lastKnownStatus,
963
- callToAction: callToAction,
964
- };
965
- }
966
- static isNeverReported(context) {
967
- var _a;
968
- return (context.runState === MonitorOverviewRunState.Overdue &&
969
- context.freshness.resultAgeSeconds === null &&
970
- !((_a = context.telemetry) === null || _a === void 0 ? void 0 : _a.isMissingFromLog));
971
- }
972
- /*
973
- * "No result for 12m" states how long it has been since the last result -
974
- * the same age the pulse's "Last checked" shows - so the two never
975
- * disagree. The pulse's "Overdue by" line carries how late that is.
976
- */
977
- static getOverdueExplanation(data) {
978
- var _a;
979
- const input = data.input;
980
- const context = data.context;
981
- const isProbeCheck = context.family === MonitorOverviewFamily_1.MonitorOverviewFamily.ProbeCheck;
982
- const resultAgeSeconds = context.freshness.resultAgeSeconds;
983
- if ((_a = context.telemetry) === null || _a === void 0 ? void 0 : _a.isMissingFromLog) {
984
- return `No evaluation recorded in the last day, but this monitor is evaluated ${context.intervalPhrase}.`;
985
- }
986
- if (resultAgeSeconds === null) {
987
- const createdAgo = input.createdAt
988
- ? (0, SloDuration_1.formatDurationCompact)(secondsSince(input.now, input.createdAt))
989
- : (0, SloDuration_1.formatDurationCompact)(context.freshness.overdueSeconds || 0);
990
- return isProbeCheck
991
- ? `No check result has arrived since this monitor was created ${createdAgo} ago.`
992
- : `No evaluation has run since this monitor was created ${createdAgo} ago.`;
993
- }
994
- const age = (0, SloDuration_1.formatDurationCompact)(resultAgeSeconds);
995
- return isProbeCheck
996
- ? `No result for ${age}, but this monitor checks ${context.intervalPhrase}. A probe may be overloaded or offline.`
997
- : `No evaluation for ${age}, but this monitor is evaluated ${context.intervalPhrase}.`;
998
- }
999
- static getPulse(input, context) {
1000
- var _a, _b, _c, _d;
1001
- const isScheduled = context.runState !== MonitorOverviewRunState.Paused &&
1002
- context.runState !== MonitorOverviewRunState.NotChecking &&
1003
- context.runState !== MonitorOverviewRunState.NotConfigured;
1004
- const overdueSeconds = context.runState === MonitorOverviewRunState.Overdue &&
1005
- context.freshness.overdueSeconds !== null
1006
- ? context.freshness.overdueSeconds
1007
- : undefined;
1008
- switch (context.family) {
1009
- case MonitorOverviewFamily_1.MonitorOverviewFamily.ProbeCheck: {
1010
- const nextAt = (_a = input.probes) === null || _a === void 0 ? void 0 : _a.nextCheckAt;
1011
- return {
1012
- label: "Last checked",
1013
- at: (_b = input.probes) === null || _b === void 0 ? void 0 : _b.lastResultAt,
1014
- emptyText: "Not checked yet",
1015
- // A paused or unchecked monitor has no cadence to promise.
1016
- cadenceText: isScheduled ? context.intervalText : undefined,
1017
- nextAt: isScheduled && isFutureOf(nextAt, input.now) ? nextAt : undefined,
1018
- overdueSeconds: overdueSeconds,
1019
- isUnavailable: input.probes === null,
1020
- };
1021
- }
1022
- case MonitorOverviewFamily_1.MonitorOverviewFamily.Heartbeat: {
1023
- const isEmail = input.monitorType === MonitorType_1.default.IncomingEmail;
1024
- /*
1025
- * No cadence line: the missing-request check time is already the
1026
- * "Last missing-request check" fact, and a push-based monitor has no
1027
- * schedule of its own to promise.
1028
- */
1029
- return {
1030
- label: isEmail ? "Last email" : "Last request",
1031
- at: isEmail
1032
- ? input.email.lastReceivedAt
1033
- : input.heartbeat.lastReceivedAt,
1034
- emptyText: isEmail ? "No email yet" : "No request yet",
1035
- isUnavailable: false,
1036
- };
1037
- }
1038
- case MonitorOverviewFamily_1.MonitorOverviewFamily.Agent:
1039
- return {
1040
- label: "Last report",
1041
- at: input.agent.lastReportAt,
1042
- emptyText: "No report yet",
1043
- isUnavailable: false,
1044
- };
1045
- case MonitorOverviewFamily_1.MonitorOverviewFamily.TelemetrySignal:
1046
- case MonitorOverviewFamily_1.MonitorOverviewFamily.Infrastructure: {
1047
- const nextAt = input.telemetry.nextEvaluationAt;
1048
- /*
1049
- * Without a time from the evaluation log, the only time is the
1050
- * worker's stamp, which it writes when it queues an evaluation: it
1051
- * is named for what it is.
1052
- */
1053
- const isScheduledTime = Boolean((_c = context.telemetry) === null || _c === void 0 ? void 0 : _c.isScheduledTime);
1054
- let emptyText = "Not evaluated yet";
1055
- if (isScheduledTime) {
1056
- emptyText = "Not scheduled yet";
1057
- }
1058
- else if (context.evaluationLog === "expired") {
1059
- emptyText = NOT_EVALUATED_IN_LOG_TEXT;
1060
- }
1061
- return {
1062
- label: isScheduledTime ? "Last scheduled" : "Last evaluated",
1063
- at: (_d = context.telemetry) === null || _d === void 0 ? void 0 : _d.lastAt,
1064
- emptyText: emptyText,
1065
- cadenceText: isScheduled ? context.intervalText : undefined,
1066
- nextAt: isScheduled && isFutureOf(nextAt, input.now) ? nextAt : undefined,
1067
- overdueSeconds: overdueSeconds,
1068
- isUnavailable: false,
1069
- };
1070
- }
1071
- case MonitorOverviewFamily_1.MonitorOverviewFamily.NetworkDevice: {
1072
- let emptyText = "Not evaluated yet";
1073
- if (context.evaluationStatus === "loading") {
1074
- emptyText = "Loading…";
1075
- }
1076
- else if (context.evaluationLog === "expired") {
1077
- emptyText = NOT_EVALUATED_IN_LOG_TEXT;
1078
- }
1079
- // The time only comes from the evaluation log, so it follows its read.
1080
- return {
1081
- label: "Last evaluated",
1082
- at: context.evaluationStatus === "loaded"
1083
- ? input.latestEvaluationAt
1084
- : undefined,
1085
- emptyText: emptyText,
1086
- isUnavailable: context.evaluationStatus === "error" ||
1087
- context.evaluationStatus === "forbidden",
1088
- };
1089
- }
1090
- case MonitorOverviewFamily_1.MonitorOverviewFamily.ProbeStatus: {
1091
- let emptyText = "Not evaluated yet";
1092
- if (context.evaluationStatus === "loading") {
1093
- emptyText = "Loading…";
1094
- }
1095
- else if (context.evaluationLog === "expired") {
1096
- emptyText = NOT_EVALUATED_IN_LOG_TEXT;
1097
- }
1098
- // Evaluated by the server every minute: that is its schedule.
1099
- return {
1100
- label: "Last evaluated",
1101
- at: context.evaluationStatus === "loaded"
1102
- ? input.latestEvaluationAt
1103
- : undefined,
1104
- emptyText: emptyText,
1105
- cadenceText: isScheduled ? "Every minute" : undefined,
1106
- isUnavailable: context.evaluationStatus === "error" ||
1107
- context.evaluationStatus === "forbidden",
1108
- };
1109
- }
1110
- default:
1111
- return {
1112
- label: null,
1113
- emptyText: "No automated checks",
1114
- isUnavailable: false,
1115
- };
1116
- }
1117
- }
1118
- static getFacts(input, context) {
1119
- var _a, _b, _c;
1120
- const facts = [];
1121
- switch (context.family) {
1122
- case MonitorOverviewFamily_1.MonitorOverviewFamily.ProbeCheck:
1123
- facts.push(MonitorOverviewPresentationUtil.getLatestResultFact(input));
1124
- if (input.monitorType === MonitorType_1.default.SSLCertificate) {
1125
- facts.push(input.probes === null
1126
- ? {
1127
- key: "certificate-expiry",
1128
- label: "Certificate expires",
1129
- value: "Unavailable",
1130
- isMuted: true,
1131
- }
1132
- : MonitorOverviewPresentationUtil.getExpiryFact({
1133
- key: "certificate-expiry",
1134
- expiresAt: (_a = input.probes.latestResult) === null || _a === void 0 ? void 0 : _a.sslExpiresAt,
1135
- isValidCertificate: (_b = input.probes.latestResult) === null || _b === void 0 ? void 0 : _b.isValidCertificate,
1136
- now: input.now,
1137
- }));
1138
- }
1139
- if (input.monitorType === MonitorType_1.default.Domain) {
1140
- facts.push(input.probes === null
1141
- ? {
1142
- key: "domain-expiry",
1143
- label: "Domain expires",
1144
- value: "Unavailable",
1145
- isMuted: true,
1146
- }
1147
- : MonitorOverviewPresentationUtil.getExpiryFact({
1148
- key: "domain-expiry",
1149
- expiresAt: (_c = input.probes.latestResult) === null || _c === void 0 ? void 0 : _c.domainExpiresAt,
1150
- now: input.now,
1151
- }));
1152
- }
1153
- facts.push(MonitorOverviewPresentationUtil.getProbesFact(input, context));
1154
- break;
1155
- case MonitorOverviewFamily_1.MonitorOverviewFamily.Heartbeat: {
1156
- const isEmail = input.monitorType === MonitorType_1.default.IncomingEmail;
1157
- const minutes = MonitorOverviewCriteriaUtil_1.default.getMissingSignalMinutes({
1158
- monitorSteps: input.monitorSteps,
1159
- checkOn: isEmail
1160
- ? CriteriaFilter_1.CheckOn.EmailReceivedAt
1161
- : CriteriaFilter_1.CheckOn.IncomingRequest,
1162
- });
1163
- const lastCheckedAt = isEmail
1164
- ? input.email.lastCheckedAt
1165
- : input.heartbeat.lastCheckedAt;
1166
- facts.push(minutes === null
1167
- ? {
1168
- key: "missing-window",
1169
- label: isEmail
1170
- ? "Missing-email window"
1171
- : "Missing-request window",
1172
- value: "Set in Criteria",
1173
- linkKey: "criteria",
1174
- }
1175
- : {
1176
- key: "missing-window",
1177
- label: isEmail
1178
- ? "Missing-email window"
1179
- : "Missing-request window",
1180
- value: pluralize(minutes, "minute", "minutes"),
1181
- secondary: "From this monitor's criteria",
1182
- });
1183
- facts.push(lastCheckedAt
1184
- ? {
1185
- key: "heartbeat-check",
1186
- label: isEmail
1187
- ? "Last missing-email check"
1188
- : "Last missing-request check",
1189
- value: "",
1190
- valueDate: lastCheckedAt,
1191
- }
1192
- : {
1193
- key: "heartbeat-check",
1194
- label: isEmail
1195
- ? "Last missing-email check"
1196
- : "Last missing-request check",
1197
- value: "Not run yet",
1198
- isMuted: true,
1199
- });
1200
- break;
1201
- }
1202
- case MonitorOverviewFamily_1.MonitorOverviewFamily.Agent: {
1203
- const hostname = (input.agent.hostname || "").trim();
1204
- facts.push(hostname
1205
- ? { key: "host", label: "Host", value: hostname, isMono: true }
1206
- : {
1207
- key: "host",
1208
- label: "Host",
1209
- value: "Not reported yet",
1210
- isMuted: true,
1211
- });
1212
- facts.push(MonitorOverviewPresentationUtil.getPercentFact({
1213
- key: "cpu",
1214
- label: "CPU",
1215
- percent: input.agent.cpuPercent,
1216
- }));
1217
- facts.push(MonitorOverviewPresentationUtil.getPercentFact({
1218
- key: "memory",
1219
- label: "Memory",
1220
- percent: input.agent.memoryPercent,
1221
- }));
1222
- break;
1223
- }
1224
- case MonitorOverviewFamily_1.MonitorOverviewFamily.TelemetrySignal:
1225
- case MonitorOverviewFamily_1.MonitorOverviewFamily.Infrastructure:
1226
- facts.push({
1227
- key: "evaluates",
1228
- label: "Evaluates",
1229
- value: context.intervalText,
1230
- });
1231
- facts.push({
1232
- key: "criteria",
1233
- label: "Criteria",
1234
- value: pluralize(context.stepCount, "step", "steps"),
1235
- linkKey: "criteria",
1236
- });
1237
- break;
1238
- case MonitorOverviewFamily_1.MonitorOverviewFamily.NetworkDevice:
1239
- facts.push(context.networkDeviceId
1240
- ? {
1241
- key: "device",
1242
- label: "Device",
1243
- value: "View device",
1244
- linkKey: "networkDevice",
1245
- linkId: context.networkDeviceId,
1246
- }
1247
- : {
1248
- key: "device",
1249
- label: "Device",
1250
- value: "Not selected",
1251
- isMuted: true,
1252
- });
1253
- facts.push({
1254
- key: "evaluated",
1255
- label: "Evaluated",
1256
- value: "On every poll and matching trap",
1257
- });
1258
- break;
1259
- case MonitorOverviewFamily_1.MonitorOverviewFamily.ProbeStatus: {
1260
- /*
1261
- * Which probe is down comes first, as a probe check's latest result
1262
- * does. No "Evaluates" fact: the pulse above already says "Every
1263
- * minute". A monitor watching no probe has no result to give.
1264
- */
1265
- if (context.watchedProbeCount > 0) {
1266
- facts.push(MonitorOverviewPresentationUtil.getProbeStatusResultFact(input, context));
1267
- }
1268
- facts.push(context.watchedProbeCount > 0
1269
- ? {
1270
- key: "probes",
1271
- label: "Watches",
1272
- value: pluralize(context.watchedProbeCount, "probe", "probes"),
1273
- linkKey: "criteria",
1274
- }
1275
- : {
1276
- key: "probes",
1277
- label: "Watches",
1278
- value: "No probes picked",
1279
- isMuted: true,
1280
- linkKey: "criteria",
1281
- });
1282
- break;
1283
- }
1284
- default:
1285
- facts.push({
1286
- key: "checks",
1287
- label: "Checks",
1288
- value: "None",
1289
- secondary: "Status is set by hand or by incidents",
1290
- });
1291
- break;
1292
- }
1293
- /*
1294
- * Owners always close the band; the component renders them from the
1295
- * owners section, so the value here is empty.
1296
- */
1297
- return [
1298
- ...facts.slice(0, MAX_FACTS - 1),
1299
- { key: "owners", label: "Owners", value: "" },
1300
- ];
1301
- }
1302
- /*
1303
- * A Probe Status monitor's newest evaluation, in the hero: which of its
1304
- * probes are disconnected, by name, or that they all are connected. It
1305
- * reads the same log row as the pulse's "Last evaluated", so the two
1306
- * never describe different evaluations.
1307
- */
1308
- static getProbeStatusResultFact(input, context) {
1309
- const base = {
1310
- key: "latest-result",
1311
- label: "Latest result",
1312
- };
1313
- if (context.evaluationStatus === "error" ||
1314
- context.evaluationStatus === "forbidden") {
1315
- return Object.assign(Object.assign({}, base), { value: "Unavailable", isMuted: true });
1316
- }
1317
- if (context.evaluationStatus === "loading") {
1318
- return Object.assign(Object.assign({}, base), { value: "Loading…", isMuted: true });
1319
- }
1320
- const result = input.probeStatus;
1321
- if (!result) {
1322
- return Object.assign(Object.assign({}, base), { value: "—", secondary: context.evaluationLog === "expired"
1323
- ? "None in the last day"
1324
- : "No results yet", isMuted: true });
1325
- }
1326
- const probes = Array.isArray(result.probes)
1327
- ? result.probes
1328
- : [];
1329
- const connected = result.connectedProbeCount || 0;
1330
- const disconnected = result.disconnectedProbeCount || 0;
1331
- const total = connected + disconnected;
1332
- // Every probe it watches was deleted: nothing was counted.
1333
- if (total === 0) {
1334
- return Object.assign(Object.assign({}, base), { value: "No probes found", secondary: "Pick probes again", tone: "warning" });
1335
- }
1336
- if (disconnected > 0) {
1337
- return Object.assign(Object.assign({}, base), { value: total === 1
1338
- ? "Disconnected"
1339
- : `${disconnected} of ${total} disconnected`, secondary: ProbeStatusMonitorUtil_1.default.joinProbeNames(ProbeStatusMonitorUtil_1.default.getDisconnectedProbes({ probes: probes })), tone: "danger" });
1340
- }
1341
- return Object.assign(Object.assign({}, base), { value: total === 1 ? "Connected" : `${total} of ${total} connected`,
1342
- // One probe is named; several connected need no list.
1343
- secondary: total === 1 ? ProbeStatusMonitorUtil_1.default.joinProbeNames(probes) : undefined, tone: "good" });
1344
- }
1345
- static getLatestResultFact(input) {
1346
- const base = {
1347
- key: "latest-result",
1348
- label: "Latest result",
1349
- };
1350
- if (input.probes === null) {
1351
- return Object.assign(Object.assign({}, base), { value: "Unavailable", isMuted: true });
1352
- }
1353
- const result = input.probes.latestResult;
1354
- if (!result) {
1355
- return Object.assign(Object.assign({}, base), { value: "—", secondary: "No results yet", isMuted: true });
1356
- }
1357
- const isScripted = input.monitorType === MonitorType_1.default.SyntheticMonitor ||
1358
- input.monitorType === MonitorType_1.default.CustomJavaScriptCode;
1359
- const upCount = input.probes.upCount || 0;
1360
- const downCount = input.probes.downCount || 0;
1361
- /*
1362
- * When the probes disagree, the newest single result is just whichever
1363
- * probe reported last, and would flip between Up and Down from one poll
1364
- * to the next. Say they disagree instead.
1365
- */
1366
- if (upCount > 0 && downCount > 0) {
1367
- return Object.assign(Object.assign({}, base), { value: isScripted
1368
- ? `Mixed · ${upCount} passed, ${downCount} failed`
1369
- : `Mixed · ${upCount} up, ${downCount} down`, tone: "warning" });
1370
- }
1371
- let value = "Reported";
1372
- let tone = "neutral";
1373
- if (result.isOnline === true) {
1374
- value = isScripted ? "Passed" : "Up";
1375
- tone = "good";
1376
- }
1377
- else if (result.isOnline === false) {
1378
- value = isScripted ? "Failed" : "Down";
1379
- tone = "danger";
1380
- }
1381
- if (result.responseTimeInMs !== undefined) {
1382
- value += ` · ${Math.round(result.responseTimeInMs)} ms`;
1383
- }
1384
- if (result.responseCode !== undefined &&
1385
- (input.monitorType === MonitorType_1.default.API ||
1386
- input.monitorType === MonitorType_1.default.Website)) {
1387
- value += ` · HTTP ${result.responseCode}`;
1388
- }
1389
- return Object.assign(Object.assign({}, base), { value: value, secondary: result.isOnline === false && result.failureCause
1390
- ? result.failureCause
1391
- : `from ${result.probeName}`, tone: tone });
1392
- }
1393
- static getProbesFact(input, context) {
1394
- const base = { key: "probes", label: "Probes", linkKey: "probes" };
1395
- if (input.probes === null) {
1396
- return Object.assign(Object.assign({}, base), { value: "Unavailable", isMuted: true });
1397
- }
1398
- const probes = input.probes;
1399
- const downCount = probes.downCount || 0;
1400
- const connectionParts = [];
1401
- if (probes.disabledCount > 0) {
1402
- connectionParts.push(`${probes.disabledCount} disabled`);
1403
- }
1404
- if (probes.disconnectedCount > 0) {
1405
- connectionParts.push(`${probes.disconnectedCount} disconnected`);
1406
- }
1407
- const joinParts = (parts) => {
1408
- return parts.length > 0 ? parts.join(" · ") : undefined;
1409
- };
1410
- if (probes.enabledCount === 0) {
1411
- return Object.assign(Object.assign({}, base), { value: "None enabled", secondary: joinParts(connectionParts), tone: "danger" });
1412
- }
1413
- /*
1414
- * No probe is meant to report while monitoring is paused, so a
1415
- * reporting ratio would read as a probe fault that does not exist.
1416
- */
1417
- if (context.isPaused) {
1418
- return Object.assign(Object.assign({}, base), { value: `${probes.enabledCount} enabled`, secondary: joinParts(["Checks paused", ...connectionParts]), tone: "neutral" });
1419
- }
1420
- let tone = "neutral";
1421
- if (probes.reportingCount === 0 || downCount >= probes.reportingCount) {
1422
- // Nothing reporting, or every probe that reports sees it down.
1423
- tone = "danger";
1424
- }
1425
- else if (downCount > 0 || probes.reportingCount < probes.enabledCount) {
1426
- tone = "warning";
1427
- }
1428
- const isScripted = input.monitorType === MonitorType_1.default.SyntheticMonitor ||
1429
- input.monitorType === MonitorType_1.default.CustomJavaScriptCode;
1430
- // A probe that reports Down is reporting, but it is not fine.
1431
- const downPart = `${downCount} ${isScripted ? "failing" : "down"}`;
1432
- return Object.assign(Object.assign({}, base), { value: `${probes.reportingCount} of ${probes.enabledCount} reporting`, secondary: joinParts(downCount > 0 ? [downPart, ...connectionParts] : connectionParts), tone: tone });
1433
- }
1434
- static getPercentFact(data) {
1435
- if (data.percent === undefined || !Number.isFinite(data.percent)) {
1436
- return { key: data.key, label: data.label, value: "—", isMuted: true };
1437
- }
1438
- return {
1439
- key: data.key,
1440
- label: data.label,
1441
- value: `${Math.round(data.percent)}%`,
1442
- };
1443
- }
1444
- static getSections(context) {
1445
- const isAwaiting = context.runState === MonitorOverviewRunState.AwaitingFirstData;
1446
- const layout = context.layout;
1447
- const isPushFamily = context.family === MonitorOverviewFamily_1.MonitorOverviewFamily.Heartbeat ||
1448
- context.family === MonitorOverviewFamily_1.MonitorOverviewFamily.Agent;
1449
- return {
1450
- /*
1451
- * Bars for a monitor that has never reported would all be "No data",
1452
- * unless the server has already judged it: then its history (and what
1453
- * is open now) is the point.
1454
- */
1455
- showUptime: !isAwaiting || context.hasPushVerdict,
1456
- setup: isAwaiting ? layout.setupKind : null,
1457
- connection: isAwaiting ? null : layout.setupKind,
1458
- summary: {
1459
- isShown: layout.summaryDescription !== null &&
1460
- !(isAwaiting && isPushFamily) &&
1461
- /*
1462
- * A Probe Status monitor that watches no probe has nothing to
1463
- * summarise: an older evaluation would list probes it no longer
1464
- * watches. Before its first evaluation the hero already says
1465
- * when one comes, so an empty card would only say it again.
1466
- */
1467
- !(context.family === MonitorOverviewFamily_1.MonitorOverviewFamily.ProbeStatus &&
1468
- (context.runState === MonitorOverviewRunState.NotConfigured ||
1469
- isAwaiting)),
1470
- description: layout.summaryDescription || "",
1471
- },
1472
- // The connection card only makes sense once something has connected.
1473
- sideCard: layout.sideCard === "connection" && isAwaiting ? null : layout.sideCard,
1474
- responseTimeMetric: isAwaiting ? null : layout.responseTimeMetric,
1475
- telemetryPreview: context.stepCount > 0 ? layout.telemetryPreview : null,
1476
- stepCount: context.stepCount,
1477
- };
1478
- }
1479
- }
1480
- exports.default = MonitorOverviewPresentationUtil;