Skip to content

Instantly share code, notes, and snippets.

@fernandobatels
Created March 26, 2025 18:09
Show Gist options
  • Save fernandobatels/e0fc014186ebed442903b6060e678442 to your computer and use it in GitHub Desktop.
Save fernandobatels/e0fc014186ebed442903b6060e678442 to your computer and use it in GitHub Desktop.
#!/bin/ruby
require 'json'
require 'rugged'
require 'fileutils'
repo_url = 'https://github.com/outages/vultr-outages.git'
clone_path = '/tmp/vultr-outages'
if !Dir.exist?(clone_path)
Rugged::Repository.clone_at(repo_url, clone_path)
end
repo = Rugged::Repository.new(clone_path)
repo.remotes['origin'].fetch
walker = Rugged::Walker.new(repo)
walker.push(repo.head.target)
alerts = []
walker.each do |commit|
begin
entry = commit.tree.path("vultr_outages.json")
blob = repo.lookup(entry[:oid])
rescue Rugged::TreeError
next
end
if blob.content.empty?
next
end
outages = JSON.parse(blob.content, symbolize_names: true)
regions = outages[:regions].is_a?(Array) ? outages[:regions] : outages[:regions].values
regions.each do |region|
region[:alerts].each do |alert|
alerts << { region: region, alert: alert }
end
end
end
puts "Country,Region,Timestamp,ID,Message"
unique_alerts = alerts.uniq { |al| al[:alert][:id] }
unique_alerts.each do |al|
puts "\"#{al[:region][:country]}\", \"#{al[:region][:location]}\", \"#{al[:alert][:start_date]}\", \"#{al[:alert][:id]}\", \"#{al[:alert][:subject]}\""
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment