-
-
Save omega8cc/ec1aedb55c07c657fa93 to your computer and use it in GitHub Desktop.
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
require 'net/http' | |
require 'net/https' | |
require 'uri' | |
PINGDOM_API_HOSTNAME = "api.pingdom.com" | |
PINGDOM_API_KEY = "your_api_key_here" | |
PINGDOM_API_VERSION = "2.0" | |
PINGDOM_CHECK_ID = "######" | |
PINGDOM_USERNAME = "[email protected]" | |
PINGDOM_PASSWORD = "password" | |
# This method uses the Pingdom API to pause and un-pause a Pingdom check | |
# Doing so should prevent unnecessary (both annoying + expensive) false alarms of downtime during deploys | |
# Params: | |
# do_it -- defaults to true -- this param represents whether the check should be paused (pause = true, unpause = false) | |
def pause_pingdom_check(do_it=true) | |
# assemble the url to hit | |
target_url = "https://" + PINGDOM_API_HOSTNAME + "/api/" + PINGDOM_API_VERSION + "/checks/" + PINGDOM_CHECK_ID | |
headers = { | |
'App-Key' => PINGDOM_API_KEY | |
} | |
# setup the connection and hit the url with params -- paused => true | |
url = URI.parse( target_url ) | |
http = Net::HTTP.new(url.host, 443) #send to port 443 to avoid unknown protocol error | |
http.use_ssl = true | |
http.verify_mode = OpenSSL::SSL::VERIFY_NONE # ignore noisy certificate errors | |
# configure the request | |
request = Net::HTTP::Put.new(url.path, headers) | |
request.basic_auth PINGDOM_USERNAME, PINGDOM_PASSWORD | |
request.set_form_data({ :paused => do_it }, ';') | |
# make the request and get response | |
response = http.request( request ) | |
# were we successful? | |
case response | |
when Net::HTTPSuccess#, Net::HTTPRedirection | |
puts response.body | |
return true | |
else | |
raise response.error! | |
end | |
end | |
pause_pingdom_check(true) | |
pause_pingdom_check(false) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment