Class: SidekiqVigil::Alert::State
- Inherits:
-
Object
- Object
- SidekiqVigil::Alert::State
- Defined in:
- lib/sidekiq_vigil/alert/state.rb
Constant Summary collapse
- ATTRIBUTES =
%i[ status cycles first_seen_at last_notified_at last_transition_at severity value threshold message suppressed flap_notified flapping_until transition_timestamps ].freeze
Class Method Summary collapse
Instance Method Summary collapse
- #dump ⇒ Object
- #firing? ⇒ Boolean
-
#initialize(attributes = {}) ⇒ State
constructor
A new instance of State.
- #to_h ⇒ Object
Constructor Details
#initialize(attributes = {}) ⇒ State
Returns a new instance of State.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/sidekiq_vigil/alert/state.rb', line 15 def initialize(attributes = {}) attributes = attributes.transform_keys(&:to_sym) @status = attributes.fetch(:status, "ok") @cycles = attributes.fetch(:cycles, 0) @first_seen_at = attributes[:first_seen_at] @last_notified_at = attributes[:last_notified_at] @last_transition_at = attributes[:last_transition_at] @severity = attributes.fetch(:severity, "ok") @value = attributes[:value] @threshold = attributes[:threshold] @message = attributes[:message] @suppressed = attributes.fetch(:suppressed, false) @flap_notified = attributes.fetch(:flap_notified, false) @flapping_until = attributes[:flapping_until] @transition_timestamps = attributes.fetch(:transition_timestamps, []) end |
Class Method Details
.load(json) ⇒ Object
32 33 34 35 36 |
# File 'lib/sidekiq_vigil/alert/state.rb', line 32 def self.load(json) new(JSON.parse(json)) rescue JSON::ParserError new end |
Instance Method Details
#dump ⇒ Object
42 43 44 |
# File 'lib/sidekiq_vigil/alert/state.rb', line 42 def dump JSON.generate(to_h) end |
#firing? ⇒ Boolean
46 47 48 |
# File 'lib/sidekiq_vigil/alert/state.rb', line 46 def firing? status == "firing" end |
#to_h ⇒ Object
38 39 40 |
# File 'lib/sidekiq_vigil/alert/state.rb', line 38 def to_h ATTRIBUTES.to_h { |name| [name, public_send(name)] } end |