Skip to content
This repository was archived by the owner on Sep 29, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,8 @@ alerts = prometheus.get()
\# get all the alerts with generation_id='12497ca8-b597-4590-ac5d-d55af7f3d185' and index >= 34

alerts = prometheus.get(generation_id: '12497ca8-b597-4590-ac5d-d55af7f3d185', from_index: 34)

#### Posting alerts
\# post an alert JSON to server

alerts = prometheus.post('{"alertId":12}')
4 changes: 2 additions & 2 deletions examples/get_alerts.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'prometheus/alert_buffer_client'

# returns a client
prometheus = Prometheus::AlertBufferClient::Client.new(url: 'http://localhost:9099', path: '/topics/zgalor')
prometheus = Prometheus::AlertBufferClient::Client.new(url: 'http://localhost:9099', path: '/topics/test')

alerts = prometheus.get(generation_id: '12497ca8-b597-4590-ac5d-d55af7f3d185', from_index: 5)
alerts = prometheus.get(generation_id: '12497ca8-b597-4590-ac5d-d55af7f3d185', from_index: 1)
puts alerts
8 changes: 8 additions & 0 deletions examples/post_alerts.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
require 'prometheus/alert_buffer_client'

# returns a client
prometheus = Prometheus::AlertBufferClient::Client.new(url: 'http://localhost:9099', path: '/topics/test')

prometheus.post '{"posted":"alert"}'
prometheus.post '{"alertId":12}'

10 changes: 10 additions & 0 deletions lib/prometheus/alert_buffer_client/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,16 @@ def get(options = {})
JSON.parse(response.body)['messages']
end

# post alert:
# @param [String] alert Alert to post
def post(alert)
@client.post do |req|
req.body = alert
end
rescue
raise RequestError, 'Bad response from server'
end

# Helper function to evalueate the low level proxy option
def faraday_proxy(options)
return options[:proxy] if options[:proxy]
Expand Down