Repository navigation
Expand file tree
/
Copy pathservice-status.js
More file actions
291 lines (261 loc) · 14.1 KB
/
Copy pathservice-status.js
File metadata and controls
291 lines (261 loc) · 14.1 KB
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
<
8000
div data-line-number="227" class="react-line-number react-code-text" style="padding-right:16px">227228
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
export const config = { runtime: 'edge' };
// Major tech services and their status page endpoints
// Most use Statuspage.io which has a standard /api/v2/status.json endpoint
const SERVICES = [
// Cloud Providers
{ id: 'aws', name: 'AWS', statusPage: 'https://health.aws.amazon.com/health/status', customParser: 'aws', category: 'cloud' },
{ id: 'azure', name: 'Azure', statusPage: 'https://azure.status.microsoft/en-us/status/feed/', customParser: 'rss', category: 'cloud' },
{ id: 'gcp', name: 'Google Cloud', statusPage: 'https://status.cloud.google.com/incidents.json', customParser: 'gcp', category: 'cloud' },
{ id: 'cloudflare', name: 'Cloudflare', statusPage: 'https://www.cloudflarestatus.com/api/v2/status.json', category: 'cloud' },
{ id: 'vercel', name: 'Vercel', statusPage: 'https://www.vercel-status.com/api/v2/status.json', category: 'cloud' },
{ id: 'netlify', name: 'Netlify', statusPage: 'https://www.netlifystatus.com/api/v2/status.json', category: 'cloud' },
{ id: 'digitalocean', name: 'DigitalOcean', statusPage: 'https://status.digitalocean.com/api/v2/status.json', category: 'cloud' },
{ id: 'render', name: 'Render', statusPage: 'https://status.render.com/api/v2/status.json', category: 'cloud' },
{ id: 'railway', name: 'Railway', statusPage: 'https://railway.instatus.com/summary.json', customParser: 'instatus', category: 'cloud' },
// Developer Tools
{ id: 'github', name: 'GitHub', statusPage: 'https://www.githubstatus.com/api/v2/status.json', category: 'dev' },
{ id: 'gitlab', name: 'GitLab', statusPage: 'https://status.gitlab.com/1.0/status/5b36dc6502d06804c08349f7', customParser: 'statusio', category: 'dev' },
{ id: 'npm', name: 'npm', statusPage: 'https://status.npmjs.org/api/v2/status.json', category: 'dev' },
{ id: 'docker', name: 'Docker Hub', statusPage: 'https://www.dockerstatus.com/1.0/status/533c6539221ae15e3f000031', customParser: 'statusio', category: 'dev' },
{ id: 'bitbucket', name: 'Bitbucket', statusPage: 'https://bitbucket.status.atlassian.com/api/v2/status.json', category: 'dev' },
{ id: 'circleci', name: 'CircleCI', statusPage: 'https://status.circleci.com/api/v2/status.json', category: 'dev' },
{ id: 'jira', name: 'Jira', statusPage: 'https://jira-software.status.atlassian.com/api/v2/status.json', category: 'dev' },
{ id: 'confluence', name: 'Confluence', statusPage: 'https://confluence.status.atlassian.com/api/v2/status.json', category: 'dev' },
{ id: 'linear', name: 'Linear', statusPage: 'https://linearstatus.com/api/v2/status.json', customParser: 'incidentio', category: 'dev' },
// Communication
{ id: 'slack', name: 'Slack', statusPage: 'https://slack-status.com/api/v2.0.0/current', customParser: 'slack', category: 'comm' },
{ id: 'discord', name: 'Discord', statusPage: 'https://discordstatus.com/api/v2/status.json', category: 'comm' },
{ id: 'zoom', name: 'Zoom', statusPage: 'https://www.zoomstatus.com/api/v2/status.json', category: 'comm' },
{ id: 'notion', name: 'Notion', statusPage: 'https://www.notion-status.com/api/v2/status.json', category: 'comm' },
// AI Services (incident.io powered)
{ id: 'openai', name: 'OpenAI', statusPage: 'https://status.openai.com/api/v2/status.json', customParser: 'incidentio', category: 'ai' },
{ id: 'anthropic', name: 'Anthropic', statusPage: 'https://status.claude.com/api/v2/status.json', customParser: 'incidentio', category: 'ai' },
{ id: 'replicate', name: 'Replicate', statusPage: 'https://www.replicatestatus.com/api/v2/status.json', customParser: 'incidentio', category: 'ai' },
// SaaS
{ id: 'stripe', name: 'Stripe', statusPage: 'https://status.stripe.com/current', customParser: 'stripe', category: 'saas' },
{ id: 'twilio', name: 'Twilio', statusPage: 'https://status.twilio.com/api/v2/status.json', category: 'saas' },
{ id: 'datadog', name: 'Datadog', statusPage: 'https://status.datadoghq.com/api/v2/status.json', category: 'saas' },
{ id: 'sentry', name: 'Sentry', statusPage: 'https://status.sentry.io/api/v2/status.json', category: 'saas' },
{ id: 'supabase', name: 'Supabase', statusPage: 'https://status.supabase.com/api/v2/status.json', category: 'saas' },
];
// Statuspage.io API returns status like: none, minor, major, critical
function normalizeStatus(indicator) {
if (!indicator) return 'unknown';
const val = indicator.toLowerCase();
// Check for operational indicators
if (val === 'none' || val === 'operational' || val.includes('all systems operational')) {
return 'operational';
}
// Check for degraded indicators
if (val === 'minor' || val === 'degraded_performance' || val === 'partial_outage' || val.includes('degraded')) {
return 'degraded';
}
// Check for outage indicators
if (val === 'major' || val === 'major_outage' || val === 'critical' || val.includes('outage')) {
return 'outage';
}
return 'unknown';
}
async function checkStatusPage(service) {
if (!service.statusPage) {
return { ...service, status: 'unknown', description: 'No API available' };
}
try {
// Use browser-like headers to avoid being blocked
const headers = {
'Accept': service.customParser === 'rss' ? 'application/xml, text/xml' : 'application/json, text/plain, */*',
'Accept-Language': 'en-US,en;q=0.9',
'Cache-Control': 'no-cache',
};
// Don't send User-Agent for incident.io - they may block bots
if (service.customParser !== 'incidentio') {
headers['User-Agent'] = 'Mozilla/5.0 (compatible; WorldMonitor/1.0)';
}
const response = await fetch(service.statusPage, {
headers,
signal: AbortSignal.timeout(10000),
});
if (!response.ok) {
return { ...service, status: 'unknown', description: `HTTP ${response.status}` };
}
// Handle custom parsers
if (service.customParser === 'gcp') {
const data = await response.json();
// GCP incidents.json returns array of incidents
const activeIncidents = Array.isArray(data) ? data.filter(i =>
i.end === undefined || new Date(i.end) > new Date()
) : [];
if (activeIncidents.length === 0) {
return { ...service, status: 'operational', description: 'All services operational' };
}
const severity = activeIncidents.some(i => i.severity === 'high') ? 'outage' : 'degraded';
return { ...service, status: severity, description: `${activeIncidents.length} active incident(s)` };
}
if (service.customParser === 'aws') {
// AWS status page is complex HTML - assume operational if reachable
return { ...service, status: 'operational', description: 'Status page reachable' };
}
if (service.customParser === 'rss') {
// Azure RSS feed - check if there are recent items (incidents)
const text = await response.text();
const hasRecentIncident = text.includes('<item>') &&
(text.includes('degradation') || text.includes('outage') || text.includes('incident'));
return {
...service,
status: hasRecentIncident ? 'degraded' : 'operational',
description: hasRecentIncident ? 'Recent incidents reported' : 'No recent incidents'
};
}
if (service.customParser === 'instatus') {
// Instatus format (Railway, etc.)
const data = await response.json();
const pageStatus = data.page?.status;
if (pageStatus === 'UP') {
return { ...service, status: 'operational', description: 'All systems operational' };
} else if (pageStatus === 'HASISSUES') {
return { ...service, status: 'degraded', description: 'Some issues reported' };
} else {
return { ...service, status: 'unknown', description: pageStatus || 'Unknown' };
}
}
if (service.customParser === 'statusio') {
// Status.io format (GitLab, Docker Hub)
const data = await response.json();
const overall = data.result?.status_overall;
const statusCode = overall?.status_code;
if (statusCode === 100) {
return { ...service, status: 'operational', description: overall.status || 'All systems operational' };
} else if (statusCode >= 300 && statusCode < 500) {
return { ...service, status: 'degraded', description: overall.status || 'Degraded performance' };
} else if (statusCode >= 500) {
return { ...service, status: 'outage', description: overall.status || 'Service disruption' };
}
return { ...service, status: 'unknown', description: overall?.status || 'Unknown status' };
}
if (service.customParser === 'slack') {
// Slack custom API format
const data = await response.json();
if (data.status === 'ok') {
return { ...service, status: 'operational', description: 'All systems operational' };
} else if (data.status === 'active' || data.active_incidents?.length > 0) {
const count = data.active_incidents?.length || 1;
return { ...service, status: 'degraded', description: `${count} active incident(s)` };
}
return { ...service, status: 'unknown', description: data.status || 'Unknown' };
}
if (service.customParser === 'stripe') {
// Stripe custom API format at /current
const data = await response.json();
if (data.largestatus === 'up') {
return { ...service, status: 'operational', description: data.message || 'All systems operational' };
} else if (data.largestatus === 'degraded') {
return { ...service, status: 'degraded', description: data.message || 'Degraded performance' };
} else if (data.largestatus === 'down') {
return { ...service, status: 'outage', description: data.message || 'Service disruption' };
}
return { ...service, status: 'unknown', description: data.message || 'Unknown' };
}
if (service.customParser === 'incidentio') {
// incident.io status pages (OpenAI, Linear, Replicate, Anthropic)
const text = await response.text();
// Check for HTML response (blocked)
if (text.startsWith('<!') || text.startsWith('<html')) {
// Try parsing HTML for status - incident.io pages have status in HTML
const operationalMatch = text.match(/All Systems Operational|fully operational|no issues/i);
if (operationalMatch) {
return { ...service, status: 'operational', description: 'All systems operational' };
}
const degradedMatch = text.match(/degraded|partial outage|experiencing issues/i);
if (degradedMatch) {
return { ...service, status: 'degraded', description: 'Some issues reported' };
}
return { ...service, status: 'unknown', description: 'Could not parse status' };
}
// Parse JSON response
try {
const data = JSON.parse(text);
const indicator = data.status?.indicator || '';
const description = data.status?.description || '';
if (indicator === 'none' || description.toLowerCase().includes('operational')) {
return { ...service, status: 'operational', description: description || 'All systems operational' };
} else if (indicator === 'minor' || indicator === 'maintenance') {
return { ...service, status: 'degraded', description: description || 'Minor issues' };
} else if (indicator === 'major' || indicator === 'critical') {
return { ...service, status: 'outage', description: description || 'Major outage' };
}
return { ...service, status: 'operational', description: description || 'Status OK' };
} catch {
return { ...service, status: 'unknown', description: 'Invalid response' };
}
}
const text = await response.text();
// Check if we got HTML instead of JSON (blocked/redirected)
if (text.startsWith('<!') || text.startsWith('<html')) {
return { ...service, status: 'unknown', description: 'Blocked by service' };
}
let data;
try {
data = JSON.parse(text);
} catch {
return { ...service, status: 'unknown', description: 'Invalid JSON response' };
}
// Handle different API formats
let status, description;
if (data.status?.indicator !== undefined) {
// Standard Statuspage.io format
status = normalizeStatus(data.status.indicator);
description = data.status.description || '';
} else if (data.status?.status) {
// Slack format
status = data.status.status === 'ok' ? 'operational' : 'degraded';
description = data.status.description || '';
} else if (data.page && data.status) {
// Alternative Statuspage format - check if status object exists
status = normalizeStatus(data.status.indicator || data.status.description);
description = data.status.description || 'Status available';
} else {
status = 'unknown';
description = 'Unknown format';
}
return { ...service, status, description };
} catch (error) {
return { ...service, status: 'unknown', description: error.message || 'Request failed' };
}
}
export default async function handler(req) {
const url = new URL(req.url);
const category = url.searchParams.get('category'); // cloud, dev, comm, ai, saas, or all
let servicesToCheck = SERVICES;
if (category && category !== 'all') {
servicesToCheck = SERVICES.filter(s => s.category === category);
}
// Check all services in parallel
const results = await Promise.all(servicesToCheck.map(checkStatusPage));
// Sort by status (outages first, then degraded, then operational)
const statusOrder = { outage: 0, degraded: 1, unknown: 2, operational: 3 };
results.sort((a, b) => statusOrder[a.status] - statusOrder[b.status]);
const summary = {
operational: results.filter(r => r.status === 'operational').length,
degraded: results.filter(r => r.status === 'degraded').length,
outage: results.filter(r => r.status === 'outage').length,
unknown: results.filter(r => r.status === 'unknown').length,
};
return new Response(JSON.stringify({
success: true,
timestamp: new Date().toISOString(),
summary,
services: results.map(r => ({
id: r.id,
name: r.name,
category: r.category,
status: r.status,
description: r.description,
})),
}), {
headers: {
'Content-Type': 'application/json',
'Access-Control-Allow-Origin': '*',
'Cache-Control': 'public, max-age=60', // 1 min cache
},
});
}