Created
June 5, 2019 00:05
-
-
Save orangewolf/f7d285f8aab838d002ba6966f98ccd51 to your computer and use it in GitHub Desktop.
make_checks.rb
This file contains hidden or 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 | |
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