Module: Sensu::Settings::Validators::Client

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

Instance Method Summary collapse

Instance Method Details

#validate_client(client) ⇒ Object

Validate a Sensu client definition. Validates: name, address, safe_mode


103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/sensu/settings/validators/client.rb', line 103

def validate_client(client)
  must_be_a_hash(client) ||
    invalid(client, "client must be a hash")
  if is_a_hash?(client)
    must_be_a_string(client[:name]) ||
      invalid(client, "client name must be a string")
    must_match_regex(/^[\w\.-]+$/, client[:name]) ||
      invalid(client, "client name cannot contain spaces or special characters")
    must_be_a_string(client[:address]) ||
      invalid(client, "client address must be a string")
    validate_client_safe_mode(client)
    validate_client_subscriptions(client)
    validate_client_socket(client)
    validate_client_keepalive(client)
    validate_client_redact(client)
  end
end

#validate_client_keepalive(client) ⇒ Object

Validate client keepalive. Validates: keepalive


77
78
79
80
81
82
83
84
# File 'lib/sensu/settings/validators/client.rb', line 77

def validate_client_keepalive(client)
  must_be_a_hash_if_set(client[:keepalive]) ||
    invalid(client, "client keepalive must be a hash")
  if is_a_hash?(client[:keepalive])
    validate_client_keepalive_handlers(client)
    validate_client_keepalive_thresholds(client)
  end
end

#validate_client_keepalive_handlers(client) ⇒ Object

Validate client keepalive handlers. Validates: keepalive (handler, handlers)


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

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

#validate_client_keepalive_thresholds(client) ⇒ Object

Validate client keepalive thresholds. Validates: keepalive (thresholds)


61
62
63
64
65
66
67
68
69
70
71
# File 'lib/sensu/settings/validators/client.rb', line 61

def validate_client_keepalive_thresholds(client)
  thresholds = client[:keepalive][:thresholds]
  must_be_a_hash_if_set(thresholds) ||
    invalid(client, "client keepalive thresholds must be a hash")
  if is_a_hash?(thresholds)
    must_be_an_integer_if_set(thresholds[:warning]) ||
      invalid(client, "client keepalive warning threshold must be an integer")
    must_be_an_integer_if_set(thresholds[:critical]) ||
      invalid(client, "client keepalive critical threshold must be an integer")
  end
end

#validate_client_redact(client) ⇒ Object

Validate client redact. Validates: redact


90
91
92
93
94
95
96
97
# File 'lib/sensu/settings/validators/client.rb', line 90

def validate_client_redact(client)
  must_be_an_array_if_set(client[:redact]) ||
    invalid(client, "client redact must be an array")
  if is_an_array?(client[:redact])
    items_must_be_strings(client[:redact]) ||
      invalid(client, "client redact keys must each be a string")
  end
end

#validate_client_safe_mode(client) ⇒ Object

Validate client safe mode. Validates: safe_mode


22
23
24
25
# File 'lib/sensu/settings/validators/client.rb', line 22

def validate_client_safe_mode(client)
  must_be_boolean_if_set(client[:safe_mode]) ||
    invalid(client, "client safe_mode must be boolean")
end

#validate_client_socket(client) ⇒ Object

Validate client socket. Validates: socket (bind, port)


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

def validate_client_socket(client)
  must_be_a_hash_if_set(client[:socket]) ||
    invalid(client, "client socket must be a hash")
  if is_a_hash?(client[:socket])
    must_be_a_string_if_set(client[:socket][:bind]) ||
      invalid(client, "client socket bind must be a string")
    must_be_an_integer_if_set(client[:socket][:port]) ||
      invalid(client, "client socket port must be an integer")
  end
end

#validate_client_subscriptions(client) ⇒ Object

Validate client subscriptions. Validates: subscriptions


9
10
11
12
13
14
15
16
# File 'lib/sensu/settings/validators/client.rb', line 9

def validate_client_subscriptions(client)
  if is_an_array?(client[:subscriptions])
    items_must_be_strings(client[:subscriptions]) ||
      invalid(client, "client subscriptions must each be a string")
  else
    invalid(client, "client subscriptions must be an array")
  end
end