fluent-plugin-specinfra_inventory 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -1
- data/README.md +17 -2
- data/Rakefile +1 -1
- data/lib/fluent/plugin/in_specinfra_inventory.rb +35 -1
- data/lib/fluent/plugin/specinfra_inventory/version.rb +1 -1
- data/spec/in_specinfra_inventory_spec.rb +37 -3
- data/spec/spec_helper.rb +2 -76
- metadata +2 -3
- data/.rspec +0 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3c9298f6319f6d53a76d0df249610c062c8f943c
|
4
|
+
data.tar.gz: 8c9ec9f5d57893d19f15e70500781bc765f5ac9d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 45ed2d49b08f0172b6c9af7a93a667566503cfd66a12b3f9e5ff7f5b8eff63cc3ff5ebd9f7bb613acc37fa2c19fe915b9cb64a8aedbf8ce73807e3cebe0bd2f0
|
7
|
+
data.tar.gz: d1b88e2d21aa0e83f8120dd36716da03fb255b6f9f33b03cbe50c110ab9984289f33b981c8ec6c5990abeed86a1ec71ef4238b0b0f7c3043aa7e945aba74faa1
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
## 0.2.0
|
2
|
+
|
3
|
+
* Add `cast_num` option
|
4
|
+
* Add `cast_byte` option
|
5
|
+
* Add `cast_percent` option
|
6
|
+
|
1
7
|
## 0.1.0
|
2
8
|
|
3
9
|
* Change default value of `inventory_keys` option
|
@@ -5,7 +11,7 @@
|
|
5
11
|
|
6
12
|
## 0.0.5
|
7
13
|
|
8
|
-
* Add combine option
|
14
|
+
* Add `combine` option
|
9
15
|
|
10
16
|
## 0.0.4
|
11
17
|
|
data/README.md
CHANGED
@@ -29,6 +29,9 @@ Or install it yourself as:
|
|
29
29
|
inventory_keys ["cpu.total","memory"]
|
30
30
|
combine false
|
31
31
|
family ubuntu
|
32
|
+
cast_num true
|
33
|
+
cast_byte true
|
34
|
+
cast_percent true
|
32
35
|
release 14.04
|
33
36
|
arch x86_64
|
34
37
|
path /user/local/bin
|
@@ -45,8 +48,8 @@ defualt: `60`
|
|
45
48
|
|
46
49
|
### tag_prefix
|
47
50
|
Prefix of tags of events.
|
48
|
-
Event tags are added together inventory key at the end
|
49
|
-
If you set `true` to `combine` option, It does not added the key at the end.
|
51
|
+
Event tags are added together inventory key at the end(like: `example.prefix.cpu`)
|
52
|
+
If you set `true` to `combine` option, It does not added the key at the end.
|
50
53
|
default: `specinfra.inventory`
|
51
54
|
|
52
55
|
### backend
|
@@ -62,6 +65,18 @@ default: All available keys of `Specinfra::HostInventory`
|
|
62
65
|
Combining values of `inventory_keys` to one record.
|
63
66
|
default: `true`
|
64
67
|
|
68
|
+
### cast_num
|
69
|
+
Cast all number value to integer.
|
70
|
+
default: `false`
|
71
|
+
|
72
|
+
### cast_byte
|
73
|
+
Cast all byte value(like `512KB`) to integer.
|
74
|
+
default: `false`
|
75
|
+
|
76
|
+
### cast_percent
|
77
|
+
Cast all percentile value(like `50%`) to integer.
|
78
|
+
default: `false`
|
79
|
+
|
65
80
|
### family, release, arch
|
66
81
|
See [Multi OS Support](http://serverspec.org/tutorial.html)
|
67
82
|
|
data/Rakefile
CHANGED
@@ -15,6 +15,9 @@ module Fluent
|
|
15
15
|
config_param :env, :hash, default: {}
|
16
16
|
config_param :inventory_keys, :array, default: []
|
17
17
|
config_param :combine, :bool, default: true
|
18
|
+
config_param :cast_num, :bool, default: false
|
19
|
+
config_param :cast_byte, :bool, default: false
|
20
|
+
config_param :cast_percent, :bool, default: false
|
18
21
|
|
19
22
|
KEY_DELIMITER = "."
|
20
23
|
|
@@ -95,8 +98,39 @@ module Fluent
|
|
95
98
|
key.split(KEY_DELIMITER).each do |k|
|
96
99
|
inv = inv[k]
|
97
100
|
end
|
98
|
-
{key => inv}
|
101
|
+
{key => cast(inv)}
|
99
102
|
end
|
100
103
|
|
104
|
+
def cast(inv)
|
105
|
+
if @cast_num || @cast_byte || @cast_percent
|
106
|
+
if inv.is_a?(Hash)
|
107
|
+
inv = Hash[inv.map { |k,v| [k, cast(v)] }]
|
108
|
+
elsif inv.is_a?(Array)
|
109
|
+
inv = inv.map do |v|
|
110
|
+
v = cast(v)
|
111
|
+
end
|
112
|
+
else
|
113
|
+
inv = _cast_num(inv) if @cast_num && inv.is_a?(String)
|
114
|
+
inv = _cast_byte(inv) if @cast_byte && inv.is_a?(String)
|
115
|
+
inv = _cast_percent(inv) if @cast_percent && inv.is_a?(String)
|
116
|
+
end
|
117
|
+
end
|
118
|
+
inv
|
119
|
+
end
|
120
|
+
|
121
|
+
def _cast_num(v)
|
122
|
+
m = v.match(/^([1-9]\d*|0)$/)
|
123
|
+
m.nil? ? v : m[0].to_i
|
124
|
+
end
|
125
|
+
|
126
|
+
def _cast_byte(v)
|
127
|
+
m = v.match(/^(\d+)(kb|KB)$/)
|
128
|
+
m.nil? ? v : m[0].to_i * 1000
|
129
|
+
end
|
130
|
+
|
131
|
+
def _cast_percent(v)
|
132
|
+
m = v.match(/^(\d+)%$/)
|
133
|
+
m.nil? ? v : m[0].to_i
|
134
|
+
end
|
101
135
|
end
|
102
136
|
end
|
@@ -9,7 +9,8 @@ describe Fluent::SpecinfraInventoryInput do
|
|
9
9
|
'cpu' => {
|
10
10
|
'total' => "2",
|
11
11
|
'0' => {
|
12
|
-
'vendor_id' => "1"
|
12
|
+
'vendor_id' => "1",
|
13
|
+
'cache_size' => "512KB"
|
13
14
|
}
|
14
15
|
}
|
15
16
|
}
|
@@ -28,6 +29,10 @@ describe Fluent::SpecinfraInventoryInput do
|
|
28
29
|
host localhost
|
29
30
|
ssh_user test-user
|
30
31
|
ssh_port 2222
|
32
|
+
combine false
|
33
|
+
cast_num true
|
34
|
+
cast_byte true
|
35
|
+
cast_percent true
|
31
36
|
env {"TEST_ENV": "test_value"}
|
32
37
|
]
|
33
38
|
end
|
@@ -44,6 +49,10 @@ describe Fluent::SpecinfraInventoryInput do
|
|
44
49
|
example { expect(@d.instance.host).to eq "localhost" }
|
45
50
|
example { expect(@d.instance.ssh_user).to eq "test-user" }
|
46
51
|
example { expect(@d.instance.ssh_port).to eq 2222 }
|
52
|
+
example { expect(@d.instance.combine).to eq false }
|
53
|
+
example { expect(@d.instance.cast_num).to eq true }
|
54
|
+
example { expect(@d.instance.cast_byte).to eq true }
|
55
|
+
example { expect(@d.instance.cast_percent).to eq true }
|
47
56
|
example { expect(@d.instance.env).to include('TEST_ENV' => 'test_value') }
|
48
57
|
end
|
49
58
|
|
@@ -52,10 +61,35 @@ describe Fluent::SpecinfraInventoryInput do
|
|
52
61
|
end
|
53
62
|
|
54
63
|
describe "record on flat hash" do
|
55
|
-
example { expect(@d.instance.record("cpu")['cpu']).to include('total' =>
|
64
|
+
example { expect(@d.instance.record("cpu")['cpu']).to include('total' => 2) }
|
56
65
|
end
|
57
66
|
|
58
67
|
describe "record on nested hash" do
|
59
|
-
example { expect(@d.instance.record("cpu.0")['cpu.0']).to include('vendor_id' =>
|
68
|
+
example { expect(@d.instance.record("cpu.0")['cpu.0']).to include('vendor_id' => 1) }
|
69
|
+
example { expect(@d.instance.record("cpu.0")['cpu.0']).to include('cache_size' => 512000) }
|
70
|
+
end
|
71
|
+
|
72
|
+
describe "cast_num" do
|
73
|
+
example { expect(@d.instance._cast_num("0")).to eq 0 }
|
74
|
+
example { expect(@d.instance._cast_num("1")).to eq 1 }
|
75
|
+
example { expect(@d.instance._cast_num("109")).to eq 109 }
|
76
|
+
example { expect(@d.instance._cast_num("01")).to eq "01" }
|
77
|
+
example { expect(@d.instance._cast_num("test")).to eq "test" }
|
78
|
+
end
|
79
|
+
|
80
|
+
describe "cast_byte" do
|
81
|
+
example { expect(@d.instance._cast_byte("12")).to eq "12" }
|
82
|
+
example { expect(@d.instance._cast_byte("0kb")).to eq 0 }
|
83
|
+
example { expect(@d.instance._cast_byte("99kb")).to eq 99000 }
|
84
|
+
example { expect(@d.instance._cast_byte("akb")).to eq "akb" }
|
85
|
+
example { expect(@d.instance._cast_byte("1%")).to eq "1%" }
|
86
|
+
end
|
87
|
+
|
88
|
+
describe "cast_percent" do
|
89
|
+
example { expect(@d.instance._cast_percent("99")).to eq "99" }
|
90
|
+
example { expect(@d.instance._cast_percent("77%")).to eq 77 }
|
91
|
+
example { expect(@d.instance._cast_percent("0%")).to eq 0 }
|
92
|
+
example { expect(@d.instance._cast_percent("percent")).to eq "percent" }
|
93
|
+
example { expect(@d.instance._cast_percent("s%")).to eq "s%" }
|
60
94
|
end
|
61
95
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,79 +1,5 @@
|
|
1
|
-
require 'coveralls'
|
2
|
-
Coveralls.wear!
|
3
|
-
|
4
1
|
require 'fluent/load'
|
5
2
|
require 'fluent/test'
|
6
3
|
|
7
|
-
|
8
|
-
|
9
|
-
# assertion/expectation library such as wrong or the stdlib/minitest
|
10
|
-
# assertions if you prefer.
|
11
|
-
config.expect_with :rspec do |expectations|
|
12
|
-
# This option will default to `true` in RSpec 4. It makes the `description`
|
13
|
-
# and `failure_message` of custom matchers include text for helper methods
|
14
|
-
# defined using `chain`, e.g.:
|
15
|
-
# be_bigger_than(2).and_smaller_than(4).description
|
16
|
-
# # => "be bigger than 2 and smaller than 4"
|
17
|
-
# ...rather than:
|
18
|
-
# # => "be bigger than 2"
|
19
|
-
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
20
|
-
end
|
21
|
-
|
22
|
-
# rspec-mocks config goes here. You can use an alternate test double
|
23
|
-
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
24
|
-
config.mock_with :rspec do |mocks|
|
25
|
-
# Prevents you from mocking or stubbing a method that does not exist on
|
26
|
-
# a real object. This is generally recommended, and will default to
|
27
|
-
# `true` in RSpec 4.
|
28
|
-
mocks.verify_partial_doubles = true
|
29
|
-
end
|
30
|
-
|
31
|
-
# The settings below are suggested to provide a good initial experience
|
32
|
-
# with RSpec, but feel free to customize to your heart's content.
|
33
|
-
=begin
|
34
|
-
# These two settings work together to allow you to limit a spec run
|
35
|
-
# to individual examples or groups you care about by tagging them with
|
36
|
-
# `:focus` metadata. When nothing is tagged with `:focus`, all examples
|
37
|
-
# get run.
|
38
|
-
config.filter_run :focus
|
39
|
-
config.run_all_when_everything_filtered = true
|
40
|
-
|
41
|
-
# Limits the available syntax to the non-monkey patched syntax that is
|
42
|
-
# recommended. For more details, see:
|
43
|
-
# - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
|
44
|
-
# - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
45
|
-
# - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
|
46
|
-
config.disable_monkey_patching!
|
47
|
-
|
48
|
-
# This setting enables warnings. It's recommended, but in some cases may
|
49
|
-
# be too noisy due to issues in dependencies.
|
50
|
-
config.warnings = true
|
51
|
-
|
52
|
-
# Many RSpec users commonly either run the entire suite or an individual
|
53
|
-
# file, and it's useful to allow more verbose output when running an
|
54
|
-
# individual spec file.
|
55
|
-
if config.files_to_run.one?
|
56
|
-
# Use the documentation formatter for detailed output,
|
57
|
-
# unless a formatter has already been configured
|
58
|
-
# (e.g. via a command-line flag).
|
59
|
-
config.default_formatter = 'doc'
|
60
|
-
end
|
61
|
-
|
62
|
-
# Print the 10 slowest examples and example groups at the
|
63
|
-
# end of the spec run, to help surface which specs are running
|
64
|
-
# particularly slow.
|
65
|
-
config.profile_examples = 10
|
66
|
-
|
67
|
-
# Run specs in random order to surface order dependencies. If you find an
|
68
|
-
# order dependency and want to debug it, you can fix the order by providing
|
69
|
-
# the seed, which is printed after each run.
|
70
|
-
# --seed 1234
|
71
|
-
config.order = :random
|
72
|
-
|
73
|
-
# Seed global randomization in this process using the `--seed` CLI option.
|
74
|
-
# Setting this allows you to use `--seed` to deterministically reproduce
|
75
|
-
# test failures related to randomization by passing the same `--seed` value
|
76
|
-
# as the one that triggered the failure.
|
77
|
-
Kernel.srand config.seed
|
78
|
-
=end
|
79
|
-
end
|
4
|
+
require 'coveralls'
|
5
|
+
Coveralls.wear!
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-specinfra_inventory
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Masashi Terui
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-03-
|
11
|
+
date: 2015-03-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fluentd
|
@@ -102,7 +102,6 @@ extensions: []
|
|
102
102
|
extra_rdoc_files: []
|
103
103
|
files:
|
104
104
|
- ".gitignore"
|
105
|
-
- ".rspec"
|
106
105
|
- ".travis.yml"
|
107
106
|
- CHANGELOG.md
|
108
107
|
- Gemfile
|
data/.rspec
DELETED