Skip to content
This repository was archived by the owner on Sep 29, 2021. It is now read-only.

Commit 400ab21

Browse files
authored
Merge pull request #3 from zgalor/add_post
Add post API call to post alerts
2 parents 1483d0a + 618bdad commit 400ab21

File tree

4 files changed

+25
-2
lines changed

4 files changed

+25
-2
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,8 @@ alerts = prometheus.get()
3636
\# get all the alerts with generation_id='12497ca8-b597-4590-ac5d-d55af7f3d185' and index >= 34
3737

3838
alerts = prometheus.get(generation_id: '12497ca8-b597-4590-ac5d-d55af7f3d185', from_index: 34)
39+
40+
#### Posting alerts
41+
\# post an alert JSON to server
42+
43+
alerts = prometheus.post('{"alertId":12}')

examples/get_alerts.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
require 'prometheus/alert_buffer_client'
22

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

6-
alerts = prometheus.get(generation_id: '12497ca8-b597-4590-ac5d-d55af7f3d185', from_index: 5)
6+
alerts = prometheus.get(generation_id: '12497ca8-b597-4590-ac5d-d55af7f3d185', from_index: 1)
77
puts alerts

examples/post_alerts.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
require 'prometheus/alert_buffer_client'
2+
3+
# returns a client
4+
prometheus = Prometheus::AlertBufferClient::Client.new(url: 'http://localhost:9099', path: '/topics/test')
5+
6+
prometheus.post '{"posted":"alert"}'
7+
prometheus.post '{"alertId":12}'
8+

lib/prometheus/alert_buffer_client/client.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,16 @@ def get(options = {})
5959
JSON.parse(response.body)['messages']
6060
end
6161

62+
# post alert:
63+
# @param [String] alert Alert to post
64+
def post(alert)
65+
@client.post do |req|
66+
req.body = alert
67+
end
68+
rescue
69+
raise RequestError, 'Bad response from server'
70+
end
71+
6272
# Helper function to evalueate the low level proxy option
6373
def faraday_proxy(options)
6474
return options[:proxy] if options[:proxy]

0 commit comments

Comments
 (0)