-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathincidents.js
293 lines (256 loc) · 7.09 KB
/
incidents.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
const axios = require('axios');
const { response } = require('express');
// Axios config and call to get status information
let config = {
maxBodyLength: Infinity,
url: 'https://4020906026954545.hostedstatus.com/1.0/status/60b16163e5d993052b815109',
headers: {}
};
// Declare global variables to track status information
let totalStatus = 0;
let totalOperational = 0;
let totalError = 0;
let overallStatus = null;
let statusColor = null;
let activeIncidents = 0;
let activeMaintenance = 0;
let upcomingMaintenance = 0;
let statusResult = null;
let incidentArray = [];
let brokenStatus = [];
/** An async function that grabs the status data using the public view API and returns JSON */
async function getStatusData() {
await axios.request(config)
.then((response) => {
console.log("STATUS SUCESSFULLY RECIEVED ✔");
// Iterate through the data and parse information
// We will start by checking if the data exists and then set the current overall status
totalOperational = 0;
totalStatus = 0;
if (response.data && response.data.result && response.data.result.status) {
overallStatus = response.data.result.status_overall.status;
console.log(overallStatus)
// Depending on the overall status, assign a color to the status
if (overallStatus == "Operational") {
statusColor = "green"
} else if (overallStatus == "Degraded Performance" || overallStatus == "Partial Service Disruption") {
statusColor = "yellow"
} else {
statusColor = "#E56565"
}
console.log(overallStatus)
console.log(statusColor)
// Set the status array to a variable
const statusArray = response.data.result.status;
incidentArray = response.data.result.incidents;
const activeMaintenanceArray = response.data.result.maintenance.active;
const upcomingMaintenanceArray = response.data.result.maintenance.upcoming;
statusResult = response;
console.log(overallStatus)
console.log(statusColor)
// Loop through the status array and add up the total number of services
statusArray.forEach((status) => {
if (status.containers && Array.isArray(status.containers)) {
totalStatus += status.containers.length;
}
if (status.status === "Operational") {
totalOperational += 1;
} else {
totalError += 1;
brokenStatus.push(status.name);
}
});
console.log(overallStatus)
console.log(statusColor)
activeIncidents = incidentArray.length;
activeMaintenance = activeMaintenanceArray.length;
upcomingMaintenance = upcomingMaintenanceArray.length;
totalOperational = totalStatus - totalError;
console.log("OVERALL STATUS: ", overallStatus);
console.log("TOTAL STATUS ITEMS: ", totalStatus);
console.log("TOTAL NUMBER OF OPERATIONAL STATUS ITEMS: ", totalOperational);
console.log("TOTAL STATUS ERRORS: ", totalError);
console.log("ACTIVE INCIDENTS: ", activeIncidents);
console.log("ACTIVE MAINTENANCE: ", activeMaintenance);
console.log("UPCOMING MAINTENANCE: ", upcomingMaintenance);
}
})
.catch((error) => {
console.log(error);
});
}
function makeIncidentDetails(incidentId) {
let incidentName = "";
let containerId = 0;
let affectedContainers = 0;
let affectedComponents = 0;
let containerNames = [];
let componentNames = [];
for (let i = 0; i < incidentArray.length; i++) {
if (incidentArray[i]._id == incidentId) {
incidentName = incidentArray[i].name;
containerId = i;
}
affectedContainers = incidentArray[i].containers_affected.length;
affectedComponents = incidentArray[i].components_affected.length;
for (let j = 0; j < affectedContainers; j++) {
let listTemplate = {
"title": incidentArray[i].containers_affected[j].name
}
containerNames.push(listTemplate);
}
for (let k = 0; k < affectedComponents; k++) {
let listTemplate = {
"title": incidentArray[i].components_affected[k].name
}
componentNames.push(listTemplate);
}
}
let xmJson = {
"metadata": {
"version": "2.0",
"banners": []
},
"contentContainerWidth": "full",
"header": [],
"content": [],
"elementFields": {}
}
let xmHeader = {
"elementType": "hero",
"height": "fluid",
"contentContainerWidth": "wide",
"backgroundImage": {
"overlayType": "solid",
"overlayColor": "#EFEFEF"
},
"content": [
{
"elementType": "heroBreadcrumbs",
"id": "status_detail_bc",
"separatorCharacter": "/",
"ellipsize": true,
"separatorColor": "#daa900",
"items": [
{
"elementType": "breadcrumbItem",
"title": "Status Homepage",
"url": {
"relativePath": "./status"
}
},
{
"elementType": "breadcrumbItem",
"title": "Incidents",
"url": {
"relativePath": "./status"
}
},
{
"elementType": "breadcrumbItem",
"title": `Active Incident: ${incidentName}`
}
]
},
{
"elementType": "heroHeading",
"responsiveScaling": true,
"heading": `Active Incident: ${incidentName}`,
"fontSize": "large",
// "textColor": "rgba(220,245,255,0.75)",
"textColor": "#002856",
// "fontSize": "2rem",
"textAlignment": "left",
"marginTop": "3%",
"marginBottom": "2%",
}
]
}
xmJson.header.push
xmJson.header.push(xmHeader);
let xmContent = {
"elementType": "responsiveTwoColumn",
"id": "container_detail",
"primarySide": "right",
"primaryColumn": {
"content": [
{
"elementType": "divider",
"borderStyle": "none",
"marginTop": "5%"
},
{
"elementType": "blockHeading",
"heading": "Incident Updates",
}
]
},
"secondaryColumn": {
"content": [
{
"elementType": "divider",
"borderStyle": "none",
"marginTop": "5%"
},
{
"elementType": "collapsible",
"title": "View Affected Systems",
"borderTopStyle": "none",
"collapsed": true,
"content": [
{
"elementType": "list",
"listStyle": "grouped",
"items": componentNames
}
]
},
{
"elementType": "collapsible",
"title": "View Affected Components",
"borderTopStyle": "none",
"collapsed": true,
"content": [
{
"elementType": "list",
"listStyle": "grouped",
"items": containerNames
}
]
}
]
}
}
let xmIncidentList = {
"elementType": "list",
"listStyle": "grouped",
"items": []
}
for (let i = (incidentArray[0].messages.length) - 1; i >= 0; i--) {
let messageTime = new Date(incidentArray[0].messages[i].datetime);
console.log(messageTime)
let incidentItem = {
"title": incidentArray[0].messages[i].details,
"description": messageTime.toLocaleString()
}
xmIncidentList.items.push(incidentItem);
}
xmContent.primaryColumn.content.push(xmIncidentList);
xmJson.content.push(xmContent);
resetStatus();
return xmJson;
}
function resetStatus() {
totalStatus = 0;
totalOperational = 0;
totalError = 0;
overallStatus = null;
statusColor = null;
activeIncidents = 0;
activeMaintenance = 0;
upcomingMaintenance = 0;
statusResult = null;
brokenStatus = [];
}
module.exports.makeIncidentDetails = makeIncidentDetails;
module.exports.getStatusData = getStatusData;