Class: Hawkular::Alerts::Client
- Inherits:
-
BaseClient
- Object
- BaseClient
- Hawkular::Alerts::Client
- Defined in:
- lib/hawkular/alerts/alerts_api.rb
Overview
Interface to use to talk to the Hawkular-Alerts component.
Constant Summary
Constants inherited from BaseClient
BaseClient::HawkularConnectionException, BaseClient::HawkularException
Instance Attribute Summary
Attributes inherited from BaseClient
Instance Method Summary collapse
-
#acknowledge_alert(alert_id, by = nil, comment = nil) ⇒ Object
Mark one alert as acknowledged.
-
#add_tags(alert_ids, tags) ⇒ Object
Add tags to existing Alerts.
-
#alerts(criteria: {}, tenants: nil) ⇒ Array<Alert>
List fired alerts.
-
#bulk_import_triggers(hash) ⇒ Hash
Import multiple trigger or action definitions specified as a hash to the server.
-
#create_action(plugin, action_id, properties = {}) ⇒ Action
Creates the action.
-
#create_event(id, category, text, extras) ⇒ Object
Inject an event into Hawkular-alerts.
-
#create_group_dampening(dampening) ⇒ Dampening
Creates a dampening for a group trigger.
-
#create_group_trigger(trigger) ⇒ Trigger
Creates the group trigger definition.
-
#create_member_trigger(group_member_info) ⇒ Trigger
Creates a member trigger.
-
#create_trigger(trigger, conditions = [], dampenings = [], _actions = []) ⇒ Trigger
Creates the trigger definition.
-
#delete_action(plugin, action_id) ⇒ Object
Deletes the action of given action plugin.
- #delete_event(id) ⇒ Object
-
#delete_group_dampening(trigger_id, dampening_id) ⇒ Object
Deletes the dampening of a group trigger.
-
#delete_group_trigger(trigger_id) ⇒ Object
Deletes the group trigger definition.
-
#delete_trigger(trigger_id) ⇒ Object
Deletes the trigger definition.
-
#events(criteria: {}, tenants: nil) ⇒ Array<Event>
List Events given optional criteria.
-
#fetch_version_and_status ⇒ Hash{String=>String}
Return version and status information for the used version of Hawkular-Alerting.
-
#get_action(plugin, action_id) ⇒ Action
Obtains one action of given action plugin from the server.
-
#get_action_definition(action_plugin = nil) ⇒ Object
Obtains action definition/plugin from the server.
-
#get_alerts_for_trigger(trigger_id) ⇒ Array<Alert>
Obtain the alerts for the Trigger with the passed id.
-
#get_single_alert(alert_id) ⇒ Alert
Retrieve a single Alert by its id.
-
#get_single_trigger(trigger_id, full = false) ⇒ Trigger
Obtains one Trigger definition from the server.
-
#initialize(entrypoint, credentials = {}, options = {}) ⇒ Client
constructor
A new instance of Client.
-
#list_alerts(criteria = {}) ⇒ Array<Alert>
List fired alerts.
-
#list_events(criteria = {}) ⇒ Array<Event>
List Events given optional criteria.
-
#list_members(trigger_id, orphans = false) ⇒ Array<Trigger>
Lists members of a group trigger.
-
#list_triggers(ids = [], tags = []) ⇒ Array<Trigger>
Lists defined triggers in the system tags are of the format # key|value.
-
#orphan_member(trigger_id) ⇒ Trigger
Detaches a member trigger from its group trigger.
-
#remove_tags(alert_ids, tag_names) ⇒ Object
Remove tags from existing Alerts.
-
#resolve_alert(alert_id, by = nil, comment = nil) ⇒ Object
Mark one alert as resolved.
-
#set_group_conditions(trigger_id, trigger_mode, group_conditions_info) ⇒ Array<Condition>
Creates the group conditions definitions.
-
#update_group_dampening(dampening) ⇒ Dampening
Updates a dampening for a group trigger.
-
#update_group_trigger(trigger) ⇒ Trigger
Updates a given group trigger definition.
Methods inherited from BaseClient
#admin_header, #base_64_credentials, #generate_query_params, #http_delete, #http_get, #http_post, #http_put, #normalize_entrypoint_url, #now, #url, #url_with_websocket_scheme
Methods included from ClientUtils
Constructor Details
#initialize(entrypoint, credentials = {}, options = {}) ⇒ Client
Returns a new instance of Client.
17 18 19 20 21 22 |
# File 'lib/hawkular/alerts/alerts_api.rb', line 17 def initialize(entrypoint, credentials = {}, = {}) entrypoint = normalize_entrypoint_url entrypoint, 'hawkular/alerts' @entrypoint = entrypoint super(entrypoint, credentials, ) end |
Instance Method Details
#acknowledge_alert(alert_id, by = nil, comment = nil) ⇒ Object
Mark one alert as acknowledged
289 290 291 292 293 294 295 296 |
# File 'lib/hawkular/alerts/alerts_api.rb', line 289 def acknowledge_alert(alert_id, by = nil, comment = nil) sub_url = "/ack/#{alert_id}" query = generate_query_params 'ackBy' => by, 'ackNotes' => comment sub_url += query http_put(sub_url, {}) true end |
#add_tags(alert_ids, tags) ⇒ Object
Add tags to existing Alerts.
353 354 355 356 |
# File 'lib/hawkular/alerts/alerts_api.rb', line 353 def (alert_ids, ) query = generate_query_params(alertIds: alert_ids, tags: ) http_put('/tags' + query, {}) end |
#alerts(criteria: {}, tenants: nil) ⇒ Array<Alert>
List fired alerts
254 255 256 257 258 259 260 261 |
# File 'lib/hawkular/alerts/alerts_api.rb', line 254 def alerts(criteria: {}, tenants: nil) query = generate_query_params(criteria) uri = tenants ? '/admin/alerts/' : '/' ret = http_get(uri + query, multi_tenants_header(tenants)) val = [] ret.each { |a| val.push(Alert.new(a)) } val end |
#bulk_import_triggers(hash) ⇒ Hash
Import multiple trigger or action definitions specified as a hash to the server.
71 72 73 |
# File 'lib/hawkular/alerts/alerts_api.rb', line 71 def bulk_import_triggers(hash) http_post 'import/all', hash end |
#create_action(plugin, action_id, properties = {}) ⇒ Action
Creates the action.
198 199 200 201 202 203 204 205 206 |
# File 'lib/hawkular/alerts/alerts_api.rb', line 198 def create_action(plugin, action_id, properties = {}) the_plugin = hawk_escape plugin # Check if plugin exists http_get("/plugins/#{the_plugin}") payload = { actionId: action_id, actionPlugin: plugin, properties: properties } ret = http_post('/actions', payload) Trigger::Action.new(ret) end |
#create_event(id, category, text, extras) ⇒ Object
Inject an event into Hawkular-alerts
335 336 337 338 339 340 341 342 343 344 |
# File 'lib/hawkular/alerts/alerts_api.rb', line 335 def create_event(id, category, text, extras) event = {} event['id'] = id event['ctime'] = Time.now.to_i * 1000 event['category'] = category event['text'] = text event.merge!(extras) { |_key, v1, _v2| v1 } http_post('/events', event) end |
#create_group_dampening(dampening) ⇒ Dampening
Creates a dampening for a group trigger
150 151 152 153 |
# File 'lib/hawkular/alerts/alerts_api.rb', line 150 def create_group_dampening(dampening) ret = http_post "triggers/groups/#{dampening.trigger_id}/dampenings", dampening.to_h Trigger::Dampening.new(ret) end |
#create_group_trigger(trigger) ⇒ Trigger
Creates the group trigger definition.
96 97 98 99 |
# File 'lib/hawkular/alerts/alerts_api.rb', line 96 def create_group_trigger(trigger) ret = http_post 'triggers/groups', trigger.to_h Trigger.new(ret) end |
#create_member_trigger(group_member_info) ⇒ Trigger
Creates a member trigger
125 126 127 128 |
# File 'lib/hawkular/alerts/alerts_api.rb', line 125 def create_member_trigger(group_member_info) ret = http_post 'triggers/groups/members', group_member_info.to_h Trigger.new(ret) end |
#create_trigger(trigger, conditions = [], dampenings = [], _actions = []) ⇒ Trigger
Creates the trigger definition.
80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/hawkular/alerts/alerts_api.rb', line 80 def create_trigger(trigger, conditions = [], dampenings = [], _actions = []) full_trigger = {} full_trigger[:trigger] = trigger.to_h conds = [] conditions.each { |c| conds.push(c.to_h) } full_trigger[:conditions] = conds damps = [] dampenings.each { |d| damps.push(d.to_h) } unless dampenings.nil? full_trigger[:dampenings] = damps http_post 'triggers/trigger', full_trigger end |
#delete_action(plugin, action_id) ⇒ Object
Deletes the action of given action plugin.
222 223 224 225 226 |
# File 'lib/hawkular/alerts/alerts_api.rb', line 222 def delete_action(plugin, action_id) the_plugin = hawk_escape plugin the_action_id = hawk_escape action_id http_delete "/actions/#{the_plugin}/#{the_action_id}" end |
#delete_event(id) ⇒ Object
346 347 348 |
# File 'lib/hawkular/alerts/alerts_api.rb', line 346 def delete_event(id) http_delete "/events/#{id}" end |
#delete_group_dampening(trigger_id, dampening_id) ⇒ Object
Deletes the dampening of a group trigger
166 167 168 |
# File 'lib/hawkular/alerts/alerts_api.rb', line 166 def delete_group_dampening(trigger_id, dampening_id) http_delete "/triggers/groups/#{trigger_id}/dampenings/#{dampening_id}" end |
#delete_group_trigger(trigger_id) ⇒ Object
Deletes the group trigger definition.
178 179 180 |
# File 'lib/hawkular/alerts/alerts_api.rb', line 178 def delete_group_trigger(trigger_id) http_delete "/triggers/groups/#{trigger_id}" end |
#delete_trigger(trigger_id) ⇒ Object
Deletes the trigger definition.
172 173 174 |
# File 'lib/hawkular/alerts/alerts_api.rb', line 172 def delete_trigger(trigger_id) http_delete "/triggers/#{trigger_id}" end |
#events(criteria: {}, tenants: nil) ⇒ Array<Event>
List Events given optional criteria. Criteria keys are strings (not symbols):
startTime numeric, milliseconds from epoch
endTime numeric, milliseconds from epoch
eventIds array of strings
triggerIds array of strings
categories array of strings
array of strings, each tag of format 'name|value'. Specify '*' for value to match all values
thin boolean, return lighter events (omits triggering data for trigger-generated events)
324 325 326 327 328 |
# File 'lib/hawkular/alerts/alerts_api.rb', line 324 def events(criteria: {}, tenants: nil) query = generate_query_params(criteria) uri = tenants ? '/admin/events' : '/events' http_get(uri + query, multi_tenants_header(tenants)).map { |e| Event.new(e) } end |
#fetch_version_and_status ⇒ Hash{String=>String}
Return version and status information for the used version of Hawkular-Alerting
27 28 29 |
# File 'lib/hawkular/alerts/alerts_api.rb', line 27 def fetch_version_and_status http_get('/status') end |
#get_action(plugin, action_id) ⇒ Action
Obtains one action of given action plugin from the server.
212 213 214 215 216 217 |
# File 'lib/hawkular/alerts/alerts_api.rb', line 212 def get_action(plugin, action_id) the_plugin = hawk_escape plugin the_action_id = hawk_escape action_id ret = http_get "/actions/#{the_plugin}/#{the_action_id}" Trigger::Action.new(ret) end |
#get_action_definition(action_plugin = nil) ⇒ Object
Obtains action definition/plugin from the server.
184 185 186 187 188 189 190 191 |
# File 'lib/hawkular/alerts/alerts_api.rb', line 184 def get_action_definition(action_plugin = nil) plugins = action_plugin.nil? ? http_get('plugins') : [action_plugin] ret = {} plugins.each do |p| ret[p] = http_get("/plugins/#{p}") end ret end |
#get_alerts_for_trigger(trigger_id) ⇒ Array<Alert>
Obtain the alerts for the Trigger with the passed id
231 232 233 234 235 236 237 238 239 240 |
# File 'lib/hawkular/alerts/alerts_api.rb', line 231 def get_alerts_for_trigger(trigger_id) # TODO: add additional filters return [] unless trigger_id url = '/?triggerIds=' + trigger_id ret = http_get(url) val = [] ret.each { |a| val.push(Alert.new(a)) } val end |
#get_single_alert(alert_id) ⇒ Alert
Retrieve a single Alert by its id
266 267 268 269 270 |
# File 'lib/hawkular/alerts/alerts_api.rb', line 266 def get_single_alert(alert_id) ret = http_get('/alert/' + alert_id) val = Alert.new(ret) val end |
#get_single_trigger(trigger_id, full = false) ⇒ Trigger
Obtains one Trigger definition from the server.
52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/hawkular/alerts/alerts_api.rb', line 52 def get_single_trigger(trigger_id, full = false) the_trigger = '/triggers/' + trigger_id ret = http_get(the_trigger) trigger = Trigger.new(ret) if full ret = http_get(the_trigger + '/conditions') ret.each { |c| trigger.conditions.push(Trigger::Condition.new(c)) } ret = http_get(the_trigger + '/dampenings') ret.each { |c| trigger.dampenings.push(Trigger::Dampening.new(c)) } end trigger end |
#list_alerts(criteria = {}) ⇒ Array<Alert>
List fired alerts
245 246 247 |
# File 'lib/hawkular/alerts/alerts_api.rb', line 245 def list_alerts(criteria = {}) alerts(criteria: criteria) end |
#list_events(criteria = {}) ⇒ Array<Event>
List Events given optional criteria. Criteria keys are strings (not symbols):
startTime numeric, milliseconds from epoch
endTime numeric, milliseconds from epoch
eventIds array of strings
triggerIds array of strings
categories array of strings
array of strings, each tag of format 'name|value'. Specify '*' for value to match all values
thin boolean, return lighter events (omits triggering data for trigger-generated events)
308 309 310 |
# File 'lib/hawkular/alerts/alerts_api.rb', line 308 def list_events(criteria = {}) events(criteria: criteria) end |
#list_members(trigger_id, orphans = false) ⇒ Array<Trigger>
Lists members of a group trigger
142 143 144 145 |
# File 'lib/hawkular/alerts/alerts_api.rb', line 142 def list_members(trigger_id, orphans = false) ret = http_get "triggers/groups/#{trigger_id}/members?includeOrphans=#{orphans}" ret.collect { |t| Trigger.new(t) } end |
#list_triggers(ids = [], tags = []) ⇒ Array<Trigger>
Lists defined triggers in the system tags are of the format # key|value. Tags are OR’d together. If a tag-key shows up more than once, only the last one is accepted
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/hawkular/alerts/alerts_api.rb', line 37 def list_triggers(ids = [], = []) query = generate_query_params 'triggerIds' => ids, 'tags' => sub_url = '/triggers' + query ret = http_get(sub_url) val = [] ret.each { |t| val.push(Trigger.new(t)) } val end |
#orphan_member(trigger_id) ⇒ Trigger
Detaches a member trigger from its group trigger
133 134 135 136 |
# File 'lib/hawkular/alerts/alerts_api.rb', line 133 def orphan_member(trigger_id) http_post "triggers/groups/members/#{trigger_id}/orphan", {} get_single_trigger trigger_id, false end |
#remove_tags(alert_ids, tag_names) ⇒ Object
Remove tags from existing Alerts.
361 362 363 364 |
# File 'lib/hawkular/alerts/alerts_api.rb', line 361 def (alert_ids, tag_names) query = generate_query_params(alertIds: alert_ids, tagNames: tag_names) http_delete('/tags' + query) end |
#resolve_alert(alert_id, by = nil, comment = nil) ⇒ Object
Mark one alert as resolved
276 277 278 279 280 281 282 283 |
# File 'lib/hawkular/alerts/alerts_api.rb', line 276 def resolve_alert(alert_id, by = nil, comment = nil) sub_url = "/resolve/#{alert_id}" query = generate_query_params 'resolvedBy' => by, 'resolvedNotes' => comment sub_url += query http_put(sub_url, {}) true end |
#set_group_conditions(trigger_id, trigger_mode, group_conditions_info) ⇒ Array<Condition>
Creates the group conditions definitions.
115 116 117 118 119 120 |
# File 'lib/hawkular/alerts/alerts_api.rb', line 115 def set_group_conditions(trigger_id, trigger_mode, group_conditions_info) ret = http_put "triggers/groups/#{trigger_id}/conditions/#{trigger_mode}", group_conditions_info.to_h conditions = [] ret.each { |c| conditions.push(Trigger::Condition.new(c)) } conditions end |
#update_group_dampening(dampening) ⇒ Dampening
Updates a dampening for a group trigger
158 159 160 161 |
# File 'lib/hawkular/alerts/alerts_api.rb', line 158 def update_group_dampening(dampening) ret = http_put "triggers/groups/#{dampening.trigger_id}/dampenings/#{dampening.dampening_id}", dampening.to_h Trigger::Dampening.new(ret) end |
#update_group_trigger(trigger) ⇒ Trigger
Updates a given group trigger definition
104 105 106 107 |
# File 'lib/hawkular/alerts/alerts_api.rb', line 104 def update_group_trigger(trigger) http_put "triggers/groups/#{trigger.id}/", trigger.to_h get_single_trigger trigger.id, false end |