A simple ruby-script which uses em-http-request to send an API request to the Pingdom API to pause or unpause all checks.
Created
September 13, 2012 12:02
-
-
Save pkhamre/3713894 to your computer and use it in GitHub Desktop.
Pingdom maintenance window
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 '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 |
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
username: '<pingdom username>' | |
password: '<pingdom password>' | |
appkey: 'pingdom application key>' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If anyone needs a C# version, I posted one here:
http://www.robertsindall.co.uk/blog/pingdom-maintenance-window-using-c/