Module: Sensu::Settings::Validators::TimeWindow

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

Instance Method Summary collapse

Instance Method Details

#validate_time_window_condition(definition, scope, attribute, condition) ⇒ Object

Validate time window condition Validates: begin, end

Parameters:

  • definition (Hash)

    sensu definition.

  • scope (String)

    definition scope to validate.

  • attribute (String)

    definition attribute to validate.

  • condition (Hash)

    to have begin and end validated.


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

def validate_time_window_condition(definition, scope, attribute, condition)
  if is_a_hash?(condition)
    must_be_time(condition[:begin], condition[:end]) ||
      invalid(definition, "#{scope} #{attribute} day time window begin and end times must be valid")
  else
    invalid(definition, "#{scope} #{attribute} day time window must be a hash")
  end
end

#validate_time_windows(definition, scope, attribute) ⇒ Object

Validate time windows Validates: days

Parameters:

  • definition (Hash)

    sensu definition.

  • scope (String)

    definition scope to validate.

  • attribute (String)

    definition attribute to validate.


55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/sensu/settings/validators/time_window.rb', line 55

def validate_time_windows(definition, scope, attribute)
  if is_a_hash?(definition[attribute])
    days = definition[attribute][:days]
    if is_a_hash?(days)
      if !days.empty?
        validate_time_windows_days(definition, scope, attribute, days)
      else
        invalid(definition, "#{scope} #{attribute} days must include at least one day of the week or 'all'")
      end
    else
      invalid(definition, "#{scope} #{attribute} days must be a hash")
    end
  else
    invalid(definition, "#{scope} #{attribute} must be a hash")
  end
end

#validate_time_windows_days(definition, scope, attribute, days) ⇒ Object

Validate time windows days Validates: days

Parameters:

  • definition (Hash)

    sensu definition.

  • scope (String)

    definition scope to validate.

  • attribute (String)

    definition attribute to validate.

  • days (String)

    time window days to validate.


28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/sensu/settings/validators/time_window.rb', line 28

def validate_time_windows_days(definition, scope, attribute, days)
  valid_days = [:all, :sunday, :monday, :tuesday, :wednesday, :thursday, :friday, :saturday]
  if must_be_either(valid_days, days.keys)
    days.each do |day, conditions|
      if is_an_array?(conditions)
        if !conditions.empty?
          conditions.each do |condition|
            validate_time_window_condition(definition, scope, attribute, condition)
          end
        else
          invalid(definition, "#{scope} #{attribute} days #{day} must include at least one time window")
        end
      else
        invalid(definition, "#{scope} #{attribute} days #{day} must be in an array")
      end
    end
  else
    invalid(definition, "#{scope} #{attribute} days must be valid days of the week or 'all'")
  end
end