Class: Anomonitor::Mute

Inherits:
ApplicationRecord show all
Defined in:
app/models/anomonitor/mute.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.muted?(anomaly_or_attrs) ⇒ Boolean

Returns:

  • (Boolean)


37
38
39
40
41
# File 'app/models/anomonitor/mute.rb', line 37

def self.muted?(anomaly_or_attrs)
  active.any? { |m| m.matches?(anomaly_or_attrs) }
rescue StandardError
  false
end

.prune_expired!Object



43
44
45
# File 'app/models/anomonitor/mute.rb', line 43

def self.prune_expired!
  where("muted_until <= ?", Time.current).delete_all
end

Instance Method Details

#active?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'app/models/anomonitor/mute.rb', line 12

def active?
  muted_until > Time.current
end

#matches?(anomaly_or_attrs) ⇒ Boolean

Returns:

  • (Boolean)


16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'app/models/anomonitor/mute.rb', line 16

def matches?(anomaly_or_attrs)
  attrs =
    if anomaly_or_attrs.respond_to?(:metric)
      {
        metric: anomaly_or_attrs.metric,
        rule: anomaly_or_attrs.rule,
        source: anomaly_or_attrs.source,
        tenant: tenant_from(anomaly_or_attrs)
      }
    else
      anomaly_or_attrs
    end

  return false if metric.present? && metric.to_s != attrs[:metric].to_s
  return false if rule.present? && rule.to_s != attrs[:rule].to_s
  return false if source.present? && source.to_s != attrs[:source].to_s
  return false if tenant.present? && tenant.to_s != attrs[:tenant].to_s

  true
end