class ATSD::AlertsService

Public Instance Methods

delete(alerts) click to toggle source

Delete alerts

@param [Array<Hash, Alert>, Hash, Alert] alerts @return [self] @raise [APIError]

# File lib/atsd/services/alerts_service.rb, line 38
def delete(alerts)
  alerts = Utils.ensure_array(alerts).map do |alert|
    { :id => id_for_alert(alert) }
  end
  return if alerts.count == 0
  @client.alerts_delete alerts
end
history_query(options = {}) click to toggle source

Create query builder for alert history.

@param [Hash] options query parameters @return [AlertsHistoryQuery]

# File lib/atsd/services/alerts_service.rb, line 50
def history_query(options = {})
  query = AlertsHistoryQuery.new @client
  options.each { |option, value| query[option] = value }
  query
end
query(options = {}) click to toggle source

Create query builder for alerts.

@param [Hash] options query parameters @return [AlertsQuery]

# File lib/atsd/services/alerts_service.rb, line 13
def query(options = {})
  query = AlertsQuery.new @client
  options.each { |option, value| query[option] = value }
  query
end
update(alerts) click to toggle source

Change acknowledgement status of the specified alerts.

@param [Array<Hash, Alert>, Hash, Alert] alerts @return [self] @raise [APIError]

# File lib/atsd/services/alerts_service.rb, line 24
def update(alerts)
  alerts = Utils.ensure_array(alerts).map do |alert|
    { :id => id_for_alert(alert),
      :acknowledged => acknowledged_for_alert(alert)}
  end
  return if alerts.count == 0
  @client.alerts_update alerts
end

Private Instance Methods

acknowledged_for_alert(alert) click to toggle source
# File lib/atsd/services/alerts_service.rb, line 71
def acknowledged_for_alert(alert)
  case alert
    when Alert
      alert.acknowledged
    when Hash
      alert[:acknowledged] || alert['acknowledged']
    else
      false
  end
end
id_for_alert(alert) click to toggle source
# File lib/atsd/services/alerts_service.rb, line 58
def id_for_alert(alert)
  case alert
    when Integer
      alert
    when Alert
      alert.id
    when Hash
      alert[:id] || alert['id']
    else
      alert.id
  end
end