sensu-translator 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -0
- data/README.md +6 -7
- data/lib/sensu/translator.rb +11 -12
- data/lib/sensu/translator/cli.rb +5 -9
- data/lib/sensu/translator/translations.rb +45 -20
- data/lib/sensu/translator/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 97657180e19ead6b7b0a874db896d6a8f46270c9
|
4
|
+
data.tar.gz: 7fdb41b462dfe2890c19355f0bf8cad69edf7035
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
23
|
-
-
|
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/
|
31
|
+
$ sensu-translator -c /etc/sensu/config.json -d /etc/sensu/conf.d -o /tmp/sensu_go
|
33
32
|
|
34
|
-
$ tree /tmp/
|
33
|
+
$ tree /tmp/sensu_go
|
35
34
|
|
36
|
-
/tmp/
|
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/
|
52
|
+
sensuctl create -f /tmp/sensu_go/checks/website-healthz.json
|
54
53
|
```
|
55
54
|
|
56
55
|
## Development
|
data/lib/sensu/translator.rb
CHANGED
@@ -27,28 +27,27 @@ module Sensu
|
|
27
27
|
end
|
28
28
|
|
29
29
|
def translate(v1_settings)
|
30
|
-
|
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,
|
34
|
-
object
|
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
|
-
|
37
|
+
go_resources.compact
|
39
38
|
end
|
40
39
|
|
41
|
-
def
|
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
|
-
|
48
|
-
category = "#{
|
49
|
-
file_name = "#{
|
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(
|
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
|
-
|
61
|
-
|
59
|
+
go_resources = translate(v1_settings)
|
60
|
+
create_go_output_files!(go_resources)
|
62
61
|
puts "DONE!"
|
63
62
|
end
|
64
63
|
end
|
data/lib/sensu/translator/cli.rb
CHANGED
@@ -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/
|
16
|
-
:
|
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/
|
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("-
|
44
|
-
options[:
|
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
|
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
|
-
:
|
14
|
+
:metadata => metadata,
|
15
|
+
:spec => spec
|
8
16
|
}
|
9
17
|
end
|
10
18
|
|
11
|
-
def translate_check(
|
12
|
-
check
|
13
|
-
|
14
|
-
|
15
|
-
|
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
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
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
|
-
|
47
|
+
go_spec(:check, check, namespace, name, labels)
|
23
48
|
end
|
24
49
|
|
25
|
-
def translate_filter(
|
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(
|
32
|
-
|
56
|
+
def translate_mutator(object, namespace, name)
|
57
|
+
go_spec(:mutator, object, namespace, name)
|
33
58
|
end
|
34
59
|
|
35
|
-
def translate_handler(
|
36
|
-
|
60
|
+
def translate_handler(object, namespace, name)
|
61
|
+
go_spec(:handler, object, namespace, name)
|
37
62
|
end
|
38
63
|
|
39
|
-
def translate_extension(
|
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
|
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.
|
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-
|
12
|
+
date: 2018-11-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: sensu-json
|