Skip to content

Instantly share code, notes, and snippets.

@omega8cc
Forked from shedd/pause_pingdom.rb
Last active August 29, 2015 14:14
Show Gist options
  • Select an option

  • Save omega8cc/ec1aedb55c07c657fa93 to your computer and use it in GitHub Desktop.

Select an option

Save omega8cc/ec1aedb55c07c657fa93 to your computer and use it in GitHub Desktop.

Revisions

  1. Robert Shedd created this gist Jun 24, 2011.
    50 changes: 50 additions & 0 deletions pause_pingdom.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,50 @@
    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)