class ESP::Alert

Public Class Methods

find(*arguments) click to toggle source

Find an Alert by id

@overload find(id)

@param id [Integer, Numeric, #to_i] Required ID of the alert to retrieve.

@overload find(id, options)

@param id [Integer, Numeric, #to_i] Required ID of the alert to retrieve.
@param options [Hash]
  ===== Valid Options

  +include+ | The list of associated objects to return on the initial request.

  ===== Valid Includable Associations

  See {API documentation}[http://api-docs.evident.io?ruby#searching-alerts] for valid arguments

@overload find(scope, options)

*call-seq* -> +super.all(options)+
@api private
@param scope [Object] *Example:* +:all+
@param options [Hash] +{ params: { report_id: Integer } }+
@raise [ArgumentError] if no +report_id+ is supplied.

@return [ESP::Alert] @example

alert = ESP::Alert.find(1)
alert = ESP::Alert.find(1, include: 'tags,external_account.team')
alert = ESP::Alert.find(:all, params: { report_id: 5 })
Calls superclass method ESP::Resource::find
# File lib/esp/resources/alert.rb, line 96
def self.find(*arguments)
  scope = arguments.slice!(0)
  options = (arguments.slice!(0) || {}).with_indifferent_access
  return super(scope, options) if scope.is_a?(Numeric) || options[:from].present?
  params = options.fetch(:params, {})
  from = for_report(params.delete(:report_id))
  all(from: "#{from}.json", params: params)
end
for_report(report_id) click to toggle source

@private

# File lib/esp/resources/alert.rb, line 106
def self.for_report(report_id)
  fail ArgumentError, "You must supply a report id." unless report_id.present?
  "#{prefix}reports/#{report_id}/alerts"
end
where(clauses = {}) click to toggle source

Returns alerts for the given report_id

call-seq -> +super.where(clauses)+

@param clauses [Hash] Required hash of attributes with appended predicates to search, sort and include.

===== Valid Clauses

See {API documentation}[http://api-docs.evident.io?ruby#searching-alerts] for valid arguments

@return [ActiveResource::PaginatedCollection<ESP::Alert>] @example

alerts = ESP::Alert.where(report_id: 54, status_eq: 'fail', signature_risk_level_in: ['High'], include: 'signature')
Calls superclass method ESP::Resource::where
# File lib/esp/resources/alert.rb, line 63
def self.where(clauses = {})
  clauses = clauses.with_indifferent_access
  return super(clauses) if clauses[:from].present?
  from = for_report(clauses.delete(:report_id))
  super clauses.merge(from: from)
end

Private Class Methods

filters(params) click to toggle source

Overridden because alerts does not use ransack for searching

# File lib/esp/resources/alert.rb, line 137
def self.filters(params)
  { filter: params }
end

Public Instance Methods

destroy() click to toggle source

Not Implemented. You cannot destroy an Alert.

@return [void]

# File lib/esp/resources/alert.rb, line 48
def destroy
  fail ESP::NotImplementedError
end
metadata() click to toggle source

Returns the metadata associated with this alert.

@return [ESP::Metadata]

# File lib/esp/resources/alert.rb, line 34
def metadata
  ESP::Metadata.for_alert(id)
end
save() click to toggle source

Not Implemented. You cannot create or update an Alert.

@return [void]

# File lib/esp/resources/alert.rb, line 41
def save
  fail ESP::NotImplementedError
end
suppress_region(reason = nil) click to toggle source

Suppress the region associated with this alert.

@param reason [String] Required reason for creating the suppression. @return [ESP::Suppression::Region]

# File lib/esp/resources/alert.rb, line 123
def suppress_region(reason = nil)
  suppress(Suppression::Region, reason)
end
suppress_signature(reason = nil) click to toggle source

Suppress the signature associated with this alert.

@param reason [String] Required reason for creating the suppression. @return [ESP::Suppression::Signature]

# File lib/esp/resources/alert.rb, line 115
def suppress_signature(reason = nil)
  suppress(Suppression::Signature, reason)
end
suppress_unique_identifier(reason = nil) click to toggle source

Suppress the unique identifier associated with this alert.

@param reason [String] Required reason for creating the suppression. @return [ESP::Suppression::UniqueIdentifier] @raise [ArgumentError] if no reason is supplied.

# File lib/esp/resources/alert.rb, line 132
def suppress_unique_identifier(reason = nil)
  suppress(Suppression::UniqueIdentifier, reason)
end

Private Instance Methods

suppress(klass, reason) click to toggle source
# File lib/esp/resources/alert.rb, line 144
def suppress(klass, reason)
  fail ArgumentError, "You must specify the reason.".freeze unless reason.present?
  klass.create(alert_id: id, reason: reason)
end