sensu-translator 0.3.0 → 1.2.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 +5 -5
- data/.gitignore +1 -0
- data/CHANGELOG.md +34 -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 +48 -20
- data/lib/sensu/translator/version.rb +1 -1
- data/sensu-translator.gemspec +1 -1
- metadata +7 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 650c8cdfabbe7a3c6f8fd224a4655d6ff6208e8e1e6ada2f2b01e6223883cc9e
|
4
|
+
data.tar.gz: af0978bded782e6c6cc0c52cd86efb5cfadaa5f3592e7ca9e988105c553d05af
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d3210d02ec78544877a61f2d34128942dae1934056a0c80e0de064891e7342b3a5d5376ee7ae794140dc6901e9ec3dc4e250d2e2049416de2aba00bd07173b49
|
7
|
+
data.tar.gz: 1514ebcfc57391505e1365a9bf1dd7f9467e676171b1d2b16099d942e9a73fc36001ceac9fd5347454057e6352ed18857981ef80a67226904f99ee508340bc1d
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
@@ -6,6 +6,40 @@ This CHANGELOG follows the format listed [here](https://github.com/sensu-plugins
|
|
6
6
|
|
7
7
|
## [Unreleased]
|
8
8
|
|
9
|
+
## [1.2.0] - 2021-03-10
|
10
|
+
### Added
|
11
|
+
- Translate check pager_team to the pagerduty plugin config team annotation
|
12
|
+
|
13
|
+
## [1.1.0] - 2020-02-19
|
14
|
+
### Added
|
15
|
+
- Translate check occurrences and refresh to fatigue_check annotations
|
16
|
+
|
17
|
+
## [1.0.1] - 2018-12-18
|
18
|
+
|
19
|
+
### Fixed
|
20
|
+
- Now getting Sensu Go config file name from object metadata
|
21
|
+
- Check timeout no longer treated as custom
|
22
|
+
- Unable to translate log lines now include object inspection
|
23
|
+
|
24
|
+
## [1.0.0] - 2018-12-04
|
25
|
+
|
26
|
+
### Changed
|
27
|
+
- Now using an annotation for json_attributes instead of a label
|
28
|
+
- Namespaced the json_attributes annotation, sensu.io.*
|
29
|
+
|
30
|
+
### Added
|
31
|
+
- Custom attributes added to Go label "json_attributes"
|
32
|
+
|
33
|
+
## [0.4.0] - 2018-11-29
|
34
|
+
|
35
|
+
### Changed
|
36
|
+
- Renamed Sensu 2.x -> Sensu Go
|
37
|
+
- Replaced Organization/Environment with Namespace
|
38
|
+
- Sensu Go configuration object files now include mandatory metadata
|
39
|
+
|
40
|
+
### Added
|
41
|
+
- Custom attributes added to Go label "json_attributes"
|
42
|
+
|
9
43
|
## [0.3.0] - 2018-05-04
|
10
44
|
|
11
45
|
### 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[:metadata][: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,72 @@
|
|
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[:timeout] = object.delete(:timeout) if object[:timeout]
|
39
|
+
check[:ttl] = object.delete(:ttl) if object[:ttl]
|
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
|
+
annotations = {}
|
44
|
+
unless object.empty?
|
45
|
+
annotations["sensu.io.json_attributes".to_sym] = Sensu::JSON.dump(object)
|
21
46
|
end
|
22
|
-
|
47
|
+
annotations["fatigue_check/occurrences"] = object[:occurrences].to_s if object[:occurrences]
|
48
|
+
annotations["fatigue_check/interval"] = object[:refresh].to_s if object[:refresh]
|
49
|
+
annotations["sensu.io/plugins/sensu-pagerduty-handler/config/team"] = object[:pager_team].to_s if object[:pager_team]
|
50
|
+
go_spec(:check, check, namespace, name, {}, annotations)
|
23
51
|
end
|
24
52
|
|
25
|
-
def translate_filter(
|
53
|
+
def translate_filter(object, namespace, name)
|
26
54
|
puts "Sensu 1.x filter translation is not yet supported"
|
27
|
-
puts "Unable to translate Sensu 1.x filter: #{
|
55
|
+
puts "Unable to translate Sensu 1.x filter: #{name} #{object}"
|
28
56
|
nil
|
29
57
|
end
|
30
58
|
|
31
|
-
def translate_mutator(
|
32
|
-
|
59
|
+
def translate_mutator(object, namespace, name)
|
60
|
+
go_spec(:mutator, object, namespace, name)
|
33
61
|
end
|
34
62
|
|
35
|
-
def translate_handler(
|
36
|
-
|
63
|
+
def translate_handler(object, namespace, name)
|
64
|
+
go_spec(:handler, object, namespace, name)
|
37
65
|
end
|
38
66
|
|
39
|
-
def translate_extension(
|
67
|
+
def translate_extension(object, namespace, name)
|
40
68
|
puts "Sensu 1.x extension translation is not yet supported"
|
41
|
-
puts "Unable to translate Sensu 1.x extension: #{
|
69
|
+
puts "Unable to translate Sensu 1.x extension: #{name} - #{object}"
|
42
70
|
nil
|
43
71
|
end
|
44
72
|
end
|
data/sensu-translator.gemspec
CHANGED
@@ -24,7 +24,7 @@ Gem::Specification.new do |spec|
|
|
24
24
|
spec.add_dependency "sensu-json", ">= 2.1.1"
|
25
25
|
spec.add_dependency "sensu-settings", ">= 10.13.1"
|
26
26
|
|
27
|
-
spec.add_development_dependency "bundler"
|
27
|
+
spec.add_development_dependency "bundler"
|
28
28
|
spec.add_development_dependency "rake", "~> 10.0"
|
29
29
|
spec.add_development_dependency "rspec", "~> 3.0"
|
30
30
|
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:
|
4
|
+
version: 1.2.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:
|
12
|
+
date: 2021-03-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: sensu-json
|
@@ -43,16 +43,16 @@ dependencies:
|
|
43
43
|
name: bundler
|
44
44
|
requirement: !ruby/object:Gem::Requirement
|
45
45
|
requirements:
|
46
|
-
- - "
|
46
|
+
- - ">="
|
47
47
|
- !ruby/object:Gem::Version
|
48
|
-
version: '
|
48
|
+
version: '0'
|
49
49
|
type: :development
|
50
50
|
prerelease: false
|
51
51
|
version_requirements: !ruby/object:Gem::Requirement
|
52
52
|
requirements:
|
53
|
-
- - "
|
53
|
+
- - ">="
|
54
54
|
- !ruby/object:Gem::Version
|
55
|
-
version: '
|
55
|
+
version: '0'
|
56
56
|
- !ruby/object:Gem::Dependency
|
57
57
|
name: rake
|
58
58
|
requirement: !ruby/object:Gem::Requirement
|
@@ -125,8 +125,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
125
125
|
- !ruby/object:Gem::Version
|
126
126
|
version: '0'
|
127
127
|
requirements: []
|
128
|
-
|
129
|
-
rubygems_version: 2.6.11
|
128
|
+
rubygems_version: 3.1.2
|
130
129
|
signing_key:
|
131
130
|
specification_version: 4
|
132
131
|
summary: A tool for translating Sensu 1.x config to the Sensu 2.x format.
|