Last active
September 23, 2015 22:09
-
-
Save jderrett/28bc1df891034ac98e1b to your computer and use it in GitHub Desktop.
Get Librato Alerts with Status and optionally clear triggered alerts
This file contains 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
require 'librato/metrics' | |
require 'json' | |
c = Librato::Metrics | |
c.authenticate '[email protected]', 'token' | |
alerts = JSON.parse(c.connection.get('/v1/alerts?version=2').body)['alerts'] | |
alert_ids = alerts.map {|a| a['id']} | |
show_ok_alerts = true | |
clear_triggered = false | |
# Get status of each alert | |
alert_ids.each do |id| | |
resp = JSON.parse(c.connection.get("/v1/alerts/#{id}/status").body) | |
status = resp['status'] | |
if status == 'triggered' | |
puts resp | |
puts "https://metrics.librato.com/alerts#/#{id}" | |
if clear_triggered | |
resp = c.connection.post("/v1/alerts/#{id}/clear") | |
if resp.status == 204 | |
puts "cleared #{id}" | |
else | |
puts "Failed to clear #{id} with #{resp.status}" | |
end | |
end | |
elsif show_ok_alerts && status == 'ok' | |
puts resp | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
awesome @jderret, thanks!