ohai 18.1.0 → 18.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ohai/mixin/alibaba_metadata.rb +20 -33
- data/lib/ohai/mixin/azure_metadata.rb +9 -16
- data/lib/ohai/mixin/ec2_metadata.rb +10 -2
- data/lib/ohai/mixin/gce_metadata.rb +20 -26
- data/lib/ohai/mixin/json_helper.rb +36 -0
- data/lib/ohai/mixin/oci_metadata.rb +8 -17
- data/lib/ohai/plugins/linux/block_device.rb +1 -1
- data/lib/ohai/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 62cb983e4564cb9d15a8eb0b74bbdfdbf2c515fc2906a46718ad71f8e54fa663
|
4
|
+
data.tar.gz: 1b5157e0f291485d13ef5ee96d5b0aa90e274f19d259d1ac15897ea9a9a3bb33
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 815bce3ce6a1a8b83d0bdcd702581331632fc2239f7eea243261db411c951145bdbdc0c45802acae14ad514bcb390ce7f65fc8c2ef61d9e16b672cdb550e53fe
|
7
|
+
data.tar.gz: 98a13a200478051a2898b7d210f944bbdad9fecab0b39ecf7fa54ea0a3104027bcfcced0b22d9b17bf25383830a0386bd5a3cad5cf2ca202adf36a4fd19ffafb
|
@@ -18,6 +18,9 @@
|
|
18
18
|
|
19
19
|
require "net/http" unless defined?(Net::HTTP)
|
20
20
|
|
21
|
+
require_relative "../mixin/json_helper"
|
22
|
+
include Ohai::Mixin::JsonHelper
|
23
|
+
|
21
24
|
module Ohai
|
22
25
|
module Mixin
|
23
26
|
#
|
@@ -40,44 +43,28 @@ module Ohai
|
|
40
43
|
|
41
44
|
def fetch_metadata(id = "")
|
42
45
|
response = http_get(id)
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
46
|
+
if response.code == "200"
|
47
|
+
json_data = parse_json(response.body)
|
48
|
+
if json_data.nil?
|
49
|
+
logger.warn("Mixin AlibabaMetadata: Metadata response is NOT valid JSON for id='#{id}'")
|
50
|
+
if response.body.include?("\n")
|
51
|
+
temp = {}
|
52
|
+
response.body.split("\n").each do |sub_attr|
|
53
|
+
temp[sanitize_key(sub_attr)] = fetch_metadata("#{id}/#{sub_attr}")
|
54
|
+
end
|
55
|
+
temp
|
56
|
+
else
|
57
|
+
response.body
|
58
|
+
end
|
59
|
+
else
|
60
|
+
json_data
|
53
61
|
end
|
54
|
-
temp
|
55
62
|
else
|
56
|
-
response.
|
63
|
+
logger.warn("Mixin AlibabaMetadata: Received response code #{response.code} requesting metadata for id='#{id}'")
|
64
|
+
nil
|
57
65
|
end
|
58
66
|
end
|
59
67
|
|
60
|
-
# @param [String] data that might be JSON
|
61
|
-
#
|
62
|
-
# @return [Boolean] is the data JSON or not?
|
63
|
-
def json?(data)
|
64
|
-
data = String(data)
|
65
|
-
parser = FFI_Yajl::Parser.new
|
66
|
-
begin
|
67
|
-
parser.parse(data)
|
68
|
-
true
|
69
|
-
rescue FFI_Yajl::ParseError
|
70
|
-
false
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
# @param data [String]
|
75
|
-
#
|
76
|
-
# @return [Boolean] is there a trailing /?
|
77
|
-
def has_trailing_slash?(data)
|
78
|
-
!!( data =~ %r{/$} )
|
79
|
-
end
|
80
|
-
|
81
68
|
def sanitize_key(key)
|
82
69
|
key.gsub(%r{\-|/}, "_")
|
83
70
|
end
|
@@ -18,6 +18,9 @@
|
|
18
18
|
|
19
19
|
require "net/http" unless defined?(Net::HTTP)
|
20
20
|
|
21
|
+
require_relative "../mixin/json_helper"
|
22
|
+
include Ohai::Mixin::JsonHelper
|
23
|
+
|
21
24
|
module Ohai
|
22
25
|
module Mixin
|
23
26
|
#
|
@@ -81,26 +84,16 @@ module Ohai
|
|
81
84
|
conn.get(uri, { "Metadata" => "true" })
|
82
85
|
end
|
83
86
|
|
84
|
-
|
85
|
-
#
|
86
|
-
# @param [String] response_body json as string to parse
|
87
|
-
#
|
88
|
-
# @return [Hash]
|
89
|
-
def parse_json(response_body)
|
90
|
-
data = String(response_body)
|
91
|
-
parser = FFI_Yajl::Parser.new
|
92
|
-
parser.parse(data)
|
93
|
-
rescue FFI_Yajl::ParseError
|
94
|
-
logger.warn("Mixin AzureMetadata: Metadata response is NOT valid JSON")
|
95
|
-
nil
|
96
|
-
end
|
97
|
-
|
98
|
-
def fetch_metadata(api_version = nil)
|
87
|
+
def fetch_metadata(_api_version = nil)
|
99
88
|
metadata_url = "/metadata/instance?api-version=#{best_api_version}"
|
100
89
|
logger.trace("Mixin AzureMetadata: Fetching metadata from host #{AZURE_METADATA_ADDR} at #{metadata_url}")
|
101
90
|
response = http_get(metadata_url)
|
102
91
|
if response.code == "200"
|
103
|
-
parse_json(response.body)
|
92
|
+
json_data = parse_json(response.body)
|
93
|
+
if json_data.nil?
|
94
|
+
logger.warn("Mixin AzureMetadata: Metadata response is NOT valid JSON")
|
95
|
+
end
|
96
|
+
json_data
|
104
97
|
else
|
105
98
|
logger.warn("Mixin AzureMetadata: Received response code #{response.code} requesting metadata")
|
106
99
|
nil
|
@@ -20,6 +20,9 @@
|
|
20
20
|
|
21
21
|
require "net/http" unless defined?(Net::HTTP)
|
22
22
|
|
23
|
+
require_relative "../mixin/json_helper"
|
24
|
+
include Ohai::Mixin::JsonHelper
|
25
|
+
|
23
26
|
module Ohai
|
24
27
|
module Mixin
|
25
28
|
##
|
@@ -229,9 +232,14 @@ module Ohai
|
|
229
232
|
@fetch_dynamic_data ||= begin
|
230
233
|
response = http_client.get("/#{best_api_version}/dynamic/instance-identity/document/", { 'X-aws-ec2-metadata-token': v2_token })
|
231
234
|
|
232
|
-
if
|
233
|
-
|
235
|
+
if response.code == "200"
|
236
|
+
json_data = parse_json(response.body, {})
|
237
|
+
if json_data.nil?
|
238
|
+
logger.warn("Mixin Ec2Metadata: Metadata response is NOT valid JSON")
|
239
|
+
end
|
240
|
+
json_data
|
234
241
|
else
|
242
|
+
logger.warn("Mixin Ec2Metadata: Received response code #{response.code} requesting metadata")
|
235
243
|
{}
|
236
244
|
end
|
237
245
|
end
|
@@ -17,6 +17,9 @@
|
|
17
17
|
|
18
18
|
require "net/http" unless defined?(Net::HTTP)
|
19
19
|
|
20
|
+
require_relative "../mixin/json_helper"
|
21
|
+
include Ohai::Mixin::JsonHelper
|
22
|
+
|
20
23
|
module Ohai
|
21
24
|
module Mixin
|
22
25
|
module GCEMetadata
|
@@ -37,34 +40,25 @@ module Ohai
|
|
37
40
|
|
38
41
|
def fetch_metadata(id = "")
|
39
42
|
response = http_get("#{GCE_METADATA_URL}/#{id}")
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
43
|
+
if response.code == "200"
|
44
|
+
json_data = parse_json(response.body)
|
45
|
+
if json_data.nil?
|
46
|
+
logger.warn("Mixin GCEMetadata: Metadata response is NOT valid JSON for id='#{id}'")
|
47
|
+
if has_trailing_slash?(id) || (id == "")
|
48
|
+
temp = {}
|
49
|
+
response.body.split("\n").each do |sub_attr|
|
50
|
+
temp[sanitize_key(sub_attr)] = fetch_metadata("#{id}#{sub_attr}")
|
51
|
+
end
|
52
|
+
temp
|
53
|
+
else
|
54
|
+
response.body
|
55
|
+
end
|
56
|
+
else
|
57
|
+
json_data
|
50
58
|
end
|
51
|
-
temp
|
52
59
|
else
|
53
|
-
response.
|
54
|
-
|
55
|
-
end
|
56
|
-
|
57
|
-
# @param [String] data that might be JSON
|
58
|
-
#
|
59
|
-
# @return [Boolean] is the data JSON or not?
|
60
|
-
def json?(data)
|
61
|
-
data = String(data)
|
62
|
-
parser = FFI_Yajl::Parser.new
|
63
|
-
begin
|
64
|
-
parser.parse(data)
|
65
|
-
true
|
66
|
-
rescue FFI_Yajl::ParseError
|
67
|
-
false
|
60
|
+
logger.warn("Mixin GCEMetadata: Received response code #{response.code} requesting metadata for id='#{id}'")
|
61
|
+
nil
|
68
62
|
end
|
69
63
|
end
|
70
64
|
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
#
|
3
|
+
# Author:: Renato Covarrubias (<rnt@rnt.cl>)
|
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
|
+
module Ohai
|
19
|
+
module Mixin
|
20
|
+
module JsonHelper
|
21
|
+
# parse JSON data from a String to a Hash
|
22
|
+
#
|
23
|
+
# @param [String] response_body json as string to parse
|
24
|
+
# @param [Object] return_on_parse_error value to return if parsing fails
|
25
|
+
#
|
26
|
+
# @return [Hash]
|
27
|
+
def parse_json(response_body, return_on_parse_error = nil)
|
28
|
+
data = String(response_body)
|
29
|
+
parser = FFI_Yajl::Parser.new
|
30
|
+
parser.parse(data)
|
31
|
+
rescue FFI_Yajl::ParseError
|
32
|
+
return_on_parse_error
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -18,6 +18,9 @@
|
|
18
18
|
|
19
19
|
require "net/http" unless defined?(Net::HTTP)
|
20
20
|
|
21
|
+
require_relative "../mixin/json_helper"
|
22
|
+
include Ohai::Mixin::JsonHelper
|
23
|
+
|
21
24
|
module Ohai
|
22
25
|
module Mixin
|
23
26
|
module OCIMetadata
|
@@ -38,27 +41,15 @@ module Ohai
|
|
38
41
|
)
|
39
42
|
end
|
40
43
|
|
41
|
-
# parse JSON data from a String to a Hash
|
42
|
-
#
|
43
|
-
# @param [String] response_body json as string to parse
|
44
|
-
#
|
45
|
-
# @return [Hash]
|
46
|
-
def parse_json(response_body)
|
47
|
-
data = String(response_body)
|
48
|
-
parser = FFI_Yajl::Parser.new
|
49
|
-
parser.parse(data)
|
50
|
-
rescue FFI_Yajl::ParseError
|
51
|
-
logger.warn("Mixin OciMetadata: Metadata response is NOT valid JSON")
|
52
|
-
nil
|
53
|
-
end
|
54
|
-
|
55
44
|
# Fetch metadata from api
|
56
45
|
def fetch_metadata(metadata = "instance")
|
57
46
|
response = http_get("#{OCI_METADATA_URL}/#{metadata}")
|
58
|
-
return nil unless response.code == "200"
|
59
|
-
|
60
47
|
if response.code == "200"
|
61
|
-
parse_json(response.body)
|
48
|
+
json_data = parse_json(response.body)
|
49
|
+
if json_data.nil?
|
50
|
+
logger.warn("Mixin OciMetadata: Metadata response is NOT valid JSON")
|
51
|
+
end
|
52
|
+
json_data
|
62
53
|
else
|
63
54
|
logger.warn("Mixin OciMetadata: Received response code #{response.code} requesting metadata")
|
64
55
|
nil
|
@@ -31,7 +31,7 @@ Ohai.plugin(:BlockDevice) do
|
|
31
31
|
file_open("/sys/block/#{dir}/#{check}") { |f| block[dir][check] = f.read_nonblock(1024).strip }
|
32
32
|
end
|
33
33
|
end
|
34
|
-
%w{model rev state timeout vendor queue_depth}.each do |check|
|
34
|
+
%w{model rev state timeout vendor queue_depth firmware_rev}.each do |check|
|
35
35
|
if file_exist?("/sys/block/#{dir}/device/#{check}")
|
36
36
|
file_open("/sys/block/#{dir}/device/#{check}") { |f| block[dir][check] = f.read_nonblock(1024).strip }
|
37
37
|
end
|
data/lib/ohai/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ohai
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 18.1.
|
4
|
+
version: 18.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Jacob
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-03-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: chef-config
|
@@ -240,6 +240,7 @@ files:
|
|
240
240
|
- lib/ohai/mixin/ec2_metadata.rb
|
241
241
|
- lib/ohai/mixin/gce_metadata.rb
|
242
242
|
- lib/ohai/mixin/http_helper.rb
|
243
|
+
- lib/ohai/mixin/json_helper.rb
|
243
244
|
- lib/ohai/mixin/network_helper.rb
|
244
245
|
- lib/ohai/mixin/oci_metadata.rb
|
245
246
|
- lib/ohai/mixin/os.rb
|