prometheus-alert-buffer-client 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/README.md +38 -0
- data/lib/prometheus.rb +5 -0
- data/lib/prometheus/alert_buffer_client.rb +17 -0
- data/lib/prometheus/alert_buffer_client/client.rb +121 -0
- data/lib/prometheus/alert_buffer_client/version.rb +7 -0
- metadata +63 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ed1108215a4174f4c8f44c3508af348ac27853d6
|
4
|
+
data.tar.gz: c4a056afaacb9a5815a7a7aef8ab58097580c908
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0c848caab706f6c103c7a6896b1383f670e5861b1139c59f781d7aaf74fa6090ccd0a0aff73e6f623895e859ac1ba2ecd56b2767810cadb9845e171c2f7ab62c
|
7
|
+
data.tar.gz: 6db2df7aa5389aa3b7765e52addfa4b985bb313692ea92b4b358ae5426b12fec914cb6621bfaeed2a535ccd02f57c1a544fd98bce469985a22426e9fb54a62e8
|
data/README.md
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# Prometheus Alert Buffer Ruby Client
|
2
|
+
A Ruby library for reading alerts stored on a Prometheus Alert Buffer server.
|
3
|
+
|
4
|
+
## Usage
|
5
|
+
### Overview
|
6
|
+
|
7
|
+
require 'prometheus/alert_buffer_client'
|
8
|
+
|
9
|
+
\# return a client for host http://example.com:9099/topics/alerts
|
10
|
+
|
11
|
+
prometheus = Prometheus::AlertBufferClient.client(url: 'http://example.com:9099')
|
12
|
+
|
13
|
+
### Changing alerts path
|
14
|
+
|
15
|
+
\# return a client for host http://example.com:9099/topics/topic1
|
16
|
+
|
17
|
+
prometheus = Prometheus::AlertBufferClient.client(url: 'http://example.com:9090', path: '/topics/topic1')
|
18
|
+
|
19
|
+
### Authentication proxy
|
20
|
+
|
21
|
+
If an authentication proxy ( e.g. oauth2 ) is used in a layer above the prometheus-alert-buffer REST server, this client can use ssl and authentication headers.
|
22
|
+
|
23
|
+
\# return a client for host https://example.com/topics/alerts using a Bearer token "TopSecret"
|
24
|
+
|
25
|
+
prometheus = Prometheus::AlertBufferClient.client(url: 'https://example.com:443',
|
26
|
+
credentials: { token: 'TopSecret' })
|
27
|
+
|
28
|
+
### Api calls
|
29
|
+
|
30
|
+
#### Reading alerts
|
31
|
+
\# get all the alerts from server
|
32
|
+
|
33
|
+
alerts = prometheus.get()
|
34
|
+
|
35
|
+
#### Reading latest alerts
|
36
|
+
\# get all the alerts with generation_id='12497ca8-b597-4590-ac5d-d55af7f3d185' and index >= 34
|
37
|
+
|
38
|
+
alerts = prometheus.get(generation_id: '12497ca8-b597-4590-ac5d-d55af7f3d185', from_index: 34)
|
data/lib/prometheus.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require 'uri'
|
4
|
+
require 'openssl'
|
5
|
+
require 'prometheus/alert_buffer_client/client'
|
6
|
+
|
7
|
+
module Prometheus
|
8
|
+
|
9
|
+
# Alert Client is a ruby implementation for a Prometheus-alert-buffer client.
|
10
|
+
module AlertBufferClient
|
11
|
+
|
12
|
+
def self.client(options = {})
|
13
|
+
Client.new(options)
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,121 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require 'json'
|
4
|
+
require 'faraday'
|
5
|
+
|
6
|
+
module Prometheus
|
7
|
+
# Alert Client is a ruby implementation for a Prometheus-alert-buffer client.
|
8
|
+
module AlertBufferClient
|
9
|
+
# Client contains the implementation for a Prometheus-alert-buffer client.
|
10
|
+
class Client
|
11
|
+
class RequestError < StandardError; end
|
12
|
+
|
13
|
+
# Default parameters for creating default client
|
14
|
+
DEFAULT_ARGS = {
|
15
|
+
path: '/topics/alerts',
|
16
|
+
credentials: {},
|
17
|
+
options: {
|
18
|
+
open_timeout: 2,
|
19
|
+
timeout: 5,
|
20
|
+
},
|
21
|
+
}.freeze
|
22
|
+
|
23
|
+
|
24
|
+
# Create a Prometheus Alert client:
|
25
|
+
#
|
26
|
+
# @param [Hash] options
|
27
|
+
# @option options [String] :url server base URL.
|
28
|
+
# @option options [Hash] :credentials Authentication credentials.
|
29
|
+
# @option options [Hash] :options Options used to define connection.
|
30
|
+
# @option options [Hash] :params URI query unencoded key/value pairs.
|
31
|
+
# @option options [Hash] :headers Unencoded HTTP header key/value pairs.
|
32
|
+
# @option options [Hash] :request Request options.
|
33
|
+
# @option options [Hash] :ssl SSL options.
|
34
|
+
# @option options [Hash] :proxy Proxy options.
|
35
|
+
#
|
36
|
+
# A default client is created if options is omitted.
|
37
|
+
def initialize(options = {})
|
38
|
+
options = DEFAULT_ARGS.merge(options)
|
39
|
+
|
40
|
+
@client = Faraday.new(
|
41
|
+
faraday_options(options),
|
42
|
+
)
|
43
|
+
end
|
44
|
+
|
45
|
+
|
46
|
+
# Get alerts:
|
47
|
+
#
|
48
|
+
# @param [Hash] options
|
49
|
+
# @option options [String] :generation_id Database generation Id.
|
50
|
+
# @option options [Integer] :from_index Minimal index of alerts to fetch.
|
51
|
+
#
|
52
|
+
# All alerts will be fetched if options are omitted.
|
53
|
+
def get(options = {})
|
54
|
+
response = @client.get do |req|
|
55
|
+
req.params['generationID'] = options[:generation_id]
|
56
|
+
req.params['fromIndex'] = options[:from_index]
|
57
|
+
end
|
58
|
+
|
59
|
+
JSON.parse(response.body)['messages']
|
60
|
+
end
|
61
|
+
|
62
|
+
# Helper function to evalueate the low level proxy option
|
63
|
+
def faraday_proxy(options)
|
64
|
+
return options[:proxy] if options[:proxy]
|
65
|
+
|
66
|
+
proxy = options[:options]
|
67
|
+
proxy[:http_proxy_uri] if proxy[:http_proxy_uri]
|
68
|
+
end
|
69
|
+
|
70
|
+
# Helper function to evalueate the low level ssl option
|
71
|
+
def faraday_ssl(options)
|
72
|
+
return options[:ssl] if options[:ssl]
|
73
|
+
|
74
|
+
ssl = options[:options]
|
75
|
+
return unless ssl[:verify_ssl] || ssl[:ssl_cert_store]
|
76
|
+
|
77
|
+
{
|
78
|
+
verify: ssl[:verify_ssl] != OpenSSL::SSL::VERIFY_NONE,
|
79
|
+
cert_store: ssl[:ssl_cert_store],
|
80
|
+
}
|
81
|
+
end
|
82
|
+
|
83
|
+
# Helper function to evalueate the low level headers option
|
84
|
+
def faraday_headers(options)
|
85
|
+
return options[:headers] if options[:headers]
|
86
|
+
|
87
|
+
headers = options[:credentials]
|
88
|
+
return unless headers && headers[:token]
|
89
|
+
|
90
|
+
{
|
91
|
+
Authorization: "Bearer #{headers[:token].to_s}",
|
92
|
+
}
|
93
|
+
end
|
94
|
+
|
95
|
+
# Helper function to evalueate the low level headers option
|
96
|
+
def faraday_request(options)
|
97
|
+
return options[:request] if options[:request]
|
98
|
+
|
99
|
+
request = options[:options]
|
100
|
+
return unless request[:open_timeout] || request[:timeout]
|
101
|
+
|
102
|
+
{
|
103
|
+
open_timeout: request[:open_timeout],
|
104
|
+
timeout: request[:timeout],
|
105
|
+
}
|
106
|
+
end
|
107
|
+
|
108
|
+
# Helper function to create the args for the low level client
|
109
|
+
def faraday_options(options)
|
110
|
+
{
|
111
|
+
url: options[:url] + options[:path],
|
112
|
+
proxy: faraday_proxy(options),
|
113
|
+
ssl: faraday_ssl(options),
|
114
|
+
headers: faraday_headers(options),
|
115
|
+
request: faraday_request(options),
|
116
|
+
}
|
117
|
+
end
|
118
|
+
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
metadata
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: prometheus-alert-buffer-client
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Zohar Galor
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-11-07 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: faraday
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.9.2
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.9.2
|
27
|
+
description:
|
28
|
+
email:
|
29
|
+
- zgalor@redhat.com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- README.md
|
35
|
+
- lib/prometheus.rb
|
36
|
+
- lib/prometheus/alert_buffer_client.rb
|
37
|
+
- lib/prometheus/alert_buffer_client/client.rb
|
38
|
+
- lib/prometheus/alert_buffer_client/version.rb
|
39
|
+
homepage: https://github.com/openshift/prometheus-alert-buffer-client-ruby
|
40
|
+
licenses:
|
41
|
+
- Apache-2.0
|
42
|
+
metadata: {}
|
43
|
+
post_install_message:
|
44
|
+
rdoc_options: []
|
45
|
+
require_paths:
|
46
|
+
- lib
|
47
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: '0'
|
52
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0'
|
57
|
+
requirements: []
|
58
|
+
rubyforge_project:
|
59
|
+
rubygems_version: 2.6.13
|
60
|
+
signing_key:
|
61
|
+
specification_version: 4
|
62
|
+
summary: A suite of reading alerts stored on a Prometheus Alert Buffer server.
|
63
|
+
test_files: []
|