Module: Sensu::Settings::Validators::Check

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

Instance Method Summary collapse

Instance Method Details

#validate_check(check) ⇒ Object

Validate a Sensu check definition.


59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/sensu/settings/validators/check.rb', line 59

def validate_check(check)
  must_be_a_string(check[:name]) ||
    invalid(check, "check name must be a string")
  must_match_regex(/^[\w\.-]+$/, check[:name]) ||
    invalid(check, "check name cannot contain spaces or special characters")
  must_be_a_string(check[:command]) ||
    invalid(check, "check command must be a string")
  must_be_a_numeric_if_set(check[:timeout]) ||
    invalid(check, "check timeout must be numeric")
  must_be_a_string_if_set(check[:source]) ||
    invalid(check, "check source must be a string")
  validate_check_scheduling(check)
  validate_check_handling(check)
  validate_check_flap_detection(check)
  if check[:subdue]
    validate_subdue(check)
  end
end

#validate_check_flap_detection(check) ⇒ Object

Validate check flap detection. Validates: low_flap_threshold, high_flap_threshold


47
48
49
50
51
52
53
54
# File 'lib/sensu/settings/validators/check.rb', line 47

def validate_check_flap_detection(check)
  if either_are_set?(check[:low_flap_threshold], check[:high_flap_threshold])
    must_be_an_integer(check[:low_flap_threshold]) ||
      invalid(check, "check low flap threshold must be an integer")
    must_be_an_integer(check[:high_flap_threshold]) ||
      invalid(check, "check high flap threshold must be an integer")
  end
end

#validate_check_handling(check) ⇒ Object

Validate check handling. Validates: handler, handlers


32
33
34
35
36
37
38
39
40
41
# File 'lib/sensu/settings/validators/check.rb', line 32

def validate_check_handling(check)
  must_be_a_string_if_set(check[:handler]) ||
    invalid(check, "check handler must be a string")
  must_be_an_array_if_set(check[:handlers]) ||
    invalid(check, "check handlers must be an array")
  if is_an_array?(check[:handlers])
    items_must_be_strings(check[:handlers]) ||
      invalid(check, "check handlers must each be a string")
  end
end

#validate_check_scheduling(check) ⇒ Object

Validate check scheduling. Validates: interval, standalone, subscribers


9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/sensu/settings/validators/check.rb', line 9

def validate_check_scheduling(check)
  must_be_boolean_if_set(check[:publish]) ||
    invalid(check, "check publish must be boolean")
  unless check[:publish] == false
    (must_be_an_integer(check[:interval]) && check[:interval] > 0) ||
      invalid(check, "check interval must be an integer")
  end
  must_be_boolean_if_set(check[:standalone]) ||
    invalid(check, "check standalone must be boolean")
  unless check[:standalone]
    if is_an_array?(check[:subscribers])
      items_must_be_strings(check[:subscribers]) ||
        invalid(check, "check subscribers must each be a string")
    else
      invalid(check, "check subscribers must be an array")
    end
  end
end