fluent-format 0.1.1 → 0.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 +4 -4
- data/CHANGELOG.md +7 -0
- data/README.md +20 -2
- data/example/syntax_error.conf +3 -0
- data/example/unknown_plugin.conf +3 -0
- data/lib/fluent/format/check.rb +68 -0
- data/lib/fluent/format/cli.rb +16 -5
- data/lib/fluent/format/format.rb +47 -0
- data/lib/fluent/format/version.rb +1 -1
- data/lib/fluent/format.rb +15 -35
- data/lib/fluent-format.rb +3 -0
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 885cab275f6fb1fd2c3985502fe7c4af090e04f3
|
4
|
+
data.tar.gz: 7bed0b502af72155bec463042b4c76897478cc93
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 97d236a5c5afa4a85d568856f254f35c991e0def0721651e776ed543c8492ea9e84921dc03ce006ff10556d5c169311e7e6ce49c3354743960dda61cd07e975d
|
7
|
+
data.tar.gz: abf9334f02803e4a628711c6fb639f2d0470720c519be167e87c830a908f806ed8b5feefbbae84d2ad042bdbd553552e033c09f4faa0fc09db72880f545d49c8
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -16,9 +16,27 @@ Or install it yourself as:
|
|
16
16
|
|
17
17
|
$ gem install fluent-format
|
18
18
|
|
19
|
-
|
19
|
+
## Command Line Interface
|
20
20
|
|
21
|
-
|
21
|
+
Format fluent.conf
|
22
|
+
|
23
|
+
$ fluent-format -c fluent.conf
|
24
|
+
|
25
|
+
Check fluent.conf
|
26
|
+
|
27
|
+
$ fluent-format check -c fluent.conf -p plugin_dir
|
28
|
+
$ echo $? # 0: success 1: failure
|
29
|
+
|
30
|
+
## As a library
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
require 'fluent-format'
|
34
|
+
|
35
|
+
File.open(path) {|config|
|
36
|
+
puts Fluent::Format.format(config) # formatted string
|
37
|
+
puts Fluent::Format.check(config, plugin_dir) #=> true: success false: failure
|
38
|
+
}
|
39
|
+
```
|
22
40
|
|
23
41
|
## ToDo
|
24
42
|
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'fluent/supervisor'
|
2
|
+
|
3
|
+
module Fluent
|
4
|
+
class Format
|
5
|
+
class Check
|
6
|
+
# Initialize
|
7
|
+
#
|
8
|
+
# @param [IO|String] config_dev
|
9
|
+
# @param [String] plugin_dir the plugin directory
|
10
|
+
def initialize(config_dev, plugin_dir = nil)
|
11
|
+
@opts = {
|
12
|
+
:config_path => config_dev, # Fluent::DEFAULT_CONFIG_PATH,
|
13
|
+
:plugin_dirs => [Fluent::DEFAULT_PLUGIN_DIR],
|
14
|
+
:log_level => Fluent::Log::LEVEL_INFO,
|
15
|
+
:log_path => nil,
|
16
|
+
:daemonize => false,
|
17
|
+
:libs => [],
|
18
|
+
:setup_path => nil,
|
19
|
+
:chuser => nil,
|
20
|
+
:chgroup => nil,
|
21
|
+
:suppress_interval => 0,
|
22
|
+
:suppress_repeated_stacktrace => false,
|
23
|
+
}
|
24
|
+
@opts[:plugin_dirs] << plugin_dir if plugin_dir
|
25
|
+
end
|
26
|
+
|
27
|
+
# Check config file
|
28
|
+
#
|
29
|
+
# @return [Boolean]
|
30
|
+
def run
|
31
|
+
Fluent::Supervisor.new(@opts).ext_dry_run
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
module Fluent
|
38
|
+
class Supervisor
|
39
|
+
# Extended to accept IO object
|
40
|
+
def ext_dry_run
|
41
|
+
ext_read_config
|
42
|
+
change_privilege
|
43
|
+
init_engine
|
44
|
+
install_main_process_signal_handlers
|
45
|
+
run_configure
|
46
|
+
true
|
47
|
+
rescue => e
|
48
|
+
false
|
49
|
+
end
|
50
|
+
|
51
|
+
# Extended to accept IO object
|
52
|
+
def ext_read_config
|
53
|
+
if @config_path.respond_to?(:read) # IO object
|
54
|
+
@config_data = @config_path.read
|
55
|
+
else
|
56
|
+
$log.info "reading config file", :path=>@config_path
|
57
|
+
@config_fname = File.basename(@config_path)
|
58
|
+
@config_basedir = File.dirname(@config_path)
|
59
|
+
@config_data = File.read(@config_path)
|
60
|
+
end
|
61
|
+
if @inline_config == '-'
|
62
|
+
@config_data << "\n" << STDIN.read
|
63
|
+
elsif @inline_config
|
64
|
+
@config_data << "\n" << @inline_config.gsub("\\n","\n")
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
data/lib/fluent/format/cli.rb
CHANGED
@@ -4,13 +4,24 @@ require_relative '../../fluent-format'
|
|
4
4
|
module Fluent
|
5
5
|
class Format
|
6
6
|
class CLI < Thor
|
7
|
-
default_command :
|
8
|
-
desc "
|
7
|
+
default_command :format
|
8
|
+
desc "format", "Format fluent.conf"
|
9
9
|
option :config, :aliases => ["-c"], :type => :string, :default => 'fluent.conf', :desc => 'Fluentd configuration file'
|
10
|
-
def
|
10
|
+
def format
|
11
11
|
config = @options[:config]
|
12
|
-
|
13
|
-
|
12
|
+
puts Fluent::Format.format(config)
|
13
|
+
rescue => e
|
14
|
+
$log.error "#{e.class}: #{e}"
|
15
|
+
exit 1
|
16
|
+
end
|
17
|
+
|
18
|
+
desc "check", "Check fluent.conf"
|
19
|
+
option :config, :aliases => ["-c"], :type => :string, :default => 'fluent.conf', :desc => 'Fluentd configuration file'
|
20
|
+
option :plugin, :aliases => ["-p"], :type => :string, :desc => 'Fluentd plugin directory'
|
21
|
+
def check
|
22
|
+
config = @options[:config]
|
23
|
+
plugin = @options[:plugin]
|
24
|
+
Fluent::Format.check(config, plugin) || exit(1)
|
14
25
|
rescue => e
|
15
26
|
$log.error "#{e.class}: #{e}"
|
16
27
|
exit 1
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module Fluent
|
2
|
+
class Format
|
3
|
+
class Format
|
4
|
+
# Initialize
|
5
|
+
#
|
6
|
+
# @param [IO|String] config_dev
|
7
|
+
def initialize(config_dev)
|
8
|
+
@config_dev = config_dev
|
9
|
+
end
|
10
|
+
|
11
|
+
# Format config
|
12
|
+
#
|
13
|
+
# @return [String] the formatted config
|
14
|
+
def run
|
15
|
+
config = read_config(@config_dev)
|
16
|
+
indent_config(config)
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
# partial copy from lib/fluent/config.rb
|
22
|
+
def read_config(dev)
|
23
|
+
if dev.respond_to?(:read) # IO object
|
24
|
+
parse_config(dev, '-', '-')
|
25
|
+
else
|
26
|
+
File.open(dev) {|io| parse_config(io, File.basename(dev), File.dirname(dev)) }
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
# partial copy from lib/fluent/config.rb
|
31
|
+
def parse_config(io, fname, basepath=Dir.pwd)
|
32
|
+
if fname =~ /\.rb$/
|
33
|
+
Fluent::Config::DSL::Parser.parse(io, File.join(basepath, fname))
|
34
|
+
else
|
35
|
+
Fluent::Config.parse(io, fname, basepath)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
# hmm, ugly workaround
|
40
|
+
def indent_config(conf)
|
41
|
+
lines = conf.to_s.split("\n")[1..-2] # remove <ROOT> and </ROOT>
|
42
|
+
lines = lines.map {|line| line[2..-1] } # remove heading 2 white spaces
|
43
|
+
lines.join("\n")
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
data/lib/fluent/format.rb
CHANGED
@@ -1,42 +1,22 @@
|
|
1
|
-
|
1
|
+
$log = Fluent::Log.new(STDERR, Fluent::Log::LEVEL_WARN)
|
2
2
|
|
3
3
|
module Fluent
|
4
4
|
class Format
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
end
|
13
|
-
indent_config(config)
|
14
|
-
end
|
15
|
-
|
16
|
-
private
|
17
|
-
|
18
|
-
# partial copy from lib/fluent/config.rb
|
19
|
-
def read_config(path)
|
20
|
-
File.open(path) {|io|
|
21
|
-
parse_config(io, File.basename(path), File.dirname(path))
|
22
|
-
}
|
23
|
-
end
|
24
|
-
|
25
|
-
# partial copy from lib/fluent/config.rb
|
26
|
-
def parse_config(io, fname, basepath=Dir.pwd)
|
27
|
-
if fname =~ /\.rb$/
|
28
|
-
Fluent::Config::DSL::Parser.parse(io, File.join(basepath, fname))
|
29
|
-
else
|
30
|
-
Fluent::Config.parse(io, fname, basepath)
|
31
|
-
end
|
32
|
-
end
|
5
|
+
# Format config file
|
6
|
+
#
|
7
|
+
# @param [IO|String] config_dev
|
8
|
+
# @return [String] the formatted config
|
9
|
+
def self.format(config_dev)
|
10
|
+
Fluent::Format::Format.new(config_dev).run
|
11
|
+
end
|
33
12
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
13
|
+
# Check config file
|
14
|
+
#
|
15
|
+
# @param [IO|String] config_dev
|
16
|
+
# @param [String] plugin_dir the plugin directory
|
17
|
+
# @return [Boolean]
|
18
|
+
def self.check(config_dev, plugin_dir = nil)
|
19
|
+
Fluent::Format::Check.new(config_dev, plugin_dir).run
|
40
20
|
end
|
41
21
|
end
|
42
22
|
end
|
data/lib/fluent-format.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-format
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Naotoshi Seo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-02-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -111,11 +111,15 @@ files:
|
|
111
111
|
- README.md
|
112
112
|
- Rakefile
|
113
113
|
- bin/fluent-format
|
114
|
+
- example/syntax_error.conf
|
115
|
+
- example/unknown_plugin.conf
|
114
116
|
- fluent-format.gemspec
|
115
117
|
- fluent.conf
|
116
118
|
- lib/fluent-format.rb
|
117
119
|
- lib/fluent/format.rb
|
120
|
+
- lib/fluent/format/check.rb
|
118
121
|
- lib/fluent/format/cli.rb
|
122
|
+
- lib/fluent/format/format.rb
|
119
123
|
- lib/fluent/format/version.rb
|
120
124
|
homepage: https://github.com/sonots/fluent-format
|
121
125
|
licenses:
|