Skip to content

Commit

Permalink
Add StatusPage.io Plugin (#585)
Browse files Browse the repository at this point in the history
* Add StatusPage.io Plugin

* +x
  • Loading branch information
stephenyeargin authored and tresni committed Oct 24, 2016
1 parent 3628291 commit 3a6ee75
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions Tools/statuspage.1m.rb
@@ -0,0 +1,62 @@
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-

# <bitbar.title>StatusPage.io</bitbar.title>
# <bitbar.version>v1.0.0</bitbar.version>
# <bitbar.author>Stephen Yeargin</bitbar.author>
# <bitbar.author.github>stephenyeargin</bitbar.author.github>
# <bitbar.desc>Show a StatusPage.io's Status in BitBar</bitbar.desc>
# <bitbar.dependencies>ruby</bitbar.dependencies>
# <bitbar.image>http://i.imgur.com/FsD4zDD.png</bitbar.image>

require 'open-uri'
require 'json'

# BEGIN Configuration #

statuspage_id = 'YOUR_ID_HERE' # e.g. 4y7j9y37gcns
url = "https://#{statuspage_id}.statuspage.io/api/v2/summary.json"

# END Configuration #

status_map = {
operational: {
name: 'Operational',
color: 'gold'
},
degraded_performance: {
name: 'Degraded Performance',
color: 'orange'
},
partial_outage: {
name: 'Partial Outage',
color: 'yellow'
},
major_outage: {
name: 'Major Outage',
color: 'red'
}
}

begin
raise 'Missing configuration.' if statuspage_id == 'YOUR_ID_HERE'

summary = JSON.parse(open(url).read)

puts summary['status']['description']
puts '---'
puts "#{summary['page']['name']}|href=#{summary['page']['url']}"
puts summary['status']['description']
puts '---'
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 "Open: #{summary['page']['url']}|href=#{summary['page']['url']}"
rescue StandardError => e
puts 'Unable to load status!|color=red'
puts e.message
exit 1
end

0 comments on commit 3a6ee75

Please sign in to comment.