puppetdb_rundeck 0.3.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5ae36fec2f31239f863f2c1c7622631234342377
4
+ data.tar.gz: 37029c01975875609d3ede38bdecf9023f74e706
5
+ SHA512:
6
+ metadata.gz: bd5bb497c3f595ab1cc08bbfea46746f01ec536451db869d4d85a038d24bbd504b3e69490287df0fb42656ca29080fd6dddc4854652149ada48fe8b82115efda
7
+ data.tar.gz: de80570a32684aefd7cd1e5d1dfad38d8f24b448416cf875aca6670a176d5ee34abebaaca262ec14f8ca83ad7ee86f5be236e7d3aa3a1a6b3a71fa406457113a
data/CHANGELOG CHANGED
@@ -1,6 +1,10 @@
1
+ 2014-11-19 Release 1.0.0
2
+ - fixing some threading bugs
3
+ - excluding some facts that can cause issues
4
+
1
5
  2014-07-01 Release 0.3.1
2
6
  - fixing issue when running on 1.8.x
3
-
7
+
4
8
  2014-07-01 Release 0.3.0
5
9
  - improved performance for large instances of puppetdb
6
10
  - added 30 min cache with api for clearing cache
data/bin/puppetdb_rundeck CHANGED
@@ -21,6 +21,14 @@ OptionParser.new do |opts|
21
21
  opts.on("--pdbport PORT", String, "The port of the PuppetDB instance") do |pp|
22
22
  options[:pdbport] = pp
23
23
  end
24
+
25
+ opts.on("--cache-timeout TIMEOUT", Integer, "The number of seconds to cache the results from puppetdb") do |ct|
26
+ options[:cache_timeout] = ct
27
+ end
28
+
29
+ opts.on("--thread-count THREADS", Integer, "Limit the number of threads used by the application when communicating with PuppetDB") do |tc|
30
+ options[:thread_count] = tc
31
+ end
24
32
  end.parse!
25
33
 
26
34
  if options[:pdbhost].nil? or options[:pdbhost].eql?('')
@@ -36,6 +44,8 @@ end
36
44
  PuppetDBRunDeck.set :bind, '0.0.0.0'
37
45
  PuppetDBRunDeck.set :puppetdb_host, options[:pdbhost]
38
46
  PuppetDBRunDeck.set :puppetdb_port, options[:pdbport]
47
+ PuppetDBRunDeck.set :cache_timeout, options[:cache_timeout]
48
+ PuppetDBRunDeck.set :thread_count, options[:thread_count]
39
49
 
40
50
  if options[:port].nil? or options[:port].eql?('')
41
51
  PuppetDBRunDeck.set :port, '4567'
@@ -43,4 +53,16 @@ else
43
53
  PuppetDBRunDeck.set :port, options[:port]
44
54
  end
45
55
 
46
- PuppetDBRunDeck.run!
56
+ if options[:cache_timeout].nil? or options[:cache_timeout].eql?('')
57
+ PuppetDBRunDeck.set :cache_timeout, 30
58
+ else
59
+ PuppetDBRunDeck.set :cache_timeout, options[:cache_timeout]
60
+ end
61
+
62
+ if options[:thread_count].nil? or options[:thread_count].eql?('')
63
+ PuppetDBRunDeck.set :thread_count, 3
64
+ else
65
+ PuppetDBRunDeck.set :thread_count, options[:thread_count]
66
+ end
67
+
68
+ PuppetDBRunDeck.run!
data/lib/app.rb CHANGED
@@ -13,7 +13,7 @@ class PuppetDBRunDeck < Sinatra::Base
13
13
  def initialize(app = nil, params = {})
14
14
  super(app)
15
15
  puppetdb_helper = Helpers::PuppetDB.new(settings.puppetdb_host, settings.puppetdb_port)
16
- @endpoint = EndPoint.new(puppetdb_helper)
16
+ @endpoint = EndPoint.new(puppetdb_helper, settings.cache_timeout, settings.thread_count)
17
17
  end
18
18
 
19
19
  get '/' do
@@ -26,17 +26,17 @@ class PuppetDBRunDeck < Sinatra::Base
26
26
 
27
27
  get '/api/yaml' do
28
28
  content_type 'text/yaml'
29
- content = @endpoint.to_yaml()
29
+ content = @endpoint.to_yaml(true)
30
30
  end
31
31
 
32
32
  get '/api/xml' do
33
33
  content_type 'application/xml'
34
- content = @endpoint.to_xml()
34
+ content = @endpoint.to_xml(true)
35
35
  end
36
36
 
37
37
  get '/api/json' do
38
38
  content_type 'application/json'
39
- content = @endpoint.to_json()
39
+ content = @endpoint.to_json(true)
40
40
  end
41
41
 
42
42
  get '/cache' do
@@ -1,51 +1,45 @@
1
1
 
2
2
  class Helpers::Process
3
3
 
4
- def add_facts(facts, host, collection)
4
+ def add_facts(facts, host)
5
+
6
+ fact_collection = { host => {} }
5
7
  facts.each{|f|
6
8
  if f['certname'].eql?(host)
7
9
  fact_name = f['name']
8
10
  fact_value = f['value']
9
11
 
10
- if fact_name.include?('processor')
11
- fact_name = number_to_name(fact_name)
12
+ if fact_name.include?('hostname')
13
+ fact_value = host
12
14
  end
13
15
 
14
- if fact_name.include?('path')
15
- fact_value = fact_value.gsub!('"','')
16
+ if !is_excluded?(fact_name)
17
+ fact_collection[host][fact_name] = fact_value
16
18
  end
17
19
 
18
- if collection.instance_of?(Hash)
19
- if collection[host].nil?
20
- collection[host] = {}
21
- end
22
-
23
- collection[host][fact_name] = fact_value
24
-
25
- elsif collection.instance_of?(Array)
26
- collection << "#{fact_name}=\"#{fact_value}\" "
27
- else
28
- end
29
20
  end
30
21
  }
31
- return collection
22
+ return fact_collection
32
23
  end
33
24
 
34
- private
35
- def number_to_name(name)
36
- lookup = {
37
- '1' => 'one', '2' => 'two', '3' => 'three', '4' => 'four', '5' => 'five',
38
- '6' => 'six', '7' => 'seven', '8' => 'eight', '9' => 'nine', '10' => 'ten',
39
- '11' => 'eleven', '12' => 'twelve', '13' => 'thirteen', '14' => 'fourteen',
40
- '15' => 'fifteen', '16' => 'sixteen'
41
- }
42
-
43
- lookup.each { |k,v|
44
- if name.include?(k)
45
- name.gsub!(k,"_#{v}")
46
- end
47
- }
48
- return name
25
+ def is_excluded?(fact)
26
+
27
+ excluded_facts = [
28
+ '^processor(s|\d+)$', '^path$', '^utc_offset$', '^os$',
29
+ '^ec2_metrics_vhostmd$', '^ec2_network_interfaces_macs.*',
30
+ '^ec2_userdata$', '^ec2_metadata$',
31
+ '^partitions$', '^system_uptime$', '^apt_package_updates$'
32
+ ]
33
+
34
+ match = false
35
+ for ex in excluded_facts
36
+ if fact.match(ex)
37
+ match = true
38
+ break;
39
+ end
49
40
  end
50
41
 
42
+ return match
43
+ end
44
+
51
45
  end
@@ -32,9 +32,7 @@ module Helpers
32
32
  else
33
33
  fact_endpoint = "http://#{@puppetdb_host}:#{@puppetdb_port}/v3/facts"
34
34
  end
35
-
36
- #p "requesting facts by: #{fact_endpoint}"
37
-
35
+
38
36
  uri = URI.parse(fact_endpoint)
39
37
  request = Net::HTTP::Get.new(uri.path)
40
38
  request.add_field('Accept', 'application/json')
@@ -1,17 +1,23 @@
1
1
  require File.expand_path('../../helpers/process', __FILE__)
2
+ require 'thread'
3
+ require 'thwait'
2
4
 
3
5
  class EndPoint
4
6
 
5
7
  attr_accessor :cache_timeout
6
- THREAD_COUNT = 40
8
+ attr_accessor :thread_count
7
9
 
8
- def initialize(puppetdb_helper)
10
+ def initialize(puppetdb_helper, cache_timeout, thread_count)
9
11
  @db_helper = puppetdb_helper
10
- @cache_timeout = 1800
12
+ @cache_timeout = cache_timeout
13
+ @thread_count = thread_count
11
14
  end
12
15
 
13
16
  def reload(type)
14
- nodes = @db_helper.get_nodes
17
+ p "reloading data"
18
+ if @nodes.nil? or @nodes.empty?
19
+ @nodes = @db_helper.get_nodes
20
+ end
15
21
 
16
22
  @rundeck_data = Hash.new
17
23
 
@@ -21,23 +27,36 @@ class EndPoint
21
27
 
22
28
  per_type_cache = "/tmp/puppetdb-resource.#{type}"
23
29
 
24
- THREAD_COUNT.times.map {
25
- Thread.new(nodes) do |nodes|
26
- while node = mutex.synchronize { nodes.pop }
30
+ data_elements = []
31
+ process_threads = []
32
+
33
+ @thread_count.times.map {
34
+ t = Thread.new(@nodes) do |nodes|
35
+ while node = mutex.synchronize { @nodes.pop }
27
36
  host = node['name']
28
37
  facts = @db_helper.get_facts(host)
29
38
  if !facts.nil?
30
- mutex.synchronize { helper.add_facts(facts, host, @rundeck_data) }
39
+ mutex.synchronize do
40
+ data_elements.push(helper.add_facts(facts, host))
41
+ end
31
42
  end
32
43
  end
33
44
  end
34
- }.each(&:join)
45
+ process_threads.push(t)
46
+ }
47
+
48
+ ThreadsWait.all_waits(*process_threads)
49
+
50
+ data_elements.each do |item|
51
+ #sleep(Random.new.rand(1..10))
52
+ @rundeck_data.merge!(item) if @rundeck_data.is_a?(Hash)
53
+ end
35
54
 
36
55
  data = case type
37
- when 'json' then to_json(false)
38
- when 'yaml' then to_yaml(false)
56
+ when 'json' then self.to_json(false)
57
+ when 'yaml' then self.to_yaml(false)
39
58
  when 'xml' then to_xml(false)
40
- else "unknown"
59
+ else 'unknown'
41
60
  end
42
61
 
43
62
  File.open(per_type_cache, 'w') { |file| file.write(data) }
@@ -45,7 +64,8 @@ class EndPoint
45
64
  return data
46
65
  end
47
66
 
48
- def to_json(parse_data=true)
67
+ def to_json(parse_data)
68
+ p "parse_data is: #{parse_data}"
49
69
  parse('json') if parse_data == true
50
70
  if @rundeck_data.is_a?(String)
51
71
  @rundeck_data
@@ -54,7 +74,8 @@ class EndPoint
54
74
  end
55
75
  end
56
76
 
57
- def to_yaml(parse_data=true)
77
+ def to_yaml(parse_data)
78
+ p "parse_data is: #{parse_data}"
58
79
  parse('yaml') if parse_data == true
59
80
  if @rundeck_data.is_a?(String)
60
81
  @rundeck_data
@@ -64,8 +85,6 @@ class EndPoint
64
85
  end
65
86
 
66
87
  def to_xml(parse_data=true)
67
- helper = Helpers::Process.new
68
-
69
88
  parse('xml') if parse_data == true
70
89
  if @rundeck_data.is_a?(String)
71
90
  @rundeck_data
@@ -86,7 +105,6 @@ class EndPoint
86
105
  end
87
106
  end
88
107
 
89
-
90
108
  def parse(type)
91
109
  per_type_cache = "/tmp/puppetdb-resource.#{type}"
92
110
 
@@ -109,7 +127,7 @@ class EndPoint
109
127
  end
110
128
 
111
129
  def clear_cache
112
- cache_files = ['/tmp/puppetdb-resource.xml','/tmp/puppetdb-resource.json','/tmp/puppetdb-resource.yaml']
130
+ cache_files = ['/tmp/puppetdb-resource.json','/tmp/puppetdb-resource.yaml']
113
131
 
114
132
  cache_files.each do |file|
115
133
  if File.exist?(file)
data/lib/views/api.haml CHANGED
@@ -2,6 +2,8 @@
2
2
  %html
3
3
  %head
4
4
  %title PuppetDB-Rundeck
5
+ %link(rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css")
6
+ %link(rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css")
5
7
  %body
6
8
  %h1 PuppetDB-Rundeck
7
9
  %p
data/lib/views/cache.haml CHANGED
@@ -2,6 +2,8 @@
2
2
  %html
3
3
  %head
4
4
  %title PuppetDB-Rundeck
5
+ %link(rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css")
6
+ %link(rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css")
5
7
  %body
6
8
  %h1 PuppetDB-Rundeck
7
9
  %h2 Cache settings
@@ -3,12 +3,12 @@ $:.push File.expand_path("../lib", __FILE__)
3
3
 
4
4
  Gem::Specification.new do |spec|
5
5
  spec.name = 'puppetdb_rundeck'
6
- spec.version = '0.3.1'
6
+ spec.version = '1.0.0'
7
7
  spec.authors = ['liamjbennett']
8
8
  spec.email = ['lbennett@opentable.com']
9
9
  spec.summary = %q{A sinatra based application to provide integration between PuppetDB and Rundeck}
10
10
  spec.description = %q{puppetdb_rundeck is a sinatra based application to provide integration between PuppetDB and Rundeck.
11
- It provides an api in either xml or yaml that allows the node and fact data with puppetdb to use used as a resource
11
+ It provides an api in either xml, json or yaml that allows the node and fact data with puppetdb to use used as a resource
12
12
  with rundeck}
13
13
  spec.homepage = 'https://github.com/opentable/puppetdb_rundeck'
14
14
  spec.license = 'MIT'
metadata CHANGED
@@ -1,20 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: puppetdb_rundeck
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
5
- prerelease:
4
+ version: 1.0.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - liamjbennett
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2014-07-01 00:00:00.000000000 Z
11
+ date: 2014-11-19 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: bundler
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - ~>
20
18
  - !ruby/object:Gem::Version
@@ -22,7 +20,6 @@ dependencies:
22
20
  type: :development
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
24
  - - ~>
28
25
  - !ruby/object:Gem::Version
@@ -30,7 +27,6 @@ dependencies:
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: rake
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
31
  - - ~>
36
32
  - !ruby/object:Gem::Version
@@ -38,7 +34,6 @@ dependencies:
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
38
  - - ~>
44
39
  - !ruby/object:Gem::Version
@@ -46,87 +41,76 @@ dependencies:
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: rspec
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ! '>='
45
+ - - '>='
52
46
  - !ruby/object:Gem::Version
53
47
  version: '0'
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ! '>='
52
+ - - '>='
60
53
  - !ruby/object:Gem::Version
61
54
  version: '0'
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: rack-test
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
- - - ! '>='
59
+ - - '>='
68
60
  - !ruby/object:Gem::Version
69
61
  version: '0'
70
62
  type: :development
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
- - - ! '>='
66
+ - - '>='
76
67
  - !ruby/object:Gem::Version
77
68
  version: '0'
78
69
  - !ruby/object:Gem::Dependency
79
70
  name: webmock
80
71
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
72
  requirements:
83
- - - ! '>='
73
+ - - '>='
84
74
  - !ruby/object:Gem::Version
85
75
  version: '0'
86
76
  type: :development
87
77
  prerelease: false
88
78
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
79
  requirements:
91
- - - ! '>='
80
+ - - '>='
92
81
  - !ruby/object:Gem::Version
93
82
  version: '0'
94
83
  - !ruby/object:Gem::Dependency
95
84
  name: rspec-mocks
96
85
  requirement: !ruby/object:Gem::Requirement
97
- none: false
98
86
  requirements:
99
- - - ! '>='
87
+ - - '>='
100
88
  - !ruby/object:Gem::Version
101
89
  version: '0'
102
90
  type: :development
103
91
  prerelease: false
104
92
  version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
93
  requirements:
107
- - - ! '>='
94
+ - - '>='
108
95
  - !ruby/object:Gem::Version
109
96
  version: '0'
110
97
  - !ruby/object:Gem::Dependency
111
98
  name: builder
112
99
  requirement: !ruby/object:Gem::Requirement
113
- none: false
114
100
  requirements:
115
- - - ! '>='
101
+ - - '>='
116
102
  - !ruby/object:Gem::Version
117
103
  version: '0'
118
104
  type: :development
119
105
  prerelease: false
120
106
  version_requirements: !ruby/object:Gem::Requirement
121
- none: false
122
107
  requirements:
123
- - - ! '>='
108
+ - - '>='
124
109
  - !ruby/object:Gem::Version
125
110
  version: '0'
126
111
  - !ruby/object:Gem::Dependency
127
112
  name: json_pure
128
113
  requirement: !ruby/object:Gem::Requirement
129
- none: false
130
114
  requirements:
131
115
  - - ~>
132
116
  - !ruby/object:Gem::Version
@@ -134,7 +118,6 @@ dependencies:
134
118
  type: :runtime
135
119
  prerelease: false
136
120
  version_requirements: !ruby/object:Gem::Requirement
137
- none: false
138
121
  requirements:
139
122
  - - ~>
140
123
  - !ruby/object:Gem::Version
@@ -142,7 +125,6 @@ dependencies:
142
125
  - !ruby/object:Gem::Dependency
143
126
  name: tilt
144
127
  requirement: !ruby/object:Gem::Requirement
145
- none: false
146
128
  requirements:
147
129
  - - ~>
148
130
  - !ruby/object:Gem::Version
@@ -150,7 +132,6 @@ dependencies:
150
132
  type: :runtime
151
133
  prerelease: false
152
134
  version_requirements: !ruby/object:Gem::Requirement
153
- none: false
154
135
  requirements:
155
136
  - - ~>
156
137
  - !ruby/object:Gem::Version
@@ -158,7 +139,6 @@ dependencies:
158
139
  - !ruby/object:Gem::Dependency
159
140
  name: sinatra
160
141
  requirement: !ruby/object:Gem::Requirement
161
- none: false
162
142
  requirements:
163
143
  - - ~>
164
144
  - !ruby/object:Gem::Version
@@ -166,7 +146,6 @@ dependencies:
166
146
  type: :runtime
167
147
  prerelease: false
168
148
  version_requirements: !ruby/object:Gem::Requirement
169
- none: false
170
149
  requirements:
171
150
  - - ~>
172
151
  - !ruby/object:Gem::Version
@@ -174,7 +153,6 @@ dependencies:
174
153
  - !ruby/object:Gem::Dependency
175
154
  name: haml
176
155
  requirement: !ruby/object:Gem::Requirement
177
- none: false
178
156
  requirements:
179
157
  - - ~>
180
158
  - !ruby/object:Gem::Version
@@ -182,7 +160,6 @@ dependencies:
182
160
  type: :runtime
183
161
  prerelease: false
184
162
  version_requirements: !ruby/object:Gem::Requirement
185
- none: false
186
163
  requirements:
187
164
  - - ~>
188
165
  - !ruby/object:Gem::Version
@@ -190,7 +167,6 @@ dependencies:
190
167
  - !ruby/object:Gem::Dependency
191
168
  name: thread
192
169
  requirement: !ruby/object:Gem::Requirement
193
- none: false
194
170
  requirements:
195
171
  - - ~>
196
172
  - !ruby/object:Gem::Version
@@ -198,18 +174,14 @@ dependencies:
198
174
  type: :runtime
199
175
  prerelease: false
200
176
  version_requirements: !ruby/object:Gem::Requirement
201
- none: false
202
177
  requirements:
203
178
  - - ~>
204
179
  - !ruby/object:Gem::Version
205
180
  version: '0.1'
206
- description: ! 'puppetdb_rundeck is a sinatra based application to provide integration
207
- between PuppetDB and Rundeck.
208
-
209
- It provides an api in either xml or yaml that allows the node and fact data with
210
- puppetdb to use used as a resource
211
-
212
- with rundeck'
181
+ description: |-
182
+ puppetdb_rundeck is a sinatra based application to provide integration between PuppetDB and Rundeck.
183
+ It provides an api in either xml, json or yaml that allows the node and fact data with puppetdb to use used as a resource
184
+ with rundeck
213
185
  email:
214
186
  - lbennett@opentable.com
215
187
  executables:
@@ -242,27 +214,26 @@ files:
242
214
  homepage: https://github.com/opentable/puppetdb_rundeck
243
215
  licenses:
244
216
  - MIT
217
+ metadata: {}
245
218
  post_install_message:
246
219
  rdoc_options: []
247
220
  require_paths:
248
221
  - lib
249
222
  required_ruby_version: !ruby/object:Gem::Requirement
250
- none: false
251
223
  requirements:
252
- - - ! '>='
224
+ - - '>='
253
225
  - !ruby/object:Gem::Version
254
226
  version: '0'
255
227
  required_rubygems_version: !ruby/object:Gem::Requirement
256
- none: false
257
228
  requirements:
258
- - - ! '>='
229
+ - - '>='
259
230
  - !ruby/object:Gem::Version
260
231
  version: '0'
261
232
  requirements: []
262
233
  rubyforge_project:
263
- rubygems_version: 1.8.23.2
234
+ rubygems_version: 2.2.2
264
235
  signing_key:
265
- specification_version: 3
236
+ specification_version: 4
266
237
  summary: A sinatra based application to provide integration between PuppetDB and Rundeck
267
238
  test_files:
268
239
  - spec/app_spec.rb