Module: Sensu::Translator::Translations

Included in:
Runner
Defined in:
lib/sensu/translator/translations.rb

Instance Method Summary collapse

Instance Method Details

#go_spec(type, spec, namespace, name, labels = {}, annotations = {}) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/sensu/translator/translations.rb', line 4

def go_spec(type, spec, namespace, name, labels={}, annotations={})
   = {
    :namespace => namespace,
    :name => name,
    :labels => labels,
    :annotations => annotations
  }
  {
    :api_version => "core/v2",
    :type => type.to_s.capitalize,
    :metadata => ,
    :spec => spec
  }
end

#translate_check(object, namespace, name) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/sensu/translator/translations.rb', line 19

def translate_check(object, namespace, name)
  check = {}
  check[:command] = object.delete(:command)
  if object[:standalone]
    object.delete(:standalone)
    check[:subscriptions] = ["standalone"]
  else
    check[:subscriptions] = object.delete(:subscribers) || []
  end
  publish = object.delete(:publish)
  publish = true if publish.nil?
  check[:publish] = publish
  check[:interval] = object.delete(:interval) if object[:interval]
  check[:cron] = object.delete(:cron) if object[:cron]
  check[:handlers] = object.delete(:handlers) || ["default"]
  check[:handlers] << object.delete(:handler) if object[:handler]
  check[:handlers].uniq!
  check[:proxy_entity_name] = object.delete(:source) if object[:source]
  check[:stdin] = object.delete(:stdin) if object[:stdin]
  check[:timeout] = object.delete(:timeout) if object[:timeout]
  check[:ttl] = object.delete(:ttl) if object[:ttl]
  check[:ttl_status] = object.delete(:ttl_status) if object[:ttl_status]
  check[:low_flap_threshold] = object.delete(:low_flap_threshold) if object[:low_flap_threshold]
  check[:high_flap_threshold] = object.delete(:high_flap_threshold) if object[:high_flap_threshold]
  # TODO: subdue, hooks
  annotations = {}
  unless object.empty?
    annotations["sensu.io.json_attributes".to_sym] = Sensu::JSON.dump(object)
  end
  go_spec(:check, check, namespace, name, {}, annotations)
end

#translate_extension(object, namespace, name) ⇒ Object



65
66
67
68
69
# File 'lib/sensu/translator/translations.rb', line 65

def translate_extension(object, namespace, name)
  puts "Sensu 1.x extension translation is not yet supported"
  puts "Unable to translate Sensu 1.x extension: #{name} - #{object}"
  nil
end

#translate_filter(object, namespace, name) ⇒ Object



51
52
53
54
55
# File 'lib/sensu/translator/translations.rb', line 51

def translate_filter(object, namespace, name)
  puts "Sensu 1.x filter translation is not yet supported"
  puts "Unable to translate Sensu 1.x filter: #{name} #{object}"
  nil
end

#translate_handler(object, namespace, name) ⇒ Object



61
62
63
# File 'lib/sensu/translator/translations.rb', line 61

def translate_handler(object, namespace, name)
  go_spec(:handler, object, namespace, name)
end

#translate_mutator(object, namespace, name) ⇒ Object



57
58
59
# File 'lib/sensu/translator/translations.rb', line 57

def translate_mutator(object, namespace, name)
  go_spec(:mutator, object, namespace, name)
end