Module: Sensu::Settings::Validators::Subdue

Included in:
Sensu::Settings::Validators
Defined in:
lib/sensu/settings/validators/subdue.rb

Instance Method Summary collapse

Instance Method Details

#validate_subdue(definition) ⇒ Object

Validate Sensu subdue, for either a check or handler definition.


55
56
57
58
59
60
61
62
63
64
# File 'lib/sensu/settings/validators/subdue.rb', line 55

def validate_subdue(definition)
  subdue = definition[:subdue]
  validate_subdue_time("subdue", definition, subdue)
  if is_a_hash?(subdue)
    must_be_either_if_set(%w[handler publisher], subdue[:at]) ||
      invalid(definition, "subdue at must be either handler or publisher")
    validate_subdue_days(definition)
    validate_subdue_exceptions(definition)
  end
end

#validate_subdue_days(definition) ⇒ Object

Validate subdue days. Validates: days


26
27
28
29
30
31
32
33
34
35
# File 'lib/sensu/settings/validators/subdue.rb', line 26

def validate_subdue_days(definition)
  subdue = definition[:subdue]
  must_be_an_array_if_set(subdue[:days]) ||
    invalid(definition, "subdue days must be an array")
  if is_an_array?(subdue[:days])
    days = %w[sunday monday tuesday wednesday thursday friday saturday]
    must_be_either(days, subdue[:days]) ||
      invalid(definition, "subdue days must be valid days of the week")
  end
end

#validate_subdue_exceptions(definition) ⇒ Object

Validate subdue exceptions. Validates: exceptions (begin, end)


41
42
43
44
45
46
47
48
49
50
# File 'lib/sensu/settings/validators/subdue.rb', line 41

def validate_subdue_exceptions(definition)
  subdue = definition[:subdue]
  must_be_an_array_if_set(subdue[:exceptions]) ||
    invalid(definition, "subdue exceptions must be an array")
  if is_an_array?(subdue[:exceptions])
    subdue[:exceptions].each do |exception|
      validate_subdue_time("subdue exceptions", definition, exception)
    end
  end
end

#validate_subdue_time(scope, definition, object) ⇒ Object

Validate subdue time. Validates: begin, end


11
12
13
14
15
16
17
18
19
20
# File 'lib/sensu/settings/validators/subdue.rb', line 11

def validate_subdue_time(scope, definition, object)
  if is_a_hash?(object)
    if either_are_set?(object[:begin], object[:end])
      must_be_time(object[:begin], object[:end]) ||
        invalid(definition, "#{scope} begin and end times must be valid")
    end
  else
    invalid(definition, "#{scope} must be a hash")
  end
end