sensu-translator 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bd368436b5cde39a6ec79e55818d3ac5762b343e
4
- data.tar.gz: 843998e143b6968e22da0f23682d59bf40db76d5
3
+ metadata.gz: 97657180e19ead6b7b0a874db896d6a8f46270c9
4
+ data.tar.gz: 7fdb41b462dfe2890c19355f0bf8cad69edf7035
5
5
  SHA512:
6
- metadata.gz: 98673f38e12abebbcc9918e3549a1e4fa8351cf8e7a9a4c930b43afa02663c768abbec8625e92494d4d9d87048f8eb6c93482f343cf66bd9bf75876554b60f1d
7
- data.tar.gz: 68a3a06cccd948fa5feb1aebb134db99fab44cfcd81bd6681c792ee0c087514cc1d0a2b3bc7567d3ef07f16ea80dc14f22a1dd90baf0dd570af00c456f2d5016
6
+ metadata.gz: 954321b5d117b053b9f5a63c632e19eda222fdd4d99d523361fc112c45207ef62571b3c2169e91f5b9b825ca71d6cf1daf5b4a5d4364c8f248dc936ff3de5154
7
+ data.tar.gz: f7abd9874b90d062e3d4f29a1435812ecd3ee59aad87d2d081d66ecffb4328c883cd116a2494fb5ba41321f25556898cb0445786031b182fd01353c4a59e5043
data/CHANGELOG.md CHANGED
@@ -6,6 +6,16 @@ This CHANGELOG follows the format listed [here](https://github.com/sensu-plugins
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [0.4.0] - 2018-11-29
10
+
11
+ ### Changed
12
+ - Renamed Sensu 2.x -> Sensu Go
13
+ - Replaced Organization/Environment with Namespace
14
+ - Sensu Go configuration object files now include mandatory metadata
15
+
16
+ ### Added
17
+ - Custom attributes added to Go label "json_attributes"
18
+
9
19
  ## [0.3.0] - 2018-05-04
10
20
 
11
21
  ### Fixed
data/README.md CHANGED
@@ -19,9 +19,8 @@ Usage: sensu-translator [options]
19
19
  -V, --version Display version
20
20
  -c, --config FILE Sensu 1.x JSON config FILE. Default: /etc/sensu/config.json (if exists)
21
21
  -d, --config_dir DIR[,DIR] DIR or comma-delimited DIR list for Sensu 1.x JSON config files. Default: /etc/sensu/conf.d (if exists)
22
- -o, --output_dir DIR Sensu 2.0 config output DIR. Default: /tmp/sensu_v2
23
- -O, --organization ORG Sensu 2.0 RBAC Organization. Default: default
24
- -E, --environment ENV Sensu 2.0 RBAC Environment. Default: default
22
+ -o, --output_dir DIR Sensu Go config output DIR. Default: /tmp/sensu_go
23
+ -n, --namespace NAMESPACE Sensu Go Namespace. Default: default
25
24
  ```
26
25
 
27
26
  ## Example
@@ -29,11 +28,11 @@ Usage: sensu-translator [options]
29
28
  1. Translate Sensu 1.x configuration into the Sensu 2.x format
30
29
 
31
30
  ```
32
- $ sensu-translator -c /etc/sensu/config.json -d /etc/sensu/conf.d -o /tmp/sensu_v2
31
+ $ sensu-translator -c /etc/sensu/config.json -d /etc/sensu/conf.d -o /tmp/sensu_go
33
32
 
34
- $ tree /tmp/sensu_v2
33
+ $ tree /tmp/sensu_go
35
34
 
36
- /tmp/sensu_v2
35
+ /tmp/sensu_go
37
36
  ├── checks
38
37
  │   ├── website-healthz.json
39
38
  │   └── haproxy-backends.json
@@ -50,7 +49,7 @@ $ tree /tmp/sensu_v2
50
49
  2. Use a configured `sensuctl` and the newly created 2.x configuration files to manage Sensu 2.x resources
51
50
 
52
51
  ```
53
- sensuctl create -f /tmp/sensu_v2/checks/website-healthz.json
52
+ sensuctl create -f /tmp/sensu_go/checks/website-healthz.json
54
53
  ```
55
54
 
56
55
  ## Development
@@ -27,28 +27,27 @@ module Sensu
27
27
  end
28
28
 
29
29
  def translate(v1_settings)
30
- v2_resources = []
30
+ go_resources = []
31
31
  Sensu::Settings::CATEGORIES.each do |category|
32
32
  method_name = "translate_#{category.to_s.chop}"
33
- v1_settings[category].each do |name, settings|
34
- object = {:name => name.to_s}.merge(settings)
35
- v2_resources << send(method_name, object, @options[:organization], @options[:environment])
33
+ v1_settings[category].each do |name, object|
34
+ go_resources << send(method_name, object, @options[:namespace], name)
36
35
  end
37
36
  end
38
- v2_resources.compact
37
+ go_resources.compact
39
38
  end
40
39
 
41
- def create_v2_output_files!(v2_resources)
40
+ def create_go_output_files!(go_resources)
42
41
  output_dir = @options[:output_dir]
43
42
  Sensu::Settings::CATEGORIES.each do |category|
44
43
  category_dir = File.join(output_dir, category.to_s)
45
44
  FileUtils.mkdir_p(category_dir)
46
45
  end
47
- v2_resources.each do |v2_resource|
48
- category = "#{v2_resource[:type].downcase}s"
49
- file_name = "#{v2_resource[:spec][:name]}.json"
46
+ go_resources.each do |go_resource|
47
+ category = "#{go_resource[:type].downcase}s"
48
+ file_name = "#{go_resource[:spec][:name]}.json"
50
49
  output_file = File.join(output_dir, category, file_name)
51
- content = Sensu::JSON.dump(v2_resource, :pretty => true)
50
+ content = Sensu::JSON.dump(go_resource, :pretty => true)
52
51
  File.open(output_file, "w") do |file|
53
52
  file.write(content)
54
53
  end
@@ -57,8 +56,8 @@ module Sensu
57
56
 
58
57
  def run
59
58
  v1_settings = load_v1_settings
60
- v2_resources = translate(v1_settings)
61
- create_v2_output_files!(v2_resources)
59
+ go_resources = translate(v1_settings)
60
+ create_go_output_files!(go_resources)
62
61
  puts "DONE!"
63
62
  end
64
63
  end
@@ -12,9 +12,8 @@ module Sensu
12
12
  # @return [Hash] options
13
13
  def self.read(arguments=ARGV)
14
14
  options = {
15
- :output_dir => "/tmp/sensu_v2",
16
- :organization => "default",
17
- :environment => "default"
15
+ :output_dir => "/tmp/sensu_go",
16
+ :namespace => "default"
18
17
  }
19
18
  if File.exist?("/etc/sensu/config.json")
20
19
  options[:config_file] = "/etc/sensu/config.json"
@@ -37,14 +36,11 @@ module Sensu
37
36
  opts.on("-d", "--config_dir DIR[,DIR]", "DIR or comma-delimited DIR list for Sensu 1.x JSON config files. Default: /etc/sensu/conf.d (if exists)") do |dir|
38
37
  options[:config_dirs] = dir.split(",")
39
38
  end
40
- opts.on("-o", "--output_dir DIR", "Sensu 2.0 config output DIR. Default: /tmp/sensu_v2") do |dir|
39
+ opts.on("-o", "--output_dir DIR", "Sensu 2.0 config output DIR. Default: /tmp/sensu_go") do |dir|
41
40
  options[:output_dir] = dir
42
41
  end
43
- opts.on("-O", "--organization ORG", "Sensu 2.0 RBAC Organization. Default: default") do |org|
44
- options[:organization] = org
45
- end
46
- opts.on("-E", "--environment ENV", "Sensu 2.0 RBAC Environment. Default: default") do |env|
47
- options[:environment] = env
42
+ opts.on("-n", "--namespace NAMESPACE", "Sensu 2.0 Namespace. Default: default") do |namespace|
43
+ options[:namespace] = namespace
48
44
  end
49
45
  end
50
46
  optparse.parse!(arguments)
@@ -1,44 +1,69 @@
1
1
  module Sensu
2
2
  module Translator
3
3
  module Translations
4
- def v2_spec(type, object, organization, environment)
4
+ def go_spec(type, spec, namespace, name, labels={}, annotations={})
5
+ metadata = {
6
+ :namespace => namespace,
7
+ :name => name,
8
+ :labels => labels,
9
+ :annotations => annotations
10
+ }
5
11
  {
12
+ :api_version => "core/v2",
6
13
  :type => type.to_s.capitalize,
7
- :spec => object.merge(:organization => organization, :environment => environment)
14
+ :metadata => metadata,
15
+ :spec => spec
8
16
  }
9
17
  end
10
18
 
11
- def translate_check(check, organization, environment)
12
- check[:subscriptions] = check.delete(:subscribers) || []
13
- if check[:standalone]
14
- check.delete(:standalone)
15
- check[:subscriptions] << "standalone"
19
+ def translate_check(object, namespace, name)
20
+ check = {}
21
+ check[:command] = object.delete(:command)
22
+ if object[:standalone]
23
+ object.delete(:standalone)
24
+ check[:subscriptions] = ["standalone"]
25
+ else
26
+ check[:subscriptions] = object.delete(:subscribers) || []
16
27
  end
17
- check[:publish] = check.fetch(:publish, true)
18
- check[:handlers] ||= [check.fetch(:handler, "default")]
19
- if check[:source]
20
- check[:proxy_entity_id] = check.delete(:source)
28
+ publish = object.delete(:publish)
29
+ publish = true if publish.nil?
30
+ check[:publish] = publish
31
+ check[:interval] = object.delete(:interval) if object[:interval]
32
+ check[:cron] = object.delete(:cron) if object[:cron]
33
+ check[:handlers] = object.delete(:handlers) || ["default"]
34
+ check[:handlers] << object.delete(:handler) if object[:handler]
35
+ check[:handlers].uniq!
36
+ check[:proxy_entity_name] = object.delete(:source) if object[:source]
37
+ check[:stdin] = object.delete(:stdin) if object[:stdin]
38
+ check[:ttl] = object.delete(:ttl) if object[:ttl]
39
+ check[:ttl_status] = object.delete(:ttl_status) if object[:ttl_status]
40
+ check[:low_flap_threshold] = object.delete(:low_flap_threshold) if object[:low_flap_threshold]
41
+ check[:high_flap_threshold] = object.delete(:high_flap_threshold) if object[:high_flap_threshold]
42
+ # TODO: subdue, hooks
43
+ labels = {}
44
+ unless object.empty?
45
+ labels[:json_attributes] = Sensu::JSON.dump(object)
21
46
  end
22
- v2_spec(:check, check, organization, environment)
47
+ go_spec(:check, check, namespace, name, labels)
23
48
  end
24
49
 
25
- def translate_filter(filter, organization, environment)
50
+ def translate_filter(object, namespace, name)
26
51
  puts "Sensu 1.x filter translation is not yet supported"
27
- puts "Unable to translate Sensu 1.x filter: #{filter}"
52
+ puts "Unable to translate Sensu 1.x filter: #{name} - #{filter}"
28
53
  nil
29
54
  end
30
55
 
31
- def translate_mutator(mutator, organization, environment)
32
- v2_spec(:mutator, mutator, organization, environment)
56
+ def translate_mutator(object, namespace, name)
57
+ go_spec(:mutator, object, namespace, name)
33
58
  end
34
59
 
35
- def translate_handler(handler, organization, environment)
36
- v2_spec(:handler, handler, organization, environment)
60
+ def translate_handler(object, namespace, name)
61
+ go_spec(:handler, object, namespace, name)
37
62
  end
38
63
 
39
- def translate_extension(extension, organization, environment)
64
+ def translate_extension(object, namespace, name)
40
65
  puts "Sensu 1.x extension translation is not yet supported"
41
- puts "Unable to translate Sensu 1.x extension: #{extension}"
66
+ puts "Unable to translate Sensu 1.x extension: #{name} - #{extension}"
42
67
  nil
43
68
  end
44
69
  end
@@ -1,5 +1,5 @@
1
1
  module Sensu
2
2
  module Translator
3
- VERSION = "0.3.0"
3
+ VERSION = "0.4.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sensu-translator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sean Porter
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2018-05-04 00:00:00.000000000 Z
12
+ date: 2018-11-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sensu-json