sensu-translator 0.1.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 +7 -0
- data/.gitignore +12 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/CHANGELOG.md +15 -0
- data/Gemfile +6 -0
- data/LICENSE +21 -0
- data/README.md +68 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/exe/sensu-translator +6 -0
- data/lib/sensu/translator/cli.rb +55 -0
- data/lib/sensu/translator/translations.rb +46 -0
- data/lib/sensu/translator/version.rb +5 -0
- data/lib/sensu/translator.rb +69 -0
- data/sensu-translator.gemspec +30 -0
- metadata +133 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7ae7fd5222ecd1a4386de4bda4742cd2d4dc439f
|
4
|
+
data.tar.gz: efdadf8ef3c87af010c70c340b7ca66850e27fd3
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 781e2f2cf93423f8b9173c28215644370ddae8d663d5f6d3825ad72403f286e80776fae2e9d053c98be74a836ff076ba883e551fbafd443b606ab03e48b67356
|
7
|
+
data.tar.gz: 30e7636d494197da11f1ce7a1c2bf696a04338e9ea69e54b03f1bac6432b6b72e7aaad89b368be1e0fbf7b1d9f22c437d9de8607bd109653b189975f3f738849
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# Change Log
|
2
|
+
All notable changes to this project will be documented in this file.
|
3
|
+
This project adheres to [Semantic Versioning](http://semver.org/).
|
4
|
+
|
5
|
+
## [Unreleased]
|
6
|
+
|
7
|
+
## [0.1.0] - 2018-03-26
|
8
|
+
### Added
|
9
|
+
- Inital release (still experimental)
|
10
|
+
|
11
|
+
### Changed
|
12
|
+
|
13
|
+
### Fixed
|
14
|
+
|
15
|
+
### Breaking Change
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2018 Sensu
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
[](https://travis-ci.org/sensu/sensu-translator)
|
2
|
+
[](https://github.com/sensu/sensu-translator/blob/master/CHANGELOG.md)
|
3
|
+
[](https://raw.githubusercontent.com/sensu/sensu-translator/master/LICENSE)
|
4
|
+
[](https://slack.sensu.io/)
|
5
|
+
|
6
|
+
# Sensu Translator
|
7
|
+
|
8
|
+
A CLI tool for translating Sensu 1.x configuration into the Sensu 2.x format.
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
`gem install sensu-translator`
|
13
|
+
|
14
|
+
## Usage
|
15
|
+
|
16
|
+
```
|
17
|
+
Usage: sensu-translator [options]
|
18
|
+
-h, --help Display this message
|
19
|
+
-V, --version Display version
|
20
|
+
-c, --config FILE Sensu 1.x JSON config FILE. Default: /etc/sensu/config.json (if exists)
|
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
|
25
|
+
```
|
26
|
+
|
27
|
+
## Example
|
28
|
+
|
29
|
+
1. Translate Sensu 1.x configuration into the Sensu 2.x format
|
30
|
+
|
31
|
+
```
|
32
|
+
$ sensu-translator -c /etc/sensu/config.json -d /etc/sensu/conf.d -o /tmp/sensu_v2
|
33
|
+
|
34
|
+
$ tree /tmp/sensu_v2
|
35
|
+
|
36
|
+
/tmp/sensu_v2
|
37
|
+
├── checks
|
38
|
+
│ ├── website-healthz.json
|
39
|
+
│ └── haproxy-backends.json
|
40
|
+
├── extensions
|
41
|
+
├── filters
|
42
|
+
├── handlers
|
43
|
+
│ ├── email.json
|
44
|
+
│ └── default.json
|
45
|
+
└── mutators
|
46
|
+
├── obfuscate.json
|
47
|
+
└── tag.json
|
48
|
+
```
|
49
|
+
|
50
|
+
2. Use a configured `sensuctl` and the newly created 2.x configuration files to manage Sensu 2.x resources
|
51
|
+
|
52
|
+
```
|
53
|
+
sensuctl create -f /tmp/sensu_v2/checks/website-healthz.json
|
54
|
+
```
|
55
|
+
|
56
|
+
## Development
|
57
|
+
|
58
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
59
|
+
|
60
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
61
|
+
|
62
|
+
## Contributing
|
63
|
+
|
64
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/sensu/sensu-translator.
|
65
|
+
|
66
|
+
## License
|
67
|
+
|
68
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "sensu/translator"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
require "optparse"
|
2
|
+
|
3
|
+
module Sensu
|
4
|
+
module Translator
|
5
|
+
class CLI
|
6
|
+
# Parse CLI arguments using Ruby stdlib `optparse`. This method
|
7
|
+
# provides Sensu Translator with process options (eg. config
|
8
|
+
# directory), and can provide users with information, such as the
|
9
|
+
# Translator version.
|
10
|
+
#
|
11
|
+
# @param arguments [Array] to parse.
|
12
|
+
# @return [Hash] options
|
13
|
+
def self.read(arguments=ARGV)
|
14
|
+
options = {
|
15
|
+
:output_dir => "/tmp/sensu_v2",
|
16
|
+
:organization => "default",
|
17
|
+
:environment => "default"
|
18
|
+
}
|
19
|
+
if File.exist?("/etc/sensu/config.json")
|
20
|
+
options[:config_file] = "/etc/sensu/config.json"
|
21
|
+
end
|
22
|
+
if Dir.exist?("/etc/sensu/conf.d")
|
23
|
+
options[:config_dirs] = ["/etc/sensu/conf.d"]
|
24
|
+
end
|
25
|
+
optparse = OptionParser.new do |opts|
|
26
|
+
opts.on("-h", "--help", "Display this message") do
|
27
|
+
puts opts
|
28
|
+
exit
|
29
|
+
end
|
30
|
+
opts.on("-V", "--version", "Display version") do
|
31
|
+
puts Sensu::Translator::VERSION
|
32
|
+
exit
|
33
|
+
end
|
34
|
+
opts.on("-c", "--config FILE", "Sensu 1.x JSON config FILE. Default: /etc/sensu/config.json (if exists)") do |file|
|
35
|
+
options[:config_file] = file
|
36
|
+
end
|
37
|
+
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
|
+
options[:config_dirs] = dir.split(",")
|
39
|
+
end
|
40
|
+
opts.on("-o", "--output_dir DIR", "Sensu 2.0 config output DIR. Default: /tmp/sensu_v2") do |dir|
|
41
|
+
options[:output_dir] = dir
|
42
|
+
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
|
48
|
+
end
|
49
|
+
end
|
50
|
+
optparse.parse!(arguments)
|
51
|
+
options
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module Sensu
|
2
|
+
module Translator
|
3
|
+
module Translations
|
4
|
+
def v2_spec(type, object, organization, environment)
|
5
|
+
{
|
6
|
+
:type => type.to_s.capitalize,
|
7
|
+
:spec => object.merge(:organization => organization, :environment => environment)
|
8
|
+
}
|
9
|
+
end
|
10
|
+
|
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"
|
16
|
+
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)
|
21
|
+
end
|
22
|
+
v2_spec(:check, check, organization, environment)
|
23
|
+
end
|
24
|
+
|
25
|
+
def translate_filter(filter, organization, environment)
|
26
|
+
puts "Sensu 1.x filter translation is not yet supported"
|
27
|
+
puts "Unable to translate Sensu 1.x filter: #{filter}"
|
28
|
+
nil
|
29
|
+
end
|
30
|
+
|
31
|
+
def translate_mutator(mutator, organization, environment)
|
32
|
+
v2_spec(:mutator, mutator, organization, environment)
|
33
|
+
end
|
34
|
+
|
35
|
+
def translate_handler(handler, organization, environment)
|
36
|
+
v2_spec(:handler, handler, organization, environment)
|
37
|
+
end
|
38
|
+
|
39
|
+
def translate_extension(extension, organization, environment)
|
40
|
+
puts "Sensu 1.x extension translation is not yet supported"
|
41
|
+
puts "Unable to translate Sensu 1.x extension: #{extension}"
|
42
|
+
nil
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
gem "sensu-json", "2.1.1"
|
2
|
+
gem "sensu-settings", "10.13.1"
|
3
|
+
|
4
|
+
require "sensu/translator/cli"
|
5
|
+
require "sensu/translator/translations"
|
6
|
+
require "sensu/translator/version"
|
7
|
+
|
8
|
+
require "sensu/json"
|
9
|
+
require "sensu/settings"
|
10
|
+
|
11
|
+
require "fileutils"
|
12
|
+
|
13
|
+
module Sensu
|
14
|
+
module Translator
|
15
|
+
class Runner
|
16
|
+
include Translations
|
17
|
+
|
18
|
+
def initialize
|
19
|
+
@options = CLI.read
|
20
|
+
end
|
21
|
+
|
22
|
+
def load_v1_settings
|
23
|
+
settings = Sensu::Settings.load(@options)
|
24
|
+
unless settings.errors.empty?
|
25
|
+
puts "Sensu 1.x configuration is invalid!"
|
26
|
+
puts Sensu::JSON.dump({:errors => settings.errors}, :pretty => true)
|
27
|
+
exit 2
|
28
|
+
end
|
29
|
+
settings.to_hash
|
30
|
+
end
|
31
|
+
|
32
|
+
def translate(v1_settings)
|
33
|
+
v2_resources = []
|
34
|
+
Sensu::Settings::CATEGORIES.each do |category|
|
35
|
+
method_name = "translate_#{category.to_s.chop}"
|
36
|
+
v1_settings[category].each do |name, settings|
|
37
|
+
object = {:name => name.to_s}.merge(settings)
|
38
|
+
v2_resources << send(method_name, object, @options[:organization], @options[:environment])
|
39
|
+
end
|
40
|
+
end
|
41
|
+
v2_resources.compact
|
42
|
+
end
|
43
|
+
|
44
|
+
def create_v2_output_files!(v2_resources)
|
45
|
+
output_dir = @options[:output_dir]
|
46
|
+
Sensu::Settings::CATEGORIES.each do |category|
|
47
|
+
category_dir = File.join(output_dir, category.to_s)
|
48
|
+
FileUtils.mkdir_p(category_dir)
|
49
|
+
end
|
50
|
+
v2_resources.each do |v2_resource|
|
51
|
+
category = "#{v2_resource[:type].downcase}s"
|
52
|
+
file_name = "#{v2_resource[:spec][:name]}.json"
|
53
|
+
output_file = File.join(output_dir, category, file_name)
|
54
|
+
content = Sensu::JSON.dump(v2_resource, :pretty => true)
|
55
|
+
File.open(output_file, "w") do |file|
|
56
|
+
file.write(content)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def run
|
62
|
+
v1_settings = load_v1_settings
|
63
|
+
v2_resources = translate(v1_settings)
|
64
|
+
create_v2_output_files!(v2_resources)
|
65
|
+
puts "DONE!"
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "sensu/translator/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "sensu-translator"
|
8
|
+
spec.version = Sensu::Translator::VERSION
|
9
|
+
spec.authors = ["Sean Porter", "Justin Kolberg"]
|
10
|
+
spec.email = ["portertech@gmail.com", "amd.prophet@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{A tool for translating Sensu 1.x config to the Sensu 2.x format.}
|
13
|
+
spec.description = %q{A tool for translating Sensu 1.x config to the Sensu 2.x format.}
|
14
|
+
spec.homepage = "https://github.com/sensu/sensu-translator"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
19
|
+
end
|
20
|
+
spec.bindir = "exe"
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
|
24
|
+
spec.add_dependency "sensu-json", "2.1.1"
|
25
|
+
spec.add_dependency "sensu-settings", "10.13.1"
|
26
|
+
|
27
|
+
spec.add_development_dependency "bundler", "~> 1.15"
|
28
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
29
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,133 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sensu-translator
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sean Porter
|
8
|
+
- Justin Kolberg
|
9
|
+
autorequire:
|
10
|
+
bindir: exe
|
11
|
+
cert_chain: []
|
12
|
+
date: 2018-03-27 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: sensu-json
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - '='
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: 2.1.1
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - '='
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: 2.1.1
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: sensu-settings
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - '='
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: 10.13.1
|
35
|
+
type: :runtime
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - '='
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: 10.13.1
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: bundler
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - "~>"
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '1.15'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - "~>"
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '1.15'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: rake
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - "~>"
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '10.0'
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - "~>"
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '10.0'
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: rspec
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - "~>"
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '3.0'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - "~>"
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '3.0'
|
84
|
+
description: A tool for translating Sensu 1.x config to the Sensu 2.x format.
|
85
|
+
email:
|
86
|
+
- portertech@gmail.com
|
87
|
+
- amd.prophet@gmail.com
|
88
|
+
executables:
|
89
|
+
- sensu-translator
|
90
|
+
extensions: []
|
91
|
+
extra_rdoc_files: []
|
92
|
+
files:
|
93
|
+
- ".gitignore"
|
94
|
+
- ".rspec"
|
95
|
+
- ".travis.yml"
|
96
|
+
- CHANGELOG.md
|
97
|
+
- Gemfile
|
98
|
+
- LICENSE
|
99
|
+
- README.md
|
100
|
+
- Rakefile
|
101
|
+
- bin/console
|
102
|
+
- bin/setup
|
103
|
+
- exe/sensu-translator
|
104
|
+
- lib/sensu/translator.rb
|
105
|
+
- lib/sensu/translator/cli.rb
|
106
|
+
- lib/sensu/translator/translations.rb
|
107
|
+
- lib/sensu/translator/version.rb
|
108
|
+
- sensu-translator.gemspec
|
109
|
+
homepage: https://github.com/sensu/sensu-translator
|
110
|
+
licenses:
|
111
|
+
- MIT
|
112
|
+
metadata: {}
|
113
|
+
post_install_message:
|
114
|
+
rdoc_options: []
|
115
|
+
require_paths:
|
116
|
+
- lib
|
117
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
118
|
+
requirements:
|
119
|
+
- - ">="
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: '0'
|
122
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
123
|
+
requirements:
|
124
|
+
- - ">="
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: '0'
|
127
|
+
requirements: []
|
128
|
+
rubyforge_project:
|
129
|
+
rubygems_version: 2.6.11
|
130
|
+
signing_key:
|
131
|
+
specification_version: 4
|
132
|
+
summary: A tool for translating Sensu 1.x config to the Sensu 2.x format.
|
133
|
+
test_files: []
|