Class: Mihari::Alert

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/mihari/models/alert.rb

Class Method Summary collapse

Class Method Details

.count(filter) ⇒ Integer

Count alerts

Parameters:

  • artifact_data (String, nil)

Returns:

  • (Integer)


41
42
43
44
# File 'lib/mihari/models/alert.rb', line 41

def count(filter)
  relation = build_relation(filter)
  relation.distinct("alerts.id").count
end

.search(filter) ⇒ Array<Alert>

Search alerts

Parameters:

Returns:

Raises:

  • (ArgumentError)


19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/mihari/models/alert.rb', line 19

def search(filter)
  limit = filter.limit.to_i
  raise ArgumentError, "limit should be bigger than zero" unless limit.positive?

  page = filter.page.to_i
  raise ArgumentError, "page should be bigger than zero" unless page.positive?

  offset = (page - 1) * limit

  relation = build_relation(filter.without_pagination)

  alert_ids = relation.limit(limit).offset(offset).order(id: :desc).pluck(:id).uniq
  eager_load(:artifacts, :tags).where(id: [alert_ids]).order(id: :desc)
end