Class: SidekiqVigil::Result

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

Constant Summary collapse

SEVERITIES =
%i[ok warn critical error].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(check_name:, severity:, target: "global", value: nil, threshold: nil, message: nil, metadata: {}) ⇒ Result

Returns a new instance of Result.

Raises:

  • (ArgumentError)


9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/sidekiq_vigil/result.rb', line 9

def initialize(check_name:, severity:, target: "global", value: nil, threshold: nil, message: nil, metadata: {})
  severity = severity.to_sym
  raise ArgumentError, "unknown severity: #{severity}" unless SEVERITIES.include?(severity)

  @check_name = check_name.to_s
  @target = target.to_s
  @severity = severity
  @value = value
  @threshold = threshold
  @message = message
  @metadata = .freeze
  freeze
end

Instance Attribute Details

#check_nameObject (readonly)

Returns the value of attribute check_name.



7
8
9
# File 'lib/sidekiq_vigil/result.rb', line 7

def check_name
  @check_name
end

#messageObject (readonly)

Returns the value of attribute message.



7
8
9
# File 'lib/sidekiq_vigil/result.rb', line 7

def message
  @message
end

#metadataObject (readonly)

Returns the value of attribute metadata.



7
8
9
# File 'lib/sidekiq_vigil/result.rb', line 7

def 
  @metadata
end

#severityObject (readonly)

Returns the value of attribute severity.



7
8
9
# File 'lib/sidekiq_vigil/result.rb', line 7

def severity
  @severity
end

#targetObject (readonly)

Returns the value of attribute target.



7
8
9
# File 'lib/sidekiq_vigil/result.rb', line 7

def target
  @target
end

#thresholdObject (readonly)

Returns the value of attribute threshold.



7
8
9
# File 'lib/sidekiq_vigil/result.rb', line 7

def threshold
  @threshold
end

#valueObject (readonly)

Returns the value of attribute value.



7
8
9
# File 'lib/sidekiq_vigil/result.rb', line 7

def value
  @value
end

Instance Method Details

#alert_idObject



27
28
29
# File 'lib/sidekiq_vigil/result.rb', line 27

def alert_id
  "#{check_name}:#{target}"
end

#ok?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/sidekiq_vigil/result.rb', line 23

def ok?
  severity == :ok
end

#to_hObject



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/sidekiq_vigil/result.rb', line 31

def to_h
  {
    check_name: check_name,
    target: target,
    severity: severity,
    value: value,
    threshold: threshold,
    message: message,
    metadata: 
  }
end