Created
July 30, 2013 23:05
-
-
Save joehack3r/6117854 to your computer and use it in GitHub Desktop.
Updating DataDog alert field notify_no_data to false
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 'rubygems' | |
require 'uri' | |
require 'net/https' | |
require 'json' | |
api_key='' | |
app_key='' | |
uri = URI.parse("https://app.datadoghq.com") | |
http = Net::HTTP.new(uri.host, uri.port) | |
http.use_ssl = true | |
http.verify_mode = OpenSSL::SSL::VERIFY_NONE | |
allAlertRequest = Net::HTTP::Get.new("/api/v1/alert?api_key=#{api_key}&application_key=#{app_key}") | |
allAlerts = JSON.parse(http.request(allAlertRequest).body) | |
allAlerts['alerts'].each do |alert| | |
alertName = alert['name'] | |
updateRequest = Net::HTTP::Put.new("/api/v1/alert/#{alert['id']}?api_key=#{api_key}&application_key=#{app_key}") | |
updateRequest.add_field('Content-Type', 'application/json') | |
updateRequest.body = "{ | |
\"notify_no_data\": \"false\", | |
\"name\": \"#{alert['name']}\", | |
\"silenced\": \"#{alert['silenced']}\", | |
\"query\": \"#{alert['query']}\", | |
\"message\": \"#{alert['message'].gsub(/\n/, "\\n")}\" | |
}" | |
updateResponse = http.request(updateRequest) | |
if updateResponse.code != '200' | |
puts "#{updateResponse.code}" | |
puts "#{updateRequest.body}" | |
puts "#{updateResponse.body}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment