genesis_collector 0.1.3 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b3d39ca69a6adc13a4abd67a0fd9625732c5826e
4
- data.tar.gz: aaa36058829ee9455487571eb878622871a81828
3
+ metadata.gz: 7380d9cdffa045595133ceaf1058548d805690ef
4
+ data.tar.gz: 263298738b9ce230963da716696f27e78af66b19
5
5
  SHA512:
6
- metadata.gz: 070ccbcc1e62328c588cff5307d26a23a11968da352230e2b8b46f755afa2e75bb5280414e7d607606b9960ad2fcc8292a3baa22ad22896523928210de9af5ab
7
- data.tar.gz: 0ad60a20d56121590e319c1dbc48d4196e1347ddb45768bf2ff47e015097fd15f9a4e03bd52d0d5cc3144234ca02b57116d71c1e63aad62d54107771896695a5
6
+ metadata.gz: dcb446358887fd25740f07fc624536a2ca5c82c9d1f909138af494785c2d66f0c3390bd8ab71773e3d88b10c4301e77c59300af3989d66d187d30c110414dbaa
7
+ data.tar.gz: 108a96d5a92935b1b8debd9f1fcd7ab4d101fd80618b3986cbb856a93c56ef3377c84c972eb30afc371f2485bbe02773f724f540cea58727f8dd1c0a45237a76
@@ -1,26 +1,34 @@
1
+ require 'time'
2
+
1
3
  module GenesisCollector
2
4
  module Chef
3
5
 
4
6
  def collect_chef
5
- @payload[:chef] = {
6
- environment: get_chef_environment,
7
- roles: (@chef_node.respond_to?(:[]) ? @chef_node['roles'] : []),
8
- run_list: (@chef_node.respond_to?(:[]) ? @chef_node['run_list'] : ''),
9
- tags: get_chef_tags
10
- }
7
+ @payload[:chef] = @chef_node.nil? ? collect_chef_from_knife : collect_chef_from_node
11
8
  end
12
9
 
13
- def get_chef_environment
14
- env = nil
15
- env = File.read('/etc/chef/current_environment').gsub(/\s+/, '') if File.exist? '/etc/chef/current_environment'
16
- env || 'unknown'
10
+ def collect_chef_from_node
11
+ {
12
+ environment: @chef_node.chef_environment,
13
+ roles: @chef_node.roles,
14
+ run_list: @chef_node.run_list.to_s,
15
+ tags: @chef_node.tags,
16
+ last_run: Time.at(@chef_node.ohai_time).utc.iso8601
17
+ }
17
18
  end
18
19
 
19
- def get_chef_tags
20
- node_show_output = shellout_with_timeout('knife node show `hostname` -c /etc/chef/client.rb')
21
- node_show_output.match(/Tags:(.*)/)[0].delete(' ').gsub('Tags:', '').split(',')
20
+ def collect_chef_from_knife
21
+ output = shellout_with_timeout('knife node show `hostname` -c /etc/chef/client.rb -a ohai_time -a run_list -a tags -a environment -a roles -f json')
22
+ _hostname, parsed = JSON.parse(output).first
23
+ {
24
+ environment: parsed['environment'],
25
+ roles: parsed['roles'],
26
+ run_list: parsed['run_list'].join(', '),
27
+ tags: parsed['tags'],
28
+ last_run: Time.at(parsed['ohai_time']).utc.iso8601
29
+ }
22
30
  rescue
23
- []
31
+ nil
24
32
  end
25
33
 
26
34
  end
@@ -1,3 +1,3 @@
1
1
  module GenesisCollector
2
- VERSION = '0.1.3'
2
+ VERSION = '0.1.4'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: genesis_collector
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Radcliffe