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.
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_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
292 293 294 295 296 297 298 299 |
# File 'lib/hawkular/alerts/alerts_api.rb', line 292 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.
356 357 358 359 |
# File 'lib/hawkular/alerts/alerts_api.rb', line 356 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
257 258 259 260 261 262 263 264 |
# File 'lib/hawkular/alerts/alerts_api.rb', line 257 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.
202 203 204 205 206 207 208 209 210 |
# File 'lib/hawkular/alerts/alerts_api.rb', line 202 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
338 339 340 341 342 343 344 345 346 347 |
# File 'lib/hawkular/alerts/alerts_api.rb', line 338 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.
226 227 228 229 230 |
# File 'lib/hawkular/alerts/alerts_api.rb', line 226 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
349 350 351 |
# File 'lib/hawkular/alerts/alerts_api.rb', line 349 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
tags 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)
327 328 329 330 331 |
# File 'lib/hawkular/alerts/alerts_api.rb', line 327 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.
216 217 218 219 220 221 |
# File 'lib/hawkular/alerts/alerts_api.rb', line 216 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 192 193 194 195 |
# File 'lib/hawkular/alerts/alerts_api.rb', line 184 def get_action_definition(action_plugin = nil) if action_plugin.nil? plugins = http_get('plugins') else plugins = [action_plugin] end 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
235 236 237 238 239 240 241 242 243 |
# File 'lib/hawkular/alerts/alerts_api.rb', line 235 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
269 270 271 272 273 |
# File 'lib/hawkular/alerts/alerts_api.rb', line 269 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
248 249 250 |
# File 'lib/hawkular/alerts/alerts_api.rb', line 248 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
tags 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)
311 312 313 |
# File 'lib/hawkular/alerts/alerts_api.rb', line 311 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.
364 365 366 367 |
# File 'lib/hawkular/alerts/alerts_api.rb', line 364 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
279 280 281 282 283 284 285 286 |
# File 'lib/hawkular/alerts/alerts_api.rb', line 279 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 |