fluent-plugin-chef-client 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c88513a6f0f6fc5ce4aa8be22caf3e3bec0fb8b2
4
- data.tar.gz: ab028022a87e013d5d146c2c2cb3ed4e73568f2a
3
+ metadata.gz: b44feefe34583e151300f0d32fdab9497a4045d6
4
+ data.tar.gz: ee6716e89069236cad8247e5773b64d029bd76d2
5
5
  SHA512:
6
- metadata.gz: d7870177e02730ecabdcb25330e289975f7a2641049af3aa210145432910064b559524df4064c31eaa0d6863227459be7631a4ee35eb942b29ba71fbc5af4745
7
- data.tar.gz: cc7807486939dd23caffe9d0a7401077ec02326fbbe1e31e1ba435510bfd77ee2e9fef16cf8aba9382d86267d05d211a54845dd3db7db1a18348e8d7008c5d1c
6
+ metadata.gz: 2373341c44f5691b96785427e7561470e4b3e189d41f7a7bb0153e4d6b1bddc9ace82f564fa751ac4d832d2e69d34f0ae75dc456bd8f7bcf05e38577b2426ca8
7
+ data.tar.gz: 6ae13da60366d46b673879c584d9952dfedd81cb4fca2f3bd456cd9c2c85279faa46dcc0e824e9bd4a418e4774928f451832b0314ba1ff9f676a15507d85d6b6
@@ -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-client"
7
- spec.version = "0.1.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"
@@ -20,6 +20,7 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_development_dependency "bundler", "~> 1.9"
22
22
  spec.add_development_dependency "rake", "~> 10.0"
23
- spec.add_dependency "chef", ">= 11.18.0"
24
- spec.add_dependency "fluentd", ">= 0.10.55"
23
+ spec.add_dependency "chef", "< 12.0.0"
24
+ spec.add_dependency "fluentd"
25
+ spec.add_dependency "ohai", "< 8.0.0"
25
26
  end
@@ -1,3 +1,16 @@
1
+ if __FILE__ == $0
2
+ module Fluent
3
+ class Input
4
+ def self.config_param(name, *args, &block)
5
+ end
6
+ end
7
+ class Plugin
8
+ def self.register_input(type, klass)
9
+ end
10
+ end
11
+ end
12
+ end
13
+
1
14
  module Fluent
2
15
  class ChefClientInput < Input
3
16
  Plugin.register_input("chef_client", self)
@@ -5,26 +18,29 @@ module Fluent
5
18
  config_param :check_interval, :integer, :default => 60
6
19
  config_param :chef_server_url, :string, :default => nil
7
20
  config_param :client_key, :string, :default => nil
8
- config_param :config_file, :string, :default => "/etc/chef/config.rb"
21
+ config_param :config_file, :string, :default => "/etc/chef/client.rb"
9
22
  config_param :node_name, :string, :default => nil
10
23
  config_param :tag_prefix, :string, :default => "chef_client"
11
24
 
12
25
  def initialize
13
26
  super
14
- require "chef"
27
+ require "json"
28
+ require "rbconfig"
15
29
  end
16
30
 
17
31
  def configure(conf)
18
32
  super
19
- ::Chef::Config.from_file(@config_file)
20
- if @chef_server_url
21
- ::Chef::Config[:chef_server_url] = @chef_server_url
22
- end
23
- if @client_key
24
- ::Chef::Config[:client_key] = @client_key
25
- end
26
- if @node_name
27
- ::Chef::Config[:node_name] = @node_name
33
+ @chef_config = {
34
+ :config_file => @config_file,
35
+ :chef_server_url => @chef_server_url,
36
+ :client_key => @client_key,
37
+ :node_name => @node_name,
38
+ }
39
+ ruby = ::File.join(::RbConfig::CONFIG["bindir"], ::RbConfig::CONFIG["ruby_install_name"])
40
+ if ::File.executable?(ruby)
41
+ @ruby = ruby
42
+ else
43
+ @ruby = "ruby"
28
44
  end
29
45
  end
30
46
 
@@ -39,7 +55,6 @@ module Fluent
39
55
  end
40
56
 
41
57
  def run
42
- node_name = ::Chef::Config[:node_name]
43
58
  next_run = ::Time.new
44
59
  while @running
45
60
  if ::Time.new < next_run
@@ -47,11 +62,26 @@ module Fluent
47
62
  else
48
63
  begin
49
64
  now = Engine.now
50
- node = ::Chef::Node.load(node_name)
51
- ohai_time = node["ohai_time"]
52
- Engine.emit("#{@tag_prefix}.behind_from", now, {"value" => ohai_time ? (now - ohai_time) : -1})
65
+ data = nil
66
+ $log.debug("invoking process: #{@ruby} #{__FILE__}")
67
+ ::IO.popen([@ruby, __FILE__], "r+") do |io|
68
+ io.write(::JSON.dump(@chef_config))
69
+ io.close_write
70
+ data = ::JSON.load(io.read)
71
+ end
72
+ $log.debug("#{File.basename(__FILE__).dump} exits as #{$?.exitstatus}")
73
+ if $?.exitstatus == 0
74
+ data.each do |key, val|
75
+ Engine.emit("#{@tag_prefix}.#{key}", now, {"value" => val})
76
+ end
77
+ if ::Numeric === data["ohai_time"]
78
+ Engine.emit("#{@tag_prefix}.behind_seconds", now, {"value" => now - data["ohai_time"]})
79
+ end
80
+ else
81
+ raise("invalid response from #{__FILE__.dump}")
82
+ end
53
83
  rescue => error
54
- $log.warn("failed to load attributes of node \`#{node_name.inspect}': #{error.inspect}")
84
+ $log.warn("failed to load attributes: #{error.inspect}")
55
85
  next
56
86
  ensure
57
87
  next_run = ::Time.new + @check_interval
@@ -59,5 +89,36 @@ module Fluent
59
89
  end
60
90
  end
61
91
  end
92
+
93
+ def run_once
94
+ require "chef"
95
+ if @config_file
96
+ ::Chef::Config.from_file(@config_file)
97
+ end
98
+ if @chef_server_url
99
+ ::Chef::Config[:chef_server_url] = @chef_server_url
100
+ end
101
+ if @client_key
102
+ ::Chef::Config[:client_key] = @client_key
103
+ end
104
+ if @node_name
105
+ ::Chef::Config[:node_name] = @node_name
106
+ end
107
+ node_name = ::Chef::Config[:node_name]
108
+ node = ::Chef::Node.load(node_name)
109
+ data = ::Hash[["ohai_time", "idletime_seconds", "uptime_seconds"].map { |attr| [attr, node[attr]] }]
110
+ STDOUT.puts(::JSON.dump(data))
111
+ end
112
+ end
113
+ end
114
+
115
+ if __FILE__ == $0
116
+ input = Fluent::ChefClientInput.new
117
+ data = JSON.load(STDIN.read)
118
+ if Hash === data
119
+ data.each do |key, val|
120
+ input.instance_variable_set(:"@#{key}", val)
121
+ end
62
122
  end
123
+ input.run_once
63
124
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-chef-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yamashita Yuu
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-05-01 00:00:00.000000000 Z
11
+ date: 2015-05-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -42,30 +42,44 @@ dependencies:
42
42
  name: chef
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">="
45
+ - - "<"
46
46
  - !ruby/object:Gem::Version
47
- version: 11.18.0
47
+ version: 12.0.0
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ">="
52
+ - - "<"
53
53
  - !ruby/object:Gem::Version
54
- version: 11.18.0
54
+ version: 12.0.0
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: fluentd
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - ">="
60
60
  - !ruby/object:Gem::Version
61
- version: 0.10.55
61
+ version: '0'
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
- version: 0.10.55
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: ohai
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "<"
74
+ - !ruby/object:Gem::Version
75
+ version: 8.0.0
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "<"
81
+ - !ruby/object:Gem::Version
82
+ version: 8.0.0
69
83
  description: a fluent plugin for chef-client.
70
84
  email:
71
85
  - peek824545201@gmail.com