hawkular-client 2.1.0 → 2.2.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 +4 -4
- data/.rubocop.yml +2 -0
- data/CHANGES.rdoc +13 -0
- data/README.rdoc +94 -2
- data/hawkularclient.gemspec +1 -0
- data/lib/hawkular/alerts/alerts_api.rb +7 -3
- data/lib/hawkular/base_client.rb +22 -0
- data/lib/hawkular/hawkular_client.rb +1 -1
- data/lib/hawkular/inventory/inventory_api.rb +18 -1
- data/lib/hawkular/metrics/metric_api.rb +39 -3
- data/lib/hawkular/metrics/metrics_client.rb +2 -2
- data/lib/hawkular/operations/operations_api.rb +1 -1
- data/lib/hawkular/tokens/tokens_api.rb +1 -1
- data/lib/hawkular/version.rb +1 -1
- data/spec/integration/alerts_spec.rb +41 -1
- data/spec/integration/hawkular_client_spec.rb +12 -4
- data/spec/integration/inventory_spec.rb +10 -3
- data/spec/integration/metric_spec.rb +82 -0
- data/spec/integration/operations_spec.rb +6 -1
- data/spec/spec_helper.rb +17 -0
- data/spec/unit/base_spec.rb +56 -1
- data/spec/unit/client_spec.rb +5 -12
- data/spec/vcr_cassettes/Alert/Triggers/Should_create_a_firing_ALL_ANY_trigger.yml +463 -0
- data/spec/vcr_cassettes/Availability_metrics/Should_group_contiguous_values.yml +93 -0
- data/spec/vcr_cassettes/Mixed_metrics/Should_requests_raw_data_for_multiple_metrics.yml +330 -0
- metadata +25 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b9461b58571db98a5be62adf87a4b0eecb7e817f
|
4
|
+
data.tar.gz: 3aa940779ef467732f5d1176a06be0194341f1d7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 07a86f9b9b326c22dabfa8dc746a45bf5db6c3483643b85bac616bf904e07bca3f256cf97c4c8a8b2ecedbe709b1e8d2e7c62f5727ebd37633377378f614eca0
|
7
|
+
data.tar.gz: 0582a5844edf3bc3657f8a6e56d133b2704fa8c4b5446aceb0372b1a5852b3aeb766e4e9628d46bc5018dff3d0f283bbeaa8aaf1edc09ba9d0f476a0297d153f
|
data/.rubocop.yml
CHANGED
data/CHANGES.rdoc
CHANGED
@@ -3,6 +3,19 @@
|
|
3
3
|
This document describes the relevant changes between releases of the
|
4
4
|
_hawkular-client_ project.
|
5
5
|
|
6
|
+
=== V 2.2.0
|
7
|
+
|
8
|
+
This release is needed to work with hawkular-services v0.0.5+
|
9
|
+
|
10
|
+
* Support the changed api endpoint (/deprecated) for Hawkular-inventory 0.17+ along the old version
|
11
|
+
* Add two missing fields (firing_match and auto_resolve) on Alert-triggers
|
12
|
+
* Add distinct parameter when getting availability data points
|
13
|
+
* Remove all defaulting/fallback to localhost:8080 in the APIs
|
14
|
+
* Allow to fetch multiple raw data items from Hawkular-metrics in one call. Requires Metrics v0.17+
|
15
|
+
* Corectly use the enabled flag for deployment operations
|
16
|
+
|
17
|
+
Full list of items can be found at https://github.com/hawkular/hawkular-client-ruby/issues?q=milestone%3A2.2.0+is%3Aclosed
|
18
|
+
|
6
19
|
=== V 2.1.0
|
7
20
|
* Fix an issue where the operations endpoint constructor expected a host to be passed, which was not.
|
8
21
|
* Add authentication to the websocket setup in Operations sub-client.
|
data/README.rdoc
CHANGED
@@ -10,9 +10,101 @@ Documentation[http://www.hawkular.org/hawkular-client-ruby/]
|
|
10
10
|
|
11
11
|
== Changelog
|
12
12
|
|
13
|
-
See {CHANGELOG}[link:file.CHANGES.html] for a list of changes and
|
13
|
+
See {CHANGELOG}[link:file.CHANGES.html] for a list of changes and
|
14
14
|
{API-Breaking-Changes}[link:file.api_breaking_changes.html] for a list of api-breaking changes.
|
15
15
|
|
16
|
+
== Overview
|
17
|
+
|
18
|
+
Ruby Hawkular Client provides a Ruby API to communicate with the following Hawkular subprojects:
|
19
|
+
* {Hawkular Alerts}[https://github.com/hawkular/hawkular-alerts]
|
20
|
+
* {Hawkular Inventory}[https://github.com/hawkular/hawkular-inventory]
|
21
|
+
* {Hawkular Metrics}[https://github.com/hawkular/hawkular-metrics]
|
22
|
+
* Invoking operations on {Hawkular Wildfly Agent}[https://github.com/hawkular/hawkular-agent].
|
23
|
+
|
24
|
+
|
25
|
+
== Usage
|
26
|
+
|
27
|
+
You must initialize the Hawkular Client with the server url, your username, password and tenant.
|
28
|
+
|
29
|
+
require 'hawkular/hawkular_client'
|
30
|
+
client = Hawkular::Client.new(
|
31
|
+
entrypoint: 'http://localhost:8080',
|
32
|
+
credentials: { username: 'jdoe', password: 'password' },
|
33
|
+
options: { tenant: 'hawkular' }
|
34
|
+
)
|
35
|
+
|
36
|
+
Each subproject API is packed in its own class, which you can access through the client object.
|
37
|
+
|
38
|
+
client.alerts # Alerts API
|
39
|
+
client.inventory # Inventory API
|
40
|
+
client.metrics # Metrics API
|
41
|
+
client.operations # Operations API
|
42
|
+
|
43
|
+
Metrics API is also subdivided to: Mixed, Availability, Counters, Gauges and Tenants.
|
44
|
+
|
45
|
+
client.metrics # Mixed API
|
46
|
+
client.metrics.avail # Availability
|
47
|
+
client.metrics.counters # Counters
|
48
|
+
client.metrics.gauges # Gauges
|
49
|
+
client.metrics.tenants # Tenants
|
50
|
+
|
51
|
+
The Mixed API is capable of handling multiple types of metrics, like the
|
52
|
+
push_data[Hawkular/Metrics/Client.html#push_data-instance_method] method, which pushes data
|
53
|
+
for multiple metrics of all supported data.
|
54
|
+
|
55
|
+
You can also access each subproject's API individually, if you would like to use only the metrics API you could do
|
56
|
+
|
57
|
+
require 'hawkular/metrics/metrics_client'
|
58
|
+
metrics_client = Hawkular::Metrics::Client.new(
|
59
|
+
entrypoint: 'http://localhost:8080/hawkular/metrics',
|
60
|
+
credentials: { username: 'jdoe', password: 'password' },
|
61
|
+
options: { tenant: 'hawkular' }
|
62
|
+
)
|
63
|
+
|
64
|
+
=== Examples
|
65
|
+
|
66
|
+
Suppose you will monitor the availability of two networks to later determine which one is the best.
|
67
|
+
Every certain time, you would get the availability of each network and push them to Hawkular Metrics.
|
68
|
+
|
69
|
+
# ... Initialize client ...
|
70
|
+
is_network01_available = true
|
71
|
+
is_network02_available = false
|
72
|
+
client.metrics.push_data(availabilities: [
|
73
|
+
{ id: 'network-01', data: [{ value: is_network01_available ? 'up' : 'down' }] },
|
74
|
+
{ id: 'network-02', data: [{ value: is_network02_available ? 'up' : 'down' }] }
|
75
|
+
])
|
76
|
+
|
77
|
+
At some other point you might want to access that data to analyze it
|
78
|
+
|
79
|
+
# ... Initialize client ...
|
80
|
+
# Fetches the 5 last availabilities reported in the last 8 hours.
|
81
|
+
network01_avail = client.metrics.avail.get_data('network-01', limit: 5, order: 'DESC')
|
82
|
+
network02_avail = client.metrics.avail.get_data('network-02', limit: 5, order: 'DESC')
|
83
|
+
# ... Do something with the availabilities ...
|
84
|
+
|
85
|
+
Each network01_avail will be an array like:
|
86
|
+
|
87
|
+
[
|
88
|
+
{ "timestamp" => 1467312571473, "value" => "up" },
|
89
|
+
{ "timestamp" => 1467312492650, "value" => "up" },
|
90
|
+
# ...
|
91
|
+
]
|
92
|
+
|
93
|
+
You can get more info on the other parameters by checking the metrics API get_data[Hawkular/Metrics/Client/Metrics#get_data-instance_method]
|
94
|
+
|
95
|
+
=== More info
|
96
|
+
|
97
|
+
Check each resource API for a detailed description of what methods are available.
|
98
|
+
* Alerts[Hawkular/Alerts/AlertsClient.html]
|
99
|
+
* Inventory[Hawkular/Inventory/InventoryClient.html]
|
100
|
+
* Metrics:
|
101
|
+
* Mixed[Hawkular/Metrics/Client.html]
|
102
|
+
* Availability[Hawkular/Metrics/Client/Availability.html]
|
103
|
+
* Counters[Hawkular/Metrics/Client/Counters.html]
|
104
|
+
* Gauges[Hawkular/Metrics/Client/Gauges.html]
|
105
|
+
* Tenants[Hawkular/Metrics/Client/Tenants.html]
|
106
|
+
* Operations[Hawkular/Operations/OperationsClient.html]
|
107
|
+
|
16
108
|
== Contributing to hawkular-client-ruby
|
17
109
|
|
18
110
|
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
@@ -20,7 +112,7 @@ See {CHANGELOG}[link:file.CHANGES.html] for a list of changes and
|
|
20
112
|
* Fork the project
|
21
113
|
* Start a feature/bugfix branch
|
22
114
|
* Commit and push until you are happy with your contribution
|
23
|
-
* Make sure to add tests for it. This is important so
|
115
|
+
* Make sure to add tests for it. This is important so it won't break in a future version unintentionally.
|
24
116
|
* Run your code through RuboCop (which is default when running +rake+) and fix complaints.
|
25
117
|
* When you open a pull request, watch out for failures on Travis.
|
26
118
|
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is
|
data/hawkularclient.gemspec
CHANGED
@@ -33,6 +33,7 @@ Gem::Specification.new do |gem|
|
|
33
33
|
gem.add_development_dependency('vcr')
|
34
34
|
gem.add_development_dependency('rubocop', '= 0.34.2')
|
35
35
|
gem.add_development_dependency('coveralls')
|
36
|
+
gem.add_development_dependency('rack', '~> 1.6.4')
|
36
37
|
|
37
38
|
gem.rdoc_options << '--title' << gem.name <<
|
38
39
|
'--main' << 'README.rdoc' << '--line-numbers' << '--inline-source'
|
@@ -14,7 +14,8 @@ module Hawkular::Alerts
|
|
14
14
|
# @param credentials [Hash{String=>String}] Hash of username, password, token(optional)
|
15
15
|
# @param options [Hash{String=>String}] Additional rest client options
|
16
16
|
class AlertsClient < Hawkular::BaseClient
|
17
|
-
def initialize(entrypoint
|
17
|
+
def initialize(entrypoint, credentials = {}, options = {})
|
18
|
+
entrypoint = normalize_entrypoint_url entrypoint, 'hawkular/alerts'
|
18
19
|
@entrypoint = entrypoint
|
19
20
|
|
20
21
|
super(entrypoint, credentials, options)
|
@@ -329,7 +330,7 @@ module Hawkular::Alerts
|
|
329
330
|
attr_accessor :auto_resolve, :auto_resolve_alerts, :tags, :type
|
330
331
|
attr_accessor :tenant, :description, :group, :severity, :event_type, :event_category, :member_of, :data_id_map
|
331
332
|
attr_reader :conditions, :dampenings
|
332
|
-
attr_accessor :enabled, :actions
|
333
|
+
attr_accessor :enabled, :actions, :firing_match, :auto_resolve_match
|
333
334
|
|
334
335
|
def initialize(trigger_hash)
|
335
336
|
return if trigger_hash.nil?
|
@@ -355,6 +356,8 @@ module Hawkular::Alerts
|
|
355
356
|
@context = trigger_hash['context']
|
356
357
|
@type = trigger_hash['type']
|
357
358
|
@tags = trigger_hash['tags']
|
359
|
+
@firing_match = trigger_hash['firingMatch']
|
360
|
+
@auto_resolve_match = trigger_hash['autoResolveMatch']
|
358
361
|
# acts = trigger_hash['actions']
|
359
362
|
# acts.each { |a| @actions.push(Action.new(a)) } unless acts.nil?
|
360
363
|
end
|
@@ -366,7 +369,8 @@ module Hawkular::Alerts
|
|
366
369
|
ret[0, 1].downcase + ret[1..-1]
|
367
370
|
end
|
368
371
|
fields = [:id, :name, :enabled, :severity, :auto_resolve, :auto_resolve_alerts, :event_type, :event_category,
|
369
|
-
:description, :auto_enable, :auto_disable, :context, :type, :tags, :member_of, :data_id_map
|
372
|
+
:description, :auto_enable, :auto_disable, :context, :type, :tags, :member_of, :data_id_map,
|
373
|
+
:firing_match, :auto_resolve_match]
|
370
374
|
|
371
375
|
fields.each do |field|
|
372
376
|
camelized_field = to_camel.call(field)
|
data/lib/hawkular/base_client.rb
CHANGED
@@ -127,6 +127,28 @@ module Hawkular
|
|
127
127
|
end
|
128
128
|
end
|
129
129
|
|
130
|
+
# Generate a new url with the passed sufix path if the path is not already added
|
131
|
+
# also, this function always remove the slash at the end of the URL, so if your entrypoint is
|
132
|
+
# http://localhost/hawkular/inventory/ this function will return http://localhost/hawkular/inventory
|
133
|
+
# to the URL
|
134
|
+
# @param entrypoint [String] base path
|
135
|
+
# @param suffix_path [String] sufix path to be added if it doesn't exist
|
136
|
+
# @return [String] URL with path attached to it at the end
|
137
|
+
def normalize_entrypoint_url(entrypoint, suffix_path)
|
138
|
+
strip_path = suffix_path.gsub(%r{/$}, '')
|
139
|
+
strip_path.nil? || suffix_path = strip_path
|
140
|
+
strip_path = suffix_path.gsub(%r{^/}, '')
|
141
|
+
strip_path.nil? || suffix_path = strip_path
|
142
|
+
strip_entrypoint = entrypoint.gsub(%r{/$}, '')
|
143
|
+
strip_path.nil? && strip_entrypoint = entrypoint
|
144
|
+
relative_path_rgx = Regexp.new("\/#{Regexp.quote(suffix_path)}(\/)*$")
|
145
|
+
if relative_path_rgx.match(entrypoint)
|
146
|
+
strip_entrypoint
|
147
|
+
else
|
148
|
+
"#{strip_entrypoint}/#{suffix_path}"
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
130
152
|
# Specialized exception to be thrown
|
131
153
|
# when the interaction with Hawkular fails
|
132
154
|
class HawkularException < StandardError
|
@@ -10,9 +10,9 @@ module Hawkular
|
|
10
10
|
attr_reader :inventory, :metrics, :alerts, :operations, :tokens, :state
|
11
11
|
|
12
12
|
def initialize(hash)
|
13
|
-
hash[:entrypoint] ||= 'http://localhost:8080'
|
14
13
|
hash[:credentials] ||= {}
|
15
14
|
hash[:options] ||= {}
|
15
|
+
fail 'no parameter ":entrypoint" given' if hash[:entrypoint].nil?
|
16
16
|
@state = hash
|
17
17
|
|
18
18
|
@inventory = Inventory::InventoryClient.create(entrypoint: "#{hash[:entrypoint]}/hawkular/inventory",
|
@@ -16,8 +16,25 @@ module Hawkular::Inventory
|
|
16
16
|
# @param credentials [Hash{String=>String}] Hash of username, password, token(optional)
|
17
17
|
# @param options [Hash{String=>String}] Additional rest client options
|
18
18
|
def initialize(entrypoint = nil, credentials = {}, options = {})
|
19
|
+
entrypoint = normalize_entrypoint_url entrypoint, 'hawkular/inventory'
|
19
20
|
@entrypoint = entrypoint
|
20
21
|
super(entrypoint, credentials, options)
|
22
|
+
version = fetch_version_and_status['Implementation-Version']
|
23
|
+
major, minor = version.scan(/\d+/).map(&:to_i)
|
24
|
+
@entrypoint << '/deprecated' unless major == 0 && minor < 17
|
25
|
+
end
|
26
|
+
|
27
|
+
def fetch_version_and_status
|
28
|
+
if @entrypoint.end_with? '/deprecated'
|
29
|
+
begin
|
30
|
+
backup_entrypoint = @entrypoint
|
31
|
+
@entrypoint = @entrypoint[0...-'/deprecated'.size]
|
32
|
+
return http_get('/status')
|
33
|
+
ensure
|
34
|
+
@entrypoint = backup_entrypoint
|
35
|
+
end
|
36
|
+
end
|
37
|
+
http_get('/status')
|
21
38
|
end
|
22
39
|
|
23
40
|
# Creates a new Inventory Client
|
@@ -25,7 +42,7 @@ module Hawkular::Inventory
|
|
25
42
|
# entrypoint: http://localhost:8080/hawkular/inventory
|
26
43
|
# and another sub-hash containing the hash with username[String], password[String], token(optional)
|
27
44
|
def self.create(hash)
|
28
|
-
hash[:entrypoint]
|
45
|
+
fail 'no parameter ":entrypoint" given' if hash[:entrypoint].nil?
|
29
46
|
hash[:credentials] ||= {}
|
30
47
|
hash[:options] ||= {}
|
31
48
|
InventoryClient.new(hash[:entrypoint], hash[:credentials], hash[:options])
|
@@ -124,9 +124,19 @@ module Hawkular::Metrics
|
|
124
124
|
order: nil)
|
125
125
|
params = { start: starts, end: ends, bucketDuration: bucketDuration, buckets: buckets,
|
126
126
|
percentiles: percentiles, limit: limit, order: order }
|
127
|
-
|
128
|
-
|
129
|
-
|
127
|
+
get_data_helper(id, params)
|
128
|
+
end
|
129
|
+
|
130
|
+
# Retrieve raw data for multiple metrics.
|
131
|
+
# @param ids [Array[String]] metric definition ids
|
132
|
+
# @param starts [Integer] optional timestamp (default now - 8h)
|
133
|
+
# @param ends [Integer] optional timestamp (default now)
|
134
|
+
# @param limit [Integer] optional limit the number of data points returned
|
135
|
+
# @param order [String] optional Data point sort order, based on timestamp (ASC, DESC)
|
136
|
+
# @return [Array[Hash]] named datapoints
|
137
|
+
def raw_data(ids, starts: nil, ends: nil, limit: nil, order: nil)
|
138
|
+
params = { ids: ids, start: starts, end: ends, limit: limit, order: order }
|
139
|
+
@client.http_post("/#{@resource}/raw/query", params)
|
130
140
|
end
|
131
141
|
|
132
142
|
# Retrieve metric datapoints by tags
|
@@ -150,6 +160,14 @@ module Hawkular::Metrics
|
|
150
160
|
def encode_params(params)
|
151
161
|
URI.encode_www_form(params.select { |_k, v| !v.nil? })
|
152
162
|
end
|
163
|
+
|
164
|
+
private
|
165
|
+
|
166
|
+
def get_data_helper(id, params)
|
167
|
+
resp = @client.http_get("/#{@resource}/#{ERB::Util.url_encode(id)}/data/?" +
|
168
|
+
encode_params(params))
|
169
|
+
resp.is_a?(Array) ? resp : [] # API returns no content (empty Hash) instead of empty array
|
170
|
+
end
|
153
171
|
end
|
154
172
|
|
155
173
|
# Class that interacts with "gauge" metric types
|
@@ -204,6 +222,24 @@ module Hawkular::Metrics
|
|
204
222
|
def initialize(client)
|
205
223
|
super(client, 'availability', 'availability')
|
206
224
|
end
|
225
|
+
|
226
|
+
# Retrieve metric datapoints
|
227
|
+
# @param id [String] metric definition id
|
228
|
+
# @param starts [Integer] optional timestamp (default now - 8h)
|
229
|
+
# @param ends [Integer] optional timestamp (default now)
|
230
|
+
# @param buckets [Integer] optional desired number of buckets over the specified timerange
|
231
|
+
# @param bucketDuration [String] optional interval (default no aggregation)
|
232
|
+
# @param distinct [String] optional set to true to return only distinct, contiguous values
|
233
|
+
# @param limit [Integer] optional limit the number of data points returned
|
234
|
+
# @param order [String] optional Data point sort order, based on timestamp (ASC, DESC)
|
235
|
+
# @return [Array[Hash]] datapoints
|
236
|
+
# @see #push_data #push_data for datapoint detail
|
237
|
+
def get_data(id, starts: nil, ends: nil, bucketDuration: nil, buckets: nil, distinct: nil, limit: nil,
|
238
|
+
order: nil)
|
239
|
+
params = { start: starts, end: ends, bucketDuration: bucketDuration, buckets: buckets,
|
240
|
+
distinct: distinct, limit: limit, order: order }
|
241
|
+
get_data_helper(id, params)
|
242
|
+
end
|
207
243
|
end
|
208
244
|
end
|
209
245
|
end
|
@@ -38,10 +38,10 @@ module Hawkular::Metrics
|
|
38
38
|
# {username:"username",password:"password"},
|
39
39
|
# {"tenant" => "your tenant ID"})
|
40
40
|
#
|
41
|
-
def initialize(entrypoint
|
41
|
+
def initialize(entrypoint,
|
42
42
|
credentials = {},
|
43
43
|
options = {})
|
44
|
-
|
44
|
+
entrypoint = normalize_entrypoint_url entrypoint, 'hawkular/metrics'
|
45
45
|
super(entrypoint, credentials, options)
|
46
46
|
@tenants = Client::Tenants.new self
|
47
47
|
@counters = Client::Counters.new self
|
@@ -134,7 +134,7 @@ module Hawkular::Operations
|
|
134
134
|
#
|
135
135
|
# @param callback [Block] callback that is run after the operation is done
|
136
136
|
def add_deployment(hash, &callback)
|
137
|
-
hash[:enabled]
|
137
|
+
hash[:enabled] = hash.key?(:enabled) ? hash[:enabled] : true
|
138
138
|
required = [:resource_path, :destination_file_name, :binary_content]
|
139
139
|
check_pre_conditions hash, required, &callback
|
140
140
|
|
@@ -8,7 +8,7 @@ module Hawkular::Token
|
|
8
8
|
# @param entrypoint [String] base url of Hawkular - e.g http://localhost:8080
|
9
9
|
# @param credentials [Hash{String=>String}] Hash of username, password
|
10
10
|
# @param options [Hash{String=>String}] Additional rest client options
|
11
|
-
def initialize(entrypoint
|
11
|
+
def initialize(entrypoint, credentials = {}, options = {})
|
12
12
|
super(entrypoint, credentials, options)
|
13
13
|
end
|
14
14
|
|
data/lib/hawkular/version.rb
CHANGED
@@ -4,10 +4,11 @@ require "#{File.dirname(__FILE__)}/../spec_helper"
|
|
4
4
|
module Hawkular::Alerts::RSpec
|
5
5
|
ALERTS_BASE = 'http://localhost:8080/hawkular/alerts'
|
6
6
|
creds = { username: 'jdoe', password: 'password' }
|
7
|
+
options = { tenant: 'hawkular' }
|
7
8
|
|
8
9
|
describe 'Alert/Triggers', vcr: { decode_compressed_response: true } do
|
9
10
|
before(:each) do
|
10
|
-
@client = Hawkular::Alerts::AlertsClient.new(ALERTS_BASE, creds)
|
11
|
+
@client = Hawkular::Alerts::AlertsClient.new(ALERTS_BASE, creds, options)
|
11
12
|
end
|
12
13
|
|
13
14
|
it 'Should List Triggers' do
|
@@ -115,6 +116,45 @@ module Hawkular::Alerts::RSpec
|
|
115
116
|
end
|
116
117
|
end
|
117
118
|
|
119
|
+
it 'Should create a firing ALL_ANY trigger' do
|
120
|
+
# Create the trigger
|
121
|
+
t = Hawkular::Alerts::Trigger.new({})
|
122
|
+
t.enabled = true
|
123
|
+
t.id = 'my-cool-trigger'
|
124
|
+
t.name = 'Just a trigger'
|
125
|
+
t.severity = :HIGH
|
126
|
+
t.description = 'Just a test trigger'
|
127
|
+
|
128
|
+
begin
|
129
|
+
ft = @client.create_trigger t, [], nil
|
130
|
+
expect(ft).not_to be_nil
|
131
|
+
|
132
|
+
trigger = @client.get_single_trigger t.id, true
|
133
|
+
expect(trigger.firing_match).to eq('ALL')
|
134
|
+
expect(trigger.auto_resolve_match).to eq('ALL')
|
135
|
+
|
136
|
+
@client.delete_trigger(t.id)
|
137
|
+
|
138
|
+
t.firing_match = :ANY
|
139
|
+
t.auto_resolve_match = :ANY
|
140
|
+
|
141
|
+
ft = @client.create_trigger t, [], nil
|
142
|
+
expect(ft).not_to be_nil
|
143
|
+
|
144
|
+
trigger = @client.get_single_trigger t.id, true
|
145
|
+
expect(trigger.firing_match).to eq('ANY')
|
146
|
+
expect(trigger.auto_resolve_match).to eq('ANY')
|
147
|
+
ensure
|
148
|
+
# rubocop:disable Lint/HandleExceptions
|
149
|
+
begin
|
150
|
+
@client.delete_trigger(t.id)
|
151
|
+
rescue
|
152
|
+
# I am not interested
|
153
|
+
end
|
154
|
+
# rubocop:enable Lint/HandleExceptions
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
118
158
|
it 'Should get the action definitions' do
|
119
159
|
ret = @client.get_action_definition
|
120
160
|
expect(ret.size).to be(2)
|
@@ -4,13 +4,18 @@ require 'securerandom'
|
|
4
4
|
|
5
5
|
# examples that tests the main client which delegates all the calls to Hawkular component clients
|
6
6
|
module Hawkular::Client::RSpec
|
7
|
+
HOST = 'http://localhost:8080'
|
8
|
+
|
7
9
|
describe 'HawkularClient' do
|
8
10
|
before(:all) do
|
9
11
|
@creds = {
|
10
12
|
username: 'jdoe',
|
11
13
|
password: 'password'
|
12
14
|
}
|
13
|
-
|
15
|
+
::RSpec::Mocks.with_temporary_scope do
|
16
|
+
mock_inventory_client
|
17
|
+
@hawkular_client = Hawkular::Client.new(entrypoint: HOST, credentials: @creds)
|
18
|
+
end
|
14
19
|
@state = {
|
15
20
|
hostname: 'localhost.localdomain',
|
16
21
|
feed: nil
|
@@ -28,7 +33,10 @@ module Hawkular::Client::RSpec
|
|
28
33
|
|
29
34
|
context 'and Inventory client', vcr: { decode_compressed_response: true } do
|
30
35
|
before(:all) do
|
31
|
-
|
36
|
+
::RSpec::Mocks.with_temporary_scope do
|
37
|
+
mock_inventory_client
|
38
|
+
@client = Hawkular::Inventory::InventoryClient.create(entrypoint: HOST, credentials: @creds)
|
39
|
+
end
|
32
40
|
end
|
33
41
|
|
34
42
|
it 'Should list the same feeds' do
|
@@ -93,7 +101,7 @@ module Hawkular::Client::RSpec
|
|
93
101
|
include Hawkular::Metrics::RSpec
|
94
102
|
|
95
103
|
before(:all) do
|
96
|
-
@client = Hawkular::Metrics::Client.new(
|
104
|
+
@client = Hawkular::Metrics::Client.new(HOST, @creds)
|
97
105
|
end
|
98
106
|
|
99
107
|
it 'Should both work the same way when pushing metric data to non-existing counter' do
|
@@ -188,7 +196,7 @@ module Hawkular::Client::RSpec
|
|
188
196
|
}
|
189
197
|
|
190
198
|
actual_data = {}
|
191
|
-
client = Hawkular::Operations::OperationsClient.new(entrypoint:
|
199
|
+
client = Hawkular::Operations::OperationsClient.new(entrypoint: HOST, credentials: @creds)
|
192
200
|
client.invoke_generic_operation(redeploy) do |on|
|
193
201
|
on.success do |data|
|
194
202
|
actual_data[:data] = data
|