Last active
September 21, 2023 14:59
-
-
Save benschweizer/dc3fe74c04e487e373c5f69abf038f36 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# -*- coding: utf-8 -*- | |
# <xbar.title>StatusPage.io</xbar.title> | |
# <xbar.version>v1.0.0</xbar.version> | |
# <xbar.author>Stephen Yeargin</xbar.author> | |
# <xbar.author.github>stephenyeargin</xbar.author.github> | |
# <xbar.desc>Show a StatusPage.io's Status in BitBar</xbar.desc> | |
# <xbar.dependencies>ruby</xbar.dependencies> | |
# <xbar.image>http://i.imgur.com/FsD4zDD.png</xbar.image> | |
# https://doers.statuspage.io/api/v1/incidents/ | |
require 'open-uri' | |
require 'json' | |
# BEGIN Configuration # | |
statuspage_id = '1s5n5g5wh9fr' # e.g. 4y7j9y37gcns | |
url = "https://#{statuspage_id}.statuspage.io/api/v2/summary.json" | |
# END Configuration # | |
status_map = { | |
operational: { | |
name: 'Operational', | |
color: 'gold' | |
}, | |
scheduled: { | |
name: 'Scheduled Maintenance', | |
color: 'black' | |
}, | |
under_maintenance: { | |
name: 'Active Maintennce', | |
color: 'black' | |
}, | |
degraded_performance: { | |
name: 'Degraded Performance', | |
color: 'yellow' | |
}, | |
partial_outage: { | |
name: 'Partial Outage', | |
color: 'orange' | |
}, | |
major_outage: { | |
name: 'Major Outage', | |
color: 'red' | |
} | |
} | |
indicator_map = { | |
none: { | |
name: 'Operational', | |
color: 'black' | |
}, | |
# degraded: { | |
# name: 'Degraded Performance', | |
# color: 'yellow' | |
# }, | |
# partial: { | |
# name: 'Partial Outage', | |
# color: 'orange' | |
# }, | |
maintenance: { | |
name: 'Service Under Maintenance', | |
color: 'black' | |
}, | |
minor: { | |
name: 'Minor Outage', | |
color: 'orange' | |
}, | |
major: { | |
name: 'Major Outage', | |
color: 'red' | |
} | |
} | |
incident_map = { | |
none: { | |
name: 'No Incident', | |
color: 'black' | |
}, | |
minor: { | |
name: 'Minor Incident', | |
color: 'orange' | |
}, | |
major: { | |
name: 'Major Incident', | |
color: 'red' | |
}, | |
critical: { | |
name: 'Major Incident', | |
color: 'red' | |
} | |
} | |
begin | |
raise 'Missing configuration.' if statuspage_id == 'YOUR_ID_HERE' | |
#summary = JSON.parse(open(url).read) | |
summary = JSON.parse(open(url, proxy: URI.parse("http://localhost:8080")).read) | |
# puts "DEBUG: #{summary['status']['indicator']}" | |
# puts summary['status']['indicator'] | |
# puts '---' | |
# puts "#{summary['page']['name']}|href=#{summary['page']['url']}" | |
# puts summary['status']['description'] | |
# puts '---' | |
if summary['incidents'].length > 0 then | |
incidents = summary['incidents'].first | |
# puts "#{incident_map[incidents['impact'].to_sym][:name]}: " \ | |
# "#{incidents['status']}"\ | |
# "|color=#{incident_map[incidents['impact'].to_sym][:color]}" | |
puts "STACKIT" \ | |
"|color=#{incident_map[incidents['impact'].to_sym][:color]}" | |
else | |
if summary['status']['indicator'] == "none" then | |
puts "STACKIT" | |
#puts "#{summary['status']['description']} " | |
else | |
puts "#{summary['status']['description']} " \ | |
"|color=#{indicator_map[summary['status']['indicator'].to_sym][:color]}" | |
end | |
end | |
puts '---' | |
# puts "incidents:" | |
summary['incidents'].each do |incidents| | |
next unless incidents['status'] != 'operational' | |
puts "#{incident_map[incidents['impact'].to_sym][:name]}: " \ | |
"#{incidents['status']}"\ | |
"|color=#{incident_map[incidents['impact'].to_sym][:color]}|href=#{summary['page']['url']}" | |
end | |
puts '---' | |
# puts "components:" | |
summary['components'].each do |component| | |
next unless component['status'] != 'operational' | |
puts "#{status_map[component['status'].to_sym][:name]}: "\ | |
"#{component['name']}"\ | |
"|color=#{status_map[component['status'].to_sym][:color]}" | |
end | |
puts '---' | |
puts "Open: #{summary['page']['url']}|href=#{summary['page']['url']}" | |
# puts '---' | |
# puts "status:" | |
# puts "#{summary['status']['description']} " \ | |
# "|color=#{indicator_map[summary['status']['indicator'].to_sym][:color]}" | |
# puts '---' | |
# puts "maintenances: #{summary['scheduled_maintenances'].length}" | |
rescue StandardError => e | |
#puts 'Unable to load status!|color=red' | |
puts e.message | |
exit 1 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment