Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save orangewolf/f7d285f8aab838d002ba6966f98ccd51 to your computer and use it in GitHub Desktop.
Save orangewolf/f7d285f8aab838d002ba6966f98ccd51 to your computer and use it in GitHub Desktop.
make_checks.rb
#!/usr/bin/env ruby
require 'rest-client'
require 'json'
API_KEY=''
def checks
return @checks if @checks
@checks = RestClient.get("https://healthchecks.io/api/v1/checks/", {"X-Api-Key" => API_KEY })
@checks = JSON.parse(@checks.body)['checks']
end
def create_check(check)
#check = checks.detect do |c| c['name'] == "Tilma BcCath - get_refunds" end
#return check if check
payload = {
name: check[:name],
tags: 'tilma glass-canvas',
timeout: check[:period],
grace: check[:grace],
unique: ["name"]
}
@result = RestClient.post("https://healthchecks.io/api/v1/checks/", payload.to_json, {"X-Api-Key" => API_KEY })
new_check = JSON.parse(@result.body)["update_url"]
puts "#{check[:var]}=#{new_check}"
end
name = ARGV[0]
raise 'please provide a name' unless name && name.size > 2
checks = [
{var: 'FORMS_GET_RFND_PING', name: "Tilma #{name} - get_refunds", period: 86400, grace: 172800},
{var: 'EMAIL_PING', name: "Tilma #{name} - send_queued_emails", period: 360, grace: 1800},
{var: 'FORMS_GET_APPL_PING', name: "Tilma #{name} - cancel_completed_subscriptions", period: 86400, grace: 3600},
{var: 'FORMS_GET_SUB_PING', name: "Tilma #{name} - get_subscription_charges", period: 86400, grace: 3600}
]
checks.each do |check|
create_check(check)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment