lib/hawkular/alerts/alerts_api.rb in hawkular-client-2.9.0 vs lib/hawkular/alerts/alerts_api.rb in hawkular-client-3.0.0

- old
+ new

@@ -244,12 +244,22 @@ # List fired alerts # @param [Hash]criteria optional query criteria # @return [Array<Alert>] List of alerts in the system. Can be empty def list_alerts(criteria = {}) + alerts(criteria: criteria) + end + + # List fired alerts + # @param [Hash] criteria optional query criteria + # @param [Array] tenants optional list of tenants. The elements of the array can be any object + # convertible to a string + # @return [Array<Alert>] List of alerts in the system. Can be empty + def alerts(criteria: {}, tenants:nil) query = generate_query_params(criteria) - ret = http_get('/' + query) + uri = tenants ? '/admin/alerts/' : '/' + ret = http_get(uri + query, multi_tenants_header(tenants)) val = [] ret.each { |a| val.push(Alert.new(a)) } val end @@ -296,15 +306,32 @@ # 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) # @param [Hash] criteria optional query criteria # @return [Array<Event>] List of events. Can be empty - def list_events(*criteria) - query = generate_query_params(*criteria) - http_get('/events' + query).map { |e| Event.new(e) } + def list_events(criteria = {}) + events(criteria: criteria) end + # 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) + # @param [Hash] criteria optional query criteria + # @param [Array] tenants optional list of tenants. The elements of the array can be any object + # convertible to a string + # @return [Array<Event>] List of events. Can be empty + 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 + # Inject an event into Hawkular-alerts # @param [String] id Id of the event must be unique # @param [String] category Event category for further distinction # @param [String] text Some text to the user # @param [Hash<String,Object>] extras additional parameters @@ -336,10 +363,22 @@ # @param [Array<String>] tag_names List of tag names. def remove_tags(alert_ids, tag_names) query = generate_query_params(alertIds: alert_ids, tagNames: tag_names) http_delete('/tags' + query) end + + private + + # Builds the tenant HTTP header for multi-tenant operations + # @param [Array] tenants an array of tenant names. The elements of the array can + # be any object convertible to a string. Can be nil + # @return [Hash] The HTTP header for multi-tenant operations. An empty hash is returned + # if tenants parameter is nil + def multi_tenants_header(tenants) + tenants = tenants.join(',') if tenants.respond_to?(:join) + tenants ? { 'Hawkular-Tenant': tenants } : {} + end end # Representation of one Trigger ## (22 known properties: "enabled", "autoResolveMatch", "name", "memberOf", "autoEnable", # "firingMatch", "tags", "id", "source", "tenantId", "eventText", "context", "eventType", @@ -573,9 +612,6 @@ class Event < OpenStruct def initialize(event_hash) super(event_hash) end end - - AlertsClient = Client - deprecate_constant :AlertsClient if self.respond_to? :deprecate_constant end