Module: Sensu::Settings::Validators::Handler

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

Instance Method Summary collapse

Instance Method Details

#validate_handler(handler) ⇒ Object

Validate a Sensu handler definition. Validates: timeout, mutator, handle_flapping

Parameters:

  • handler (Hash)

    sensu handler definition.


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

def validate_handler(handler)
  validate_handler_type(handler)
  validate_handler_filtering(handler)
  validate_handler_severities(handler)
  must_be_a_numeric_if_set(handler[:timeout]) ||
    invalid(handler, "handler timeout must be numeric")
  must_be_a_string_if_set(handler[:mutator]) ||
    invalid(handler, "handler mutator must be a string")
  must_be_boolean_if_set(handler[:handle_flapping]) ||
    invalid(handler, "handler handle_flapping must be boolean")
  if handler[:subdue]
    validate_subdue(handler)
  end
end

#validate_handler_filtering(handler) ⇒ Object

Validate handler filtering. Validates: filter, filters

Parameters:

  • handler (Hash)

    sensu handler definition.


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

def validate_handler_filtering(handler)
  must_be_an_array_if_set(handler[:filters]) ||
    invalid(handler, "handler filters must be an array")
  if is_an_array?(handler[:filters])
    items_must_be_strings(handler[:filters]) ||
      invalid(handler, "handler filters items must be strings")
  end
  must_be_a_string_if_set(handler[:filter]) ||
    invalid(handler, "handler filter must be a string")
end

#validate_handler_severities(handler) ⇒ Object

Validate handler severities. Validates: severities

Parameters:

  • handler (Hash)

    sensu handler definition.


103
104
105
106
107
108
109
110
# File 'lib/sensu/settings/validators/handler.rb', line 103

def validate_handler_severities(handler)
  must_be_an_array_if_set(handler[:severities]) ||
    invalid(handler, "handler severities must be an array")
  if is_an_array?(handler[:severities])
    must_be_either(%w[ok warning critical unknown], handler[:severities]) ||
      invalid(handler, "handler severities are invalid")
  end
end

#validate_handler_type(handler) ⇒ Object

Validate handler type. Validates: type

Parameters:

  • handler (Hash)

    sensu handler definition.


67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/sensu/settings/validators/handler.rb', line 67

def validate_handler_type(handler)
  must_be_a_string(handler[:type]) ||
    invalid(handler, "handler type must be a string")
  case handler[:type]
  when "pipe"
    validate_pipe_handler(handler)
  when "tcp", "udp"
    validate_socket_handler(handler)
  when "transport"
    validate_transport_handler(handler)
  when "set"
    validate_set_handler(handler)
  else
    invalid(handler, "unknown handler type")
  end
end

#validate_pipe_handler(handler) ⇒ Object

Validate pipe handler. Validates: command

Parameters:

  • handler (Hash)

    sensu handler definition.


9
10
11
12
# File 'lib/sensu/settings/validators/handler.rb', line 9

def validate_pipe_handler(handler)
  must_be_a_string(handler[:command]) ||
    invalid(handler, "handler command must be a string")
end

#validate_set_handler(handler) ⇒ Object

Validate set handler. Validates: handlers

Parameters:

  • handler (Hash)

    sensu handler definition.


54
55
56
57
58
59
60
61
# File 'lib/sensu/settings/validators/handler.rb', line 54

def validate_set_handler(handler)
  if is_an_array?(handler[:handlers])
    items_must_be_strings(handler[:handlers]) ||
      invalid(handler, "handler set handlers must each be a string")
  else
    invalid(handler, "handler set handlers must be an array")
  end
end

#validate_socket_handler(handler) ⇒ Object

Validate socket (tcp/udp) handler. Validates: socket (host, port)

Parameters:

  • handler (Hash)

    sensu handler definition.


18
19
20
21
22
23
24
25
26
27
28
# File 'lib/sensu/settings/validators/handler.rb', line 18

def validate_socket_handler(handler)
  socket = handler[:socket]
  if is_a_hash?(socket)
    must_be_a_string(socket[:host]) ||
      invalid(handler, "handler host must be a string")
    must_be_an_integer(socket[:port]) ||
      invalid(handler, "handler port must be an integer")
  else
    invalid(handler, "handler socket must be a hash")
  end
end

#validate_transport_handler(handler) ⇒ Object

Validate transport handler. Validates: pipe (type, name, options)

Parameters:

  • handler (Hash)

    sensu handler definition.


34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/sensu/settings/validators/handler.rb', line 34

def validate_transport_handler(handler)
  pipe = handler[:pipe]
  if is_a_hash?(pipe)
    must_be_a_string(pipe[:type]) ||
      invalid(handler, "handler transport pipe type must be a string")
    must_be_either(%w[direct fanout topic], pipe[:type]) ||
      invalid(handler, "handler transport pipe type is invalid")
    must_be_a_string(pipe[:name]) ||
      invalid(handler, "handler transport pipe name must be a string")
    must_be_a_hash_if_set(pipe[:options]) ||
      invalid(handler, "handler transport pipe options must be a hash")
  else
    invalid(handler, "handler transport pipe must be a hash")
  end
end