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

Parameters:

  • client (Hash)

    sensu client definition.


213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
# File 'lib/sensu/settings/validators/client.rb', line 213

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(/\A[\w\.-]+\z/, 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_http_socket(client)
    validate_client_keepalives(client)
    validate_client_keepalive(client)
    validate_client_redact(client)
    validate_client_signature(client)
    validate_client_registration(client)
    validate_client_deregistration(client)
  end
end

#validate_client_deregistration(client) ⇒ Object

Validate client deregistration. Validates: deregistration

Parameters:

  • client (Hash)

    sensu client definition.


199
200
201
202
203
204
205
206
207
# File 'lib/sensu/settings/validators/client.rb', line 199

def validate_client_deregistration(client)
  must_be_a_hash_if_set(client[:deregistration]) ||
    invalid(client, "client deregistration must be a hash")
  if is_a_hash?(client[:deregistration])
    validate_client_deregistration_handlers(client)
    must_be_an_integer_if_set(client[:deregistration][:status]) ||
      invalid(client, "client deregistration status must be an integer")
  end
end

#validate_client_deregistration_handlers(client) ⇒ Object

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

Parameters:

  • client (Hash)

    sensu client definition.


184
185
186
187
188
189
190
191
192
193
# File 'lib/sensu/settings/validators/client.rb', line 184

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

#validate_client_http_socket(client) ⇒ Object

Validate client http_socket. Validates: http_socket (enabled, bind, port, user, password, protect_all_endpoints)

Parameters:

  • client (Hash)

    sensu client definition.


48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/sensu/settings/validators/client.rb', line 48

def validate_client_http_socket(client)
  http_socket = client[:http_socket]
  must_be_a_hash_if_set(http_socket) ||
    invalid(client, "client http_socket must be a hash")
  if is_a_hash?(http_socket)
    must_be_boolean_if_set(http_socket[:enabled]) ||
      invalid(client, "client http_socket enabled must be boolean")
    must_be_a_string_if_set(http_socket[:bind]) ||
      invalid(client, "client http_socket bind must be a string")
    must_be_an_integer_if_set(http_socket[:port]) ||
      invalid(client, "client http_socket port must be an integer")
    if either_are_set?(http_socket[:user], http_socket[:password])
      must_be_a_string(http_socket[:user]) ||
        invalid(client, "client http_socket user must be a string")
      must_be_a_string(http_socket[:password]) ||
        invalid(client, "client http_socket password must be a string")
    end
    must_be_boolean_if_set(http_socket[:protect_all_endpoints]) ||
      invalid(client, "client http_socket protect_all_endpoints must be boolean")
  end
end

#validate_client_keepalive(client) ⇒ Object

Validate client keepalive. Validates: keepalive

Parameters:

  • client (Hash)

    sensu client definition.


114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/sensu/settings/validators/client.rb', line 114

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)
    # A client keepalive may include several check attributes.
    # Validation is necessary, although the validation failure
    # messages may be a bit confusing.
    validate_check_source(client[:keepalive]) if client[:keepalive][:source]
    validate_check_aggregate(client[:keepalive])
    validate_check_flap_detection(client[:keepalive])
  end
end

#validate_client_keepalive_handlers(client) ⇒ Object

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

Parameters:

  • client (Hash)

    sensu client definition.


83
84
85
86
87
88
89
90
91
92
# File 'lib/sensu/settings/validators/client.rb', line 83

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)

Parameters:

  • client (Hash)

    sensu client definition.


98
99
100
101
102
103
104
105
106
107
108
# File 'lib/sensu/settings/validators/client.rb', line 98

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_keepalives(client) ⇒ Object

Validate client keepalives. Validates: keepalives

Parameters:

  • client (Hash)

    sensu client definition.


74
75
76
77
# File 'lib/sensu/settings/validators/client.rb', line 74

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

#validate_client_redact(client) ⇒ Object

Validate client redact. Validates: redact

Parameters:

  • client (Hash)

    sensu client definition.


133
134
135
136
137
138
139
140
# File 'lib/sensu/settings/validators/client.rb', line 133

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_registration(client) ⇒ Object

Validate client registration. Validates: registration

Parameters:

  • client (Hash)

    sensu client definition.


170
171
172
173
174
175
176
177
178
# File 'lib/sensu/settings/validators/client.rb', line 170

def validate_client_registration(client)
  must_be_a_hash_if_set(client[:registration]) ||
    invalid(client, "client registration must be a hash")
  if is_a_hash?(client[:registration])
    validate_client_registration_handlers(client)
    must_be_an_integer_if_set(client[:registration][:status]) ||
      invalid(client, "client registration status must be an integer")
  end
end

#validate_client_registration_handlers(client) ⇒ Object

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

Parameters:

  • client (Hash)

    sensu client definition.


155
156
157
158
159
160
161
162
163
164
# File 'lib/sensu/settings/validators/client.rb', line 155

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

#validate_client_safe_mode(client) ⇒ Object

Validate client safe mode. Validates: safe_mode

Parameters:

  • client (Hash)

    sensu client definition.


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_signature(client) ⇒ Object

Validate client signature. Validates: signature

Parameters:

  • client (Hash)

    sensu client definition.


146
147
148
149
# File 'lib/sensu/settings/validators/client.rb', line 146

def validate_client_signature(client)
  must_be_a_string_if_set(client[:signature]) ||
    invalid(client, "client signature must be a string")
end

#validate_client_socket(client) ⇒ Object

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

Parameters:

  • client (Hash)

    sensu client definition.


31
32
33
34
35
36
37
38
39
40
41
42
# 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_boolean_if_set(client[:socket][:enabled]) ||
      invalid(client, "client socket enabled must be a boolean")
    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

Parameters:

  • client (Hash)

    sensu client definition.


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 non empty string")
  else
    invalid(client, "client subscriptions must be an array")
  end
end