Skip to content

Instantly share code, notes, and snippets.

@jderrett
Last active September 23, 2015 22:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jderrett/28bc1df891034ac98e1b to your computer and use it in GitHub Desktop.
Save jderrett/28bc1df891034ac98e1b to your computer and use it in GitHub Desktop.
Get Librato Alerts with Status and optionally clear triggered alerts
require 'librato/metrics'
require 'json'
c = Librato::Metrics
c.authenticate 'you@example.com', '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
@mauricioborges
Copy link

awesome @jderret, thanks!

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