-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.rb
45 lines (39 loc) · 899 Bytes
/
app.rb
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
require 'sinatra'
require 'httparty'
require 'json'
require 'yaml'
class StatusPageAggregator < Sinatra::Base
configure do
set :status_pages, YAML.load_file('config/status_pages.yml')
end
get '/styles.css' do
scss :styles
end
get '/' do
@status_pages = settings.status_pages
erb :index
end
get '/statuses' do
statuses = fetch_statuses
content_type :json
statuses.to_json
end
private
def fetch_statuses
settings.status_pages.map do |name, url|
response = HTTParty.get("#{url}/api/v2/summary.json")
if response.success?
data = JSON.parse(response.body)
{
name: name,
url: url,
page: data['page'],
status: data['status'],
incidents: data['incidents']
}
else
{ name: name, url: url, error: "Failed to fetch status" }
end
end
end
end