Class: Prometheus::AlertBufferClient::Client
- Inherits:
-
Object
- Object
- Prometheus::AlertBufferClient::Client
- Defined in:
- lib/prometheus/alert_buffer_client/client.rb
Overview
Client contains the implementation for a Prometheus-alert-buffer client.
Defined Under Namespace
Classes: RequestError
Constant Summary collapse
- DEFAULT_ARGS =
Default parameters for creating default client
{ path: '/topics/alerts', credentials: {}, options: { open_timeout: 2, timeout: 5, }, }.freeze
Instance Method Summary collapse
-
#faraday_headers(options) ⇒ Object
Helper function to evalueate the low level headers option.
-
#faraday_options(options) ⇒ Object
Helper function to create the args for the low level client.
-
#faraday_proxy(options) ⇒ Object
Helper function to evalueate the low level proxy option.
-
#faraday_request(options) ⇒ Object
Helper function to evalueate the low level headers option.
-
#faraday_ssl(options) ⇒ Object
Helper function to evalueate the low level ssl option.
-
#get(options = {}) ⇒ Hash
Get alerts:.
-
#initialize(options = {}) ⇒ Client
constructor
Create a Prometheus Alert client:.
-
#post(alert) ⇒ Object
post alert:.
Constructor Details
#initialize(options = {}) ⇒ Client
Create a Prometheus Alert client:
A default client is created if options is omitted.
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/prometheus/alert_buffer_client/client.rb', line 37 def initialize( = {}) = DEFAULT_ARGS.merge() @client = Faraday.new( (), ) do |conn| conn.response(:json) conn.adapter(Faraday.default_adapter) end end |
Instance Method Details
#faraday_headers(options) ⇒ Object
Helper function to evalueate the low level headers option
95 96 97 98 99 100 101 102 103 104 |
# File 'lib/prometheus/alert_buffer_client/client.rb', line 95 def faraday_headers() return [:headers] if [:headers] headers = [:credentials] return unless headers && headers[:token] { Authorization: "Bearer #{headers[:token]}", } end |
#faraday_options(options) ⇒ Object
Helper function to create the args for the low level client
120 121 122 123 124 125 126 127 128 |
# File 'lib/prometheus/alert_buffer_client/client.rb', line 120 def () { url: [:url] + [:path], proxy: faraday_proxy(), ssl: faraday_ssl(), headers: faraday_headers(), request: faraday_request(), } end |
#faraday_proxy(options) ⇒ Object
Helper function to evalueate the low level proxy option
74 75 76 77 78 79 |
# File 'lib/prometheus/alert_buffer_client/client.rb', line 74 def faraday_proxy() return [:proxy] if [:proxy] proxy = [:options] proxy[:http_proxy_uri] if proxy[:http_proxy_uri] end |
#faraday_request(options) ⇒ Object
Helper function to evalueate the low level headers option
107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/prometheus/alert_buffer_client/client.rb', line 107 def faraday_request() return [:request] if [:request] request = [:options] return unless request[:open_timeout] || request[:timeout] { open_timeout: request[:open_timeout], timeout: request[:timeout], } end |
#faraday_ssl(options) ⇒ Object
Helper function to evalueate the low level ssl option
82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/prometheus/alert_buffer_client/client.rb', line 82 def faraday_ssl() return [:ssl] if [:ssl] ssl = [:options] return unless ssl[:verify_ssl] || ssl[:ssl_cert_store] { verify: ssl[:verify_ssl] != OpenSSL::SSL::VERIFY_NONE, cert_store: ssl[:ssl_cert_store], } end |
#get(options = {}) ⇒ Hash
Get alerts:
All alerts will be fetched if options are omitted.
56 57 58 59 60 61 62 63 |
# File 'lib/prometheus/alert_buffer_client/client.rb', line 56 def get( = {}) response = @client.get do |req| req.params['generationID'] = [:generation_id] req.params['fromIndex'] = [:from_index] end response.body end |
#post(alert) ⇒ Object
post alert:
67 68 69 70 71 |
# File 'lib/prometheus/alert_buffer_client/client.rb', line 67 def post(alert) @client.post do |req| req.body = alert end end |