Skip to content

Instantly share code, notes, and snippets.

@pkhamre
Created September 13, 2012 12:02
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pkhamre/3713894 to your computer and use it in GitHub Desktop.
Save pkhamre/3713894 to your computer and use it in GitHub Desktop.
Pingdom maintenance window

Pingdom maintenance window

A simple ruby-script which uses em-http-request to send an API request to the Pingdom API to pause or unpause all checks.

#!/usr/bin/env ruby
require 'em-http'
require 'em-http/middleware/json_response'
require 'optparse'
require 'yaml'
config = YAML.load_file 'pingdom.yml'
pingdom_user = config['username']
pingdom_pass = config['password']
pingdom_appkey = config['appkey']
host = 'https://api.pingdom.com'
request_options = {
:path => '/api/2.0/checks',
:head => {
'accept-encoding' => 'gzip, compressed',
'app-key' => pingdom_appkey,
'authorization' => [pingdom_user, pingdom_pass]
}
}
optparse = OptionParser.new do |opts|
opts.banner = "usage: #{$0} [options]"
opts.on('-h', '--help', 'display this message') do
puts opts
exit
end
opts.on('-p', '--pause', 'pause all checks') do
request_options[:body] = 'paused=true'
end
opts.on('-u', '--unpause', 'unpause all checks') do
request_options[:body] = 'paused=false'
end
end
optparse.parse!
EventMachine.run do
EventMachine::HttpRequest.use EventMachine::Middleware::JSONResponse
http = EventMachine::HttpRequest.new host
request = http.put request_options
request.callback do
if request.response.has_key? 'error'
puts request.response
exit 1
else
EventMachine.stop_event_loop
end
end
end
username: '<pingdom username>'
password: '<pingdom password>'
appkey: 'pingdom application key>'
@Robs79
Copy link

Robs79 commented Apr 2, 2013

If anyone needs a C# version, I posted one here:

http://www.robertsindall.co.uk/blog/pingdom-maintenance-window-using-c/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment