Skip to content

Instantly share code, notes, and snippets.

@shedd
Created June 24, 2011 21:57
Show Gist options
  • Save shedd/1045778 to your computer and use it in GitHub Desktop.
Save shedd/1045778 to your computer and use it in GitHub Desktop.
Script to use the Pingdom API to pause and unpause check
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 = "user@domain.com"
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