fluent-plugin-chef-api 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/fluent-plugin-chef-api.gemspec +1 -1
- data/lib/fluent/plugin/in_chef_api.rb +46 -6
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d9e66bb1109a731eaf573839fd6e9a147efc4b17
|
4
|
+
data.tar.gz: e80e0956ec0c2b644e46575820a8bd8711f5b667
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a6fdb5d1e87a4d81121a7b079f9a5b22cb9bc71d1e2168f5b82666e523b6db363e918377d43631abd8283b48c8addb4c4d789b20c24207e0cfc1b1b90e4ac920
|
7
|
+
data.tar.gz: 50adcd5cf697041470116c1a4ba8da169599c414b7062ab8dde411646681abe12a4c9e6df8c79182f8ea36a3658c5bd08a018607d25d3f0a11a51d3faa763cbb
|
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = "fluent-plugin-chef-api"
|
7
|
-
spec.version = "0.
|
7
|
+
spec.version = "0.2.0"
|
8
8
|
spec.authors = ["Yamashita Yuu"]
|
9
9
|
spec.email = ["peek824545201@gmail.com"]
|
10
10
|
spec.license = "Apache-2.0"
|
@@ -17,8 +17,52 @@ module Fluent
|
|
17
17
|
require "chef-api"
|
18
18
|
end
|
19
19
|
|
20
|
+
class ChefConfig
|
21
|
+
def self.load_file(file)
|
22
|
+
new(file).instance_eval { @config.dup }
|
23
|
+
end
|
24
|
+
|
25
|
+
def initialize(file)
|
26
|
+
@config = {}
|
27
|
+
instance_eval(::File.read(file))
|
28
|
+
end
|
29
|
+
|
30
|
+
def chef_server_url(value)
|
31
|
+
@config[:endpoint] = value
|
32
|
+
end
|
33
|
+
|
34
|
+
def node_name(value)
|
35
|
+
@config[:client] = value
|
36
|
+
end
|
37
|
+
|
38
|
+
def client_key(value)
|
39
|
+
@config[:key] = ::File.read(value)
|
40
|
+
end
|
41
|
+
|
42
|
+
def ssl_verify_mode(value)
|
43
|
+
@config[:ssl_verify] = value != :verify_none
|
44
|
+
end
|
45
|
+
|
46
|
+
def method_missing(*args)
|
47
|
+
# nop
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
20
51
|
def configure(conf)
|
21
52
|
super
|
53
|
+
@config = {}
|
54
|
+
if @config_file
|
55
|
+
@config = @config.merge(ChefConfig.load_file(@config_file))
|
56
|
+
end
|
57
|
+
if @chef_server_url
|
58
|
+
@config[:endpoint] = @chef_server_url
|
59
|
+
end
|
60
|
+
if @node_name
|
61
|
+
@config[:client] = value
|
62
|
+
end
|
63
|
+
if @client_key
|
64
|
+
@config[:key] = ::File.read(@client_key)
|
65
|
+
end
|
22
66
|
end
|
23
67
|
|
24
68
|
def start
|
@@ -32,11 +76,7 @@ module Fluent
|
|
32
76
|
end
|
33
77
|
|
34
78
|
def run
|
35
|
-
connection = ChefAPI::Connection.new(
|
36
|
-
:endpoint => @chef_server_url,
|
37
|
-
:client => @node_name,
|
38
|
-
:key => ::File.read(@client_key),
|
39
|
-
)
|
79
|
+
connection = ChefAPI::Connection.new(@config.dup)
|
40
80
|
next_run = ::Time.new
|
41
81
|
while @running
|
42
82
|
if ::Time.new < next_run
|
@@ -66,7 +106,7 @@ module Fluent
|
|
66
106
|
nodes.each do |node|
|
67
107
|
begin
|
68
108
|
Engine.emit("#{@tag}.run_list", Engine.now, data.merge({"value" => node.run_list.length, "node" => node.name}))
|
69
|
-
ohai_time = node.automatic.fetch("ohai_time")
|
109
|
+
ohai_time = node.automatic.fetch("ohai_time").to_i
|
70
110
|
Engine.emit("#{@tag}.ohai_time", Engine.now, data.merge({"value" => ohai_time, "node" => node.name}))
|
71
111
|
Engine.emit("#{@tag}.behind_seconds", Engine.now, data.merge({"value" => Time.new.to_i - ohai_time, "node" => node.name}))
|
72
112
|
rescue => error
|