collect-agent 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/Gemfile +3 -0
- data/Rakefile +1 -0
- data/bin/collect-agent +34 -0
- data/collect-agent.gemspec +19 -0
- data/lib/helpers.rb +14 -0
- metadata +86 -0
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
*.gem
|
data/Gemfile
ADDED
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
data/bin/collect-agent
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'chef'
|
4
|
+
require 'trollop'
|
5
|
+
require File.dirname(__FILE__) + '/../lib/helpers.rb'
|
6
|
+
|
7
|
+
opts = Trollop::options do
|
8
|
+
version "Collect-agent for chef"
|
9
|
+
banner <<-EOS
|
10
|
+
Collect-agent utility for collecting automatic attribute nodes and then push them to the chef.
|
11
|
+
|
12
|
+
Usage:
|
13
|
+
collect-agent [options]
|
14
|
+
where [options] are:
|
15
|
+
EOS
|
16
|
+
|
17
|
+
opt :config, "Config chef file", :default => "/etc/chef/client.rb"
|
18
|
+
end
|
19
|
+
|
20
|
+
ohai = Ohai::System.new
|
21
|
+
ohai.all_plugins
|
22
|
+
ohai.seen_plugins
|
23
|
+
Chef::Config.from_file( opts[:config] )
|
24
|
+
host = Chef::Config[:node_name] || ohai[:fqdn] || ohai[:hostname]
|
25
|
+
client = Chef::REST.new( Chef::Config[:chef_server_url] , host , Chef::Config[:client_key] )
|
26
|
+
node = client.get_rest( "nodes/#{host}" )
|
27
|
+
|
28
|
+
node_automatic = node.automatic_attrs
|
29
|
+
node_automatic.each do |key, value|
|
30
|
+
node_automatic[key] = ohai.data[key] if ohai.data[key]
|
31
|
+
end
|
32
|
+
|
33
|
+
set_network_addresses(node)
|
34
|
+
client.put_rest( "nodes/#{host}", node )
|
@@ -0,0 +1,19 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = "collect-agent"
|
3
|
+
s.version = `git describe --abbrev=0 --tags`.chomp
|
4
|
+
s.authors = ["Vasiliev D.V."]
|
5
|
+
s.email = %w(vadv.mkn@gmail.com)
|
6
|
+
s.homepage = "https://git.undev.cc/megaadmins/collect-agent"
|
7
|
+
s.summary = %q{Chef collect agent}
|
8
|
+
s.description = %q{Chef collect agent}
|
9
|
+
s.licenses = %w(MIT)
|
10
|
+
|
11
|
+
s.add_dependency('chef')
|
12
|
+
s.add_dependency('trollop')
|
13
|
+
|
14
|
+
s.files = `git ls-files`.split("\n")
|
15
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
16
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
17
|
+
s.require_paths = %w(lib)
|
18
|
+
end
|
19
|
+
|
data/lib/helpers.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
def set_network_addresses(node)
|
2
|
+
private_regexp = "(^10\.)|(^172\.1[6-9]\.)|(^172\.2[0-9]\.)|(^172\.3[0-1]\.)|(^192\.168\.)"
|
3
|
+
localhost_regexp = "(^127\.)"
|
4
|
+
all_addresses = Array.new
|
5
|
+
private_addresses = Array.new
|
6
|
+
node.network['interfaces'].each do |iface, addrs|
|
7
|
+
addrs['addresses'].each do |ip, params|
|
8
|
+
all_addresses << ip if params['family'].eql?('inet') && !ip.match(localhost_regexp)
|
9
|
+
private_addresses << ip if params['family'].eql?('inet') && ip.match(private_regexp)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
node.automatic_attrs['network']['addresses_private'] = private_addresses
|
13
|
+
node.automatic_attrs['network']['addresses_all'] = all_addresses
|
14
|
+
end
|
metadata
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: collect-agent
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Vasiliev D.V.
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-04-26 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: chef
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: trollop
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
description: Chef collect agent
|
47
|
+
email:
|
48
|
+
- vadv.mkn@gmail.com
|
49
|
+
executables:
|
50
|
+
- collect-agent
|
51
|
+
extensions: []
|
52
|
+
extra_rdoc_files: []
|
53
|
+
files:
|
54
|
+
- .gitignore
|
55
|
+
- Gemfile
|
56
|
+
- Rakefile
|
57
|
+
- bin/collect-agent
|
58
|
+
- collect-agent.gemspec
|
59
|
+
- lib/helpers.rb
|
60
|
+
homepage: https://git.undev.cc/megaadmins/collect-agent
|
61
|
+
licenses:
|
62
|
+
- MIT
|
63
|
+
post_install_message:
|
64
|
+
rdoc_options: []
|
65
|
+
require_paths:
|
66
|
+
- lib
|
67
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
68
|
+
none: false
|
69
|
+
requirements:
|
70
|
+
- - ! '>='
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ! '>='
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
requirements: []
|
80
|
+
rubyforge_project:
|
81
|
+
rubygems_version: 1.8.25
|
82
|
+
signing_key:
|
83
|
+
specification_version: 3
|
84
|
+
summary: Chef collect agent
|
85
|
+
test_files: []
|
86
|
+
has_rdoc:
|