ohai 7.2.0.alpha.0 → 7.2.0.rc.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: 81416c96c35d5769f24aae74567e9937a5e1798a
4
- data.tar.gz: 44012ca9a21be521454fe2123e73391c31f9177d
3
+ metadata.gz: 937d95d7e6b646e0028a39cc285b62c97cb05719
4
+ data.tar.gz: b0327a0a4bb11c90cf3d4f9b352b4bcb7be21e68
5
5
  SHA512:
6
- metadata.gz: 3d77a851d7feb9394295e5c5165b1a5ea2e97c1e4364e945e931fb177dcbd052c4aa3cf9600f64bcd07468780b6a468d1db070126e61e88d526a3fd65353eaca
7
- data.tar.gz: 9e8fca70a6e332456131d6e770a538253a29f739639776f1276d6f3dc849cee3487b6410592fb0404a1e943eca06794d44260696f69e16815b0c231a57744beb
6
+ metadata.gz: e58ecebbe4efa2e3774e692e70a48214985dab83c27c7364f091e82f8c576f43b457b9c45e6dab14a56665183b88d3ee6f534bee48124bb153982eae0d764404
7
+ data.tar.gz: 4e4b8b1afa20f3f84293731020e5ec3378749cd2c8bb7b10c7232959758f70ad8961f73fc0acf62635811f672fd674d92b5e3f00aae7a8465ab475b1d680d210
@@ -121,16 +121,18 @@ module Ohai
121
121
  end
122
122
  end
123
123
 
124
- def attribute?(name)
124
+ def has_key?(name)
125
125
  @data.has_key?(name)
126
126
  end
127
127
 
128
+ alias :attribute? :has_key?
129
+
128
130
  def set(name, *value)
129
131
  set_attribute(name, *value)
130
132
  end
131
133
 
132
134
  def from(cmd)
133
- status, stdout, stderr = run_command(:command => cmd)
135
+ _status, stdout, _stderr = run_command(:command => cmd)
134
136
  return "" if stdout.nil? || stdout.empty?
135
137
  stdout.strip
136
138
  end
@@ -140,7 +142,7 @@ module Ohai
140
142
  # the value.
141
143
  def from_with_regex(cmd, *regex_list)
142
144
  regex_list.flatten.each do |regex|
143
- status, stdout, stderr = run_command(:command => cmd)
145
+ _status, stdout, _stderr = run_command(:command => cmd)
144
146
  return "" if stdout.nil? || stdout.empty?
145
147
  stdout.chomp!.strip
146
148
  md = stdout.match(regex)
@@ -17,6 +17,8 @@
17
17
  # limitations under the License.
18
18
  #
19
19
 
20
+ require 'ffi_yajl'
21
+
20
22
  module Ohai
21
23
  module Hints
22
24
  def self.refresh_hints
@@ -31,12 +33,12 @@ module Ohai
31
33
  filename = File.join(path, "#{name}.json")
32
34
  if File.exist?(filename)
33
35
  begin
34
- json_parser = Yajl::Parser.new
36
+ json_parser = FFI_Yajl::Parser.new
35
37
  hash = json_parser.parse(File.read(filename))
36
38
  @hints[name] = hash || Hash.new # hint
37
39
  # should exist because the file did, even if it didn't
38
40
  # contain anything
39
- rescue Yajl::ParseError => e
41
+ rescue FFI_Yajl::ParseError => e
40
42
  Ohai::Log.error("Could not parse hint file at #{filename}: #{e.message}")
41
43
  end
42
44
  end
@@ -98,70 +98,94 @@ module Ohai
98
98
  Net::HTTP.start(EC2_METADATA_ADDR).tap {|h| h.read_timeout = 600}
99
99
  end
100
100
 
101
+ # Get metadata for a given path and API version
102
+ #
103
+ # @details
104
+ # Typically, a 200 response is expected for valid metadata.
105
+ # On certain instance types, traversing the provided metadata path
106
+ # produces a 404 for some unknown reason. In that event, return
107
+ # `nil` and continue the run instead of failing it.
101
108
  def metadata_get(id, api_version)
102
109
  path = "/#{api_version}/meta-data/#{id}"
103
110
  response = http_client.get(path)
104
- unless response.code == '200'
111
+ case response.code
112
+ when '200'
113
+ response.body
114
+ when '404'
115
+ Ohai::Log.debug("Encountered 404 response retreiving EC2 metadata path: #{path} ; continuing.")
116
+ nil
117
+ else
105
118
  raise "Encountered error retrieving EC2 metadata (#{path} returned #{response.code} response)"
106
119
  end
107
- response
108
120
  end
109
121
 
110
122
  def fetch_metadata(id='', api_version=nil)
111
123
  api_version ||= best_api_version
112
124
  return Hash.new if api_version.nil?
113
125
  metadata = Hash.new
114
- metadata_get(id, api_version).body.split("\n").each do |o|
115
- key = expand_path("#{id}#{o}")
116
- if key[-1..-1] != '/'
117
- metadata[metadata_key(key)] =
118
- if EC2_ARRAY_VALUES.include? key
119
- metadata_get(key, api_version).body.split("\n")
126
+ retrieved_metadata = metadata_get(id, api_version)
127
+ if retrieved_metadata
128
+ retrieved_metadata.split("\n").each do |o|
129
+ key = expand_path("#{id}#{o}")
130
+ if key[-1..-1] != '/'
131
+ metadata[metadata_key(key)] =
132
+ if EC2_ARRAY_VALUES.include? key
133
+ retr_meta = metadata_get(key, api_version)
134
+ retr_meta ? retr_meta.split("\n") : retr_meta
135
+ else
136
+ metadata_get(key, api_version)
137
+ end
138
+ elsif not key.eql?(id) and not key.eql?('/')
139
+ name = key[0..-2]
140
+ sym = metadata_key(name)
141
+ if EC2_ARRAY_DIR.include?(name)
142
+ metadata[sym] = fetch_dir_metadata(key, api_version)
143
+ elsif EC2_JSON_DIR.include?(name)
144
+ metadata[sym] = fetch_json_dir_metadata(key, api_version)
120
145
  else
121
- metadata_get(key, api_version).body
146
+ fetch_metadata(key, api_version).each{|k,v| metadata[k] = v}
122
147
  end
123
- elsif not key.eql?(id) and not key.eql?('/')
124
- name = key[0..-2]
125
- sym = metadata_key(name)
126
- if EC2_ARRAY_DIR.include?(name)
127
- metadata[sym] = fetch_dir_metadata(key, api_version)
128
- elsif EC2_JSON_DIR.include?(name)
129
- metadata[sym] = fetch_json_dir_metadata(key, api_version)
130
- else
131
- fetch_metadata(key, api_version).each{|k,v| metadata[k] = v}
132
148
  end
133
149
  end
150
+ metadata
134
151
  end
135
- metadata
136
152
  end
137
153
 
138
154
  def fetch_dir_metadata(id, api_version)
139
155
  metadata = Hash.new
140
- metadata_get(id, api_version).body.split("\n").each do |o|
141
- key = expand_path(o)
142
- if key[-1..-1] != '/'
143
- metadata[metadata_key(key)] = metadata_get("#{id}#{key}", api_version).body
144
- elsif not key.eql?('/')
145
- metadata[key[0..-2]] = fetch_dir_metadata("#{id}#{key}", api_version)
156
+ retrieved_metadata = metadata_get(id, api_version)
157
+ if retrieved_metadata
158
+ retrieved_metadata.split("\n").each do |o|
159
+ key = expand_path(o)
160
+ if key[-1..-1] != '/'
161
+ retr_meta = metadata_get("#{id}#{key}", api_version)
162
+ metadata[metadata_key(key)] = retr_meta ? retr_meta : ''
163
+ elsif not key.eql?('/')
164
+ metadata[key[0..-2]] = fetch_dir_metadata("#{id}#{key}", api_version)
165
+ end
146
166
  end
167
+ metadata
147
168
  end
148
- metadata
149
169
  end
150
170
 
151
171
  def fetch_json_dir_metadata(id, api_version)
152
172
  metadata = Hash.new
153
- metadata_get(id, api_version).body.split("\n").each do |o|
154
- key = expand_path(o)
155
- if key[-1..-1] != '/'
156
- data = metadata_get("#{id}#{key}", api_version).body
157
- json = StringIO.new(data)
158
- parser = Yajl::Parser.new
159
- metadata[metadata_key(key)] = parser.parse(json)
160
- elsif not key.eql?('/')
161
- metadata[key[0..-2]] = fetch_json_dir_metadata("#{id}#{key}", api_version)
173
+ retrieved_metadata = metadata_get(id, api_version)
174
+ if retrieved_metadata
175
+ retrieved_metadata.split("\n").each do |o|
176
+ key = expand_path(o)
177
+ if key[-1..-1] != '/'
178
+ retr_meta = metadata_get("#{id}#{key}", api_version)
179
+ data = retr_meta ? retr_meta : ''
180
+ json = StringIO.new(data)
181
+ parser = FFI_Yajl::Parser.new
182
+ metadata[metadata_key(key)] = parser.parse(json)
183
+ elsif not key.eql?('/')
184
+ metadata[key[0..-2]] = fetch_json_dir_metadata("#{id}#{key}", api_version)
185
+ end
162
186
  end
187
+ metadata
163
188
  end
164
- metadata
165
189
  end
166
190
 
167
191
  def fetch_userdata()
@@ -58,10 +58,10 @@ module Ohai
58
58
  uri = "#{GCE_METADATA_URL}/#{id}"
59
59
  response = http_client.get(uri)
60
60
  return nil unless response.code == "200"
61
-
61
+
62
62
  if json?(response.body)
63
63
  data = StringIO.new(response.body)
64
- parser = Yajl::Parser.new
64
+ parser = FFI_Yajl::Parser.new
65
65
  parser.parse(data)
66
66
  elsif has_trailing_slash?(id) or (id == '')
67
67
  temp={}
@@ -76,15 +76,15 @@ module Ohai
76
76
 
77
77
  def json?(data)
78
78
  data = StringIO.new(data)
79
- parser = Yajl::Parser.new
79
+ parser = FFI_Yajl::Parser.new
80
80
  begin
81
81
  parser.parse(data)
82
82
  true
83
- rescue Yajl::ParseError
83
+ rescue FFI_Yajl::ParseError
84
84
  false
85
85
  end
86
86
  end
87
-
87
+
88
88
  def multiline?(data)
89
89
  data.lines.to_a.size > 1
90
90
  end
@@ -0,0 +1,63 @@
1
+ #
2
+ # Author:: Patrick Collins (<pat@burned.com>)
3
+ # Copyright:: Copyright (c) 2013 Opscode, Inc.
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ Ohai.plugin(:Memory) do
20
+ provides 'memory'
21
+
22
+ collect_data(:darwin) do
23
+ memory Mash.new
24
+
25
+ installed_memory = shell_out("sysctl -n hw.memsize").stdout.to_i / 1024 / 1024.0
26
+ memory[:total] = "#{installed_memory.to_i}MB"
27
+
28
+ total_consumed = 0
29
+ active = 0
30
+ inactive = 0
31
+ vm_stat = shell_out("vm_stat").stdout
32
+ vm_stat_match = /page size of (\d+) bytes/.match(vm_stat)
33
+ page_size = if vm_stat_match and vm_stat_match[1]
34
+ vm_stat_match[1].to_i
35
+ else
36
+ 4096
37
+ end
38
+ vm_stat.split("\n").each do |line|
39
+ ['wired down', 'active', 'inactive'].each do |match|
40
+ unless line.index("Pages #{match}:").nil?
41
+ pages = line.split.last.to_i
42
+ megabyte_val = (pages * page_size) / 1024 / 1024.0
43
+ total_consumed += megabyte_val
44
+ case match
45
+ when 'wired down'
46
+ active += megabyte_val.to_i
47
+ when 'active'
48
+ active += megabyte_val.to_i
49
+ when 'inactive'
50
+ inactive += megabyte_val.to_i
51
+ end
52
+ end
53
+ end
54
+ end
55
+
56
+ memory[:active] = "#{active}MB" if active > 0
57
+ memory[:inactive] = "#{inactive}MB" if inactive > 0
58
+
59
+ free_memory = installed_memory - total_consumed
60
+ memory[:free] = "#{free_memory.to_i}MB" if total_consumed > 0
61
+ end
62
+ end
63
+
@@ -0,0 +1,82 @@
1
+ #
2
+ # Author: sawanoboriyu@higanworks.com
3
+ # Copyright (C) 2014 HiganWorks LLC
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+ #
19
+
20
+ # Reference from: sm-summary command
21
+
22
+ Ohai.plugin(:Joyent) do
23
+ provides 'joyent'
24
+ provides 'virtualization/guest_id'
25
+ depends 'os', 'platform', 'virtualization'
26
+
27
+ def collect_product_file
28
+ lines = []
29
+ if ::File.exists?("/etc/product")
30
+ ::File.open("/etc/product") do |file|
31
+ while line = file.gets
32
+ lines << line
33
+ end
34
+ end
35
+ end
36
+ lines
37
+ end
38
+
39
+ def collect_pkgsrc
40
+ if File.exist?('/opt/local/etc/pkg_install.conf')
41
+ sm_pkgsrc = ::File.read("/opt/local/etc/pkg_install.conf").split("=")
42
+ sm_pkgsrc[1].chomp
43
+ else
44
+ nil
45
+ end
46
+ end
47
+
48
+ def is_smartos?
49
+ platform == 'smartos'
50
+ end
51
+
52
+ collect_data do
53
+ if is_smartos?
54
+ joyent Mash.new
55
+
56
+ # copy uuid
57
+ joyent[:sm_uuid] = virtualization[:guest_uuid]
58
+
59
+ # get zone id unless globalzone
60
+ unless joyent[:sm_uuid] == "global"
61
+ joyent[:sm_id] = virtualization[:guest_id]
62
+ end
63
+
64
+ # retrieve image name and pkgsrc
65
+ collect_product_file.each do |line|
66
+ case line
67
+ when /^Image/
68
+ sm_image = line.split(" ")
69
+ joyent[:sm_image_id] = sm_image[1]
70
+ joyent[:sm_image_ver] = sm_image[2]
71
+ when /^Base Image/
72
+ sm_baseimage = line.split(" ")
73
+ joyent[:sm_baseimage_id] = sm_baseimage[2]
74
+ joyent[:sm_baseimage_ver] = sm_baseimage[3]
75
+ end
76
+ end
77
+
78
+ ## retrieve pkgsrc
79
+ joyent[:sm_pkgsrc] = collect_pkgsrc if collect_pkgsrc
80
+ end
81
+ end
82
+ end
@@ -38,6 +38,23 @@ Ohai.plugin(:Filesystem) do
38
38
  fs[filesystem][:mount] = $6
39
39
  end
40
40
  end
41
+
42
+ # Grab filesystem inode data from df
43
+ so = shell_out("df -i")
44
+ so.stdout.lines do |line|
45
+ case line
46
+ when /^Filesystem\s+Inodes/
47
+ next
48
+ when /^(.+?)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+\%)\s+(.+)$/
49
+ filesystem = $1
50
+ fs[filesystem] ||= Mash.new
51
+ fs[filesystem][:total_inodes] = $2
52
+ fs[filesystem][:inodes_used] = $3
53
+ fs[filesystem][:inodes_available] = $4
54
+ fs[filesystem][:inodes_percent_used] = $5
55
+ fs[filesystem][:mount] = $6
56
+ end
57
+ end
41
58
 
42
59
  # Grab mount information from /bin/mount
43
60
  so = shell_out("mount")
@@ -90,7 +90,7 @@ Ohai.plugin(:NetworkAddresses) do
90
90
  end.first
91
91
  if r.nil?
92
92
  r = gw_if_ips.first
93
- Ohai::Log.warn("[#{family}] no ipaddress/mask on #{network[int_attr]} matching the gateway #{network[gw_attr]}, picking one anyway")
93
+ Ohai::Log.debug("[#{family}] no ipaddress/mask on #{network[int_attr]} matching the gateway #{network[gw_attr]}, picking #{r[:ipaddress]}")
94
94
  else
95
95
  Ohai::Log.debug("[#{family}] Using default interface #{network[int_attr]} and default gateway #{network[gw_attr]} to set the default ip to #{r[:ipaddress]}")
96
96
  end
@@ -38,7 +38,7 @@ Ohai.plugin(:Rackspace) do
38
38
  if so.exitstatus == 0
39
39
  so.stdout.strip.downcase == 'rackspace'
40
40
  end
41
- rescue Ohai::Exceptions::Exec
41
+ rescue Errno::ENOENT
42
42
  false
43
43
  end
44
44
 
@@ -89,8 +89,9 @@ Ohai.plugin(:Rackspace) do
89
89
  rackspace[:region] = line.split[2].delete('\"') if line =~ /^region/
90
90
  end
91
91
  end
92
- rescue Ohai::Exceptions::Exec
92
+ rescue Errno::ENOENT
93
93
  Ohai::Log.debug("Unable to find xenstore-ls, cannot capture region information for Rackspace cloud")
94
+ nil
94
95
  end
95
96
 
96
97
  # Get the rackspace private networks
@@ -102,17 +103,19 @@ Ohai.plugin(:Rackspace) do
102
103
  so.stdout.split("\n").map{|l| l.split('=').first.strip }.map do |item|
103
104
  _so = shell_out("xenstore-read vm-data/networking/#{item}")
104
105
  if _so.exitstatus == 0
105
- networks.push(Yajl::Parser.new.parse(_so.stdout))
106
+ networks.push(FFI_Yajl::Parser.new.parse(_so.stdout))
106
107
  else
107
- raise Ohai::Exceptions::Exec
108
+ Ohai::Log.debug('Unable to capture custom private networking information for Rackspace cloud')
109
+ return false
108
110
  end
109
111
  end
110
112
  # these networks are already known to ohai, and are not 'private networks'
111
113
  networks.delete_if { |hash| hash['label'] == 'private' }
112
114
  networks.delete_if { |hash| hash['label'] == 'public' }
113
115
  end
114
- rescue Ohai::Exceptions::Exec
116
+ rescue Errno::ENOENT
115
117
  Ohai::Log.debug('Unable to capture custom private networking information for Rackspace cloud')
118
+ nil
116
119
  end
117
120
 
118
121
  collect_data do