Class: SidekiqVigil::Alert::DigestEvent

Inherits:
Object
  • Object
show all
Defined in:
lib/sidekiq_vigil/alert/event.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(events:, timestamp:, limit: 5) ⇒ DigestEvent

Returns a new instance of DigestEvent.



40
41
42
43
44
# File 'lib/sidekiq_vigil/alert/event.rb', line 40

def initialize(events:, timestamp:, limit: 5)
  @events = events
  @timestamp = timestamp
  @limit = limit
end

Instance Attribute Details

#eventsObject (readonly)

Returns the value of attribute events.



38
39
40
# File 'lib/sidekiq_vigil/alert/event.rb', line 38

def events
  @events
end

#timestampObject (readonly)

Returns the value of attribute timestamp.



38
39
40
# File 'lib/sidekiq_vigil/alert/event.rb', line 38

def timestamp
  @timestamp
end

Instance Method Details

#alert_idObject



54
55
56
# File 'lib/sidekiq_vigil/alert/event.rb', line 54

def alert_id
  "digest"
end

#historyObject



68
69
70
# File 'lib/sidekiq_vigil/alert/event.rb', line 68

def history
  []
end

#resultObject



58
59
60
61
62
63
64
65
66
# File 'lib/sidekiq_vigil/alert/event.rb', line 58

def result
  @result ||= Result.new(
    check_name: "digest",
    severity:,
    value: events.length,
    message: "#{events.length} alerts in this cycle",
    metadata: { counts: counts, top: top }
  )
end

#severityObject



50
51
52
# File 'lib/sidekiq_vigil/alert/event.rb', line 50

def severity
  severities.include?(:critical) || severities.include?(:error) ? :critical : :warn
end

#stateObject



72
73
74
# File 'lib/sidekiq_vigil/alert/event.rb', line 72

def state
  State.new(status: "firing", severity: severity.to_s)
end

#to_hObject



76
77
78
79
80
81
82
83
84
85
# File 'lib/sidekiq_vigil/alert/event.rb', line 76

def to_h
  {
    schema_version: "1.0",
    event: "digest",
    alert_id:,
    timestamp: timestamp.utc.iso8601,
    counts:,
    alerts: top
  }
end

#transitionObject



46
47
48
# File 'lib/sidekiq_vigil/alert/event.rb', line 46

def transition
  :digest
end