lrc_handler 0.1.2 → 0.1.3
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 +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +14 -1
- data/lib/lbn_report_chef/lrc_hooks.rb +22 -24
- data/lib/lbn_report_chef/lrc_reporting.rb +3 -4
- data/lib/lbn_report_chef/lrc_resource_reporter.rb +17 -25
- data/lib/lbn_report_chef/lrc_uploader.rb +5 -5
- data/lib/lbn_report_chef/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b26c6c4d52ceefdd8d519142f5230e5ee4b3436e
|
4
|
+
data.tar.gz: 8aff525c170fe6dc141edfcae3ecb297c53e2477
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6ea58873681971f39ff5e49153daa2dd699c4ab46aa432c0a52c947f123386deca48157d88495c69d8b67513a8f3078acfbbfa1d4dc4a9518622e9f777a639d2
|
7
|
+
data.tar.gz: 5a35e052299efaf82172c2b453244d8059d0b951e5315890722b1093e06b4e1ccc17a01018a4094915e8b0a7f978c9cf29adbb83cdc823a17bf3d67be42dd042
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -24,4 +24,17 @@ lrc_server_options :url => 'https://lrc.lbn.fr'
|
|
24
24
|
lrc_reports_upload true
|
25
25
|
# add following line to manage reports verbosity. Allowed values are debug, notice and error
|
26
26
|
lrc_reports_level "notice"
|
27
|
-
```
|
27
|
+
```
|
28
|
+
|
29
|
+
## packaging
|
30
|
+
|
31
|
+
Edit the `lib\lbn_report_chef\version.rb` with a new version
|
32
|
+
|
33
|
+
run the following command:
|
34
|
+
|
35
|
+
```sh
|
36
|
+
gem build lrc_handler.gemspec
|
37
|
+
gem push lrc_handler-x.x.x.gem
|
38
|
+
```
|
39
|
+
|
40
|
+
gem push require that you can login to rubygems.org
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# import files
|
1
2
|
require "#{File.dirname(__FILE__)}/lrc_reporting"
|
2
3
|
require "#{File.dirname(__FILE__)}/lrc_resource_reporter"
|
3
4
|
require "#{File.dirname(__FILE__)}/lrc_uploader"
|
@@ -15,32 +16,30 @@ module ChefHandlerLrc
|
|
15
16
|
def lrc_server_options(options = {})
|
16
17
|
options[:client_key] = client_key || '/etc/chef/client.pem' unless options[:client_key]
|
17
18
|
raise 'No LRC URL! Please provide a URL' unless options[:url]
|
18
|
-
@lrc_uploader
|
19
|
-
|
20
|
-
@
|
21
|
-
@lrc_reporter.uploader = @lrc_uploader if @lrc_reporter
|
19
|
+
@lrc_uploader = LrcUploader.new(options)
|
20
|
+
@lrc_report_handler.uploader = @lrc_uploader if @lrc_report_handler
|
21
|
+
@lrc_reporter.uploader = @lrc_uploader if @lrc_reporter
|
22
22
|
end
|
23
23
|
|
24
24
|
def lrc_reports_upload(upload, mode = 1)
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
else
|
34
|
-
Chef::Config[:event_handlers] = [@lrc_reporter]
|
35
|
-
end
|
36
|
-
when 2
|
37
|
-
@lrc_report_handler = LrcReporting.new
|
38
|
-
@lrc_report_handler.uploader = @lrc_uploader
|
39
|
-
report_handlers << @lrc_report_handler
|
40
|
-
exception_handlers << @lrc_report_handler
|
25
|
+
return unless upload
|
26
|
+
case mode
|
27
|
+
when 1
|
28
|
+
@lrc_reporter = LrcResourceReporter.new(nil)
|
29
|
+
@lrc_reporter.uploader = @lrc_uploader
|
30
|
+
@lrc_reporter.log_level = @lrc_reports_level
|
31
|
+
if Chef::Config[:event_handlers].is_a?(Array)
|
32
|
+
Chef::Config[:event_handlers].push @lrc_reporter
|
41
33
|
else
|
42
|
-
|
34
|
+
Chef::Config[:event_handlers] = [@lrc_reporter]
|
43
35
|
end
|
36
|
+
when 2
|
37
|
+
@lrc_report_handler = LrcReporting.new
|
38
|
+
@lrc_report_handler.uploader = @lrc_uploader
|
39
|
+
report_handlers << @lrc_report_handler
|
40
|
+
exception_handlers << @lrc_report_handler
|
41
|
+
else
|
42
|
+
raise ArgumentError, 'unknown mode: ' + mode.to_s
|
44
43
|
end
|
45
44
|
end
|
46
45
|
|
@@ -48,9 +47,8 @@ module ChefHandlerLrc
|
|
48
47
|
def reports_log_level(level)
|
49
48
|
raise ArgumentError, 'unknown level: ' + level.to_s unless %w(error notice debug).include?(level)
|
50
49
|
@lrc_reports_level = level
|
51
|
-
|
52
|
-
|
53
|
-
end
|
50
|
+
return unless @lrc_reporter
|
51
|
+
@lrc_reporter.log_level = level
|
54
52
|
end
|
55
53
|
end
|
56
54
|
end
|
@@ -24,7 +24,7 @@ module ChefHandlerLrc
|
|
24
24
|
times[resource_name] += resource.elapsed_time
|
25
25
|
end
|
26
26
|
end
|
27
|
-
metrics['time'] = times.merge!(
|
27
|
+
metrics['time'] = times.merge!('total' => run_status.elapsed_time)
|
28
28
|
report['metrics'] = metrics
|
29
29
|
|
30
30
|
logs = []
|
@@ -41,7 +41,6 @@ module ChefHandlerLrc
|
|
41
41
|
end
|
42
42
|
l['log']['messages']['message'] = message
|
43
43
|
l['log']['sources']['source'] = [resource.resource_name.to_s, resource.name].join(' ')
|
44
|
-
# Chef::Log.info("Diff is #{l['log']['messages']['message']}")
|
45
44
|
logs << l
|
46
45
|
end
|
47
46
|
|
@@ -52,7 +51,7 @@ module ChefHandlerLrc
|
|
52
51
|
'sources' => { 'source' => 'chef' },
|
53
52
|
'messages' => { 'message' => run_status.exception },
|
54
53
|
'level' => 'err',
|
55
|
-
}
|
54
|
+
},
|
56
55
|
}
|
57
56
|
end
|
58
57
|
|
@@ -68,7 +67,7 @@ module ChefHandlerLrc
|
|
68
67
|
if uploader
|
69
68
|
uploader.foreman_request('/report', report, node.name)
|
70
69
|
else
|
71
|
-
Chef::Log.error 'No uploader registered for
|
70
|
+
Chef::Log.error 'No uploader registered for lrc reporting, skipping report upload'
|
72
71
|
end
|
73
72
|
end
|
74
73
|
end
|
@@ -27,9 +27,8 @@ module ChefHandlerLrc
|
|
27
27
|
@status = 'failure'
|
28
28
|
# If we failed before we received the run_started callback, there's not much we can do
|
29
29
|
# in terms of reporting
|
30
|
-
|
31
|
-
|
32
|
-
end
|
30
|
+
return unless @run_status
|
31
|
+
post_reporting_data
|
33
32
|
end
|
34
33
|
|
35
34
|
def resource_current_state_loaded(new_resource, action, current_resource)
|
@@ -60,14 +59,13 @@ module ChefHandlerLrc
|
|
60
59
|
end
|
61
60
|
|
62
61
|
def resource_completed(new_resource)
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
end
|
62
|
+
return unless @pending_update && !nested_resource?(new_resource)
|
63
|
+
@pending_update.finish
|
64
|
+
@updated_resources << @pending_update
|
65
|
+
@pending_update = nil
|
68
66
|
end
|
69
67
|
|
70
|
-
def resource_bypassed(*
|
68
|
+
def resource_bypassed(*)
|
71
69
|
@why_run = true
|
72
70
|
end
|
73
71
|
|
@@ -79,7 +77,7 @@ module ChefHandlerLrc
|
|
79
77
|
begin
|
80
78
|
Chef::Log.debug('Sending data to report API ...')
|
81
79
|
if uploader
|
82
|
-
uploader.lrc_request('/report',
|
80
|
+
uploader.lrc_request('/report', 'report' => run_data)
|
83
81
|
else
|
84
82
|
Chef::Log.error 'No uploader registered for LRC reporting, skipping report upload'
|
85
83
|
end
|
@@ -130,10 +128,10 @@ module ChefHandlerLrc
|
|
130
128
|
end
|
131
129
|
|
132
130
|
def resources_per_time
|
133
|
-
@run_status.all_resources.
|
134
|
-
name
|
131
|
+
@run_status.all_resources.each_with_object({}) do |resource, memo|
|
132
|
+
name = resource.resource_name.to_s
|
133
|
+
time = resource.elapsed_time || 0
|
135
134
|
memo[name] = memo[name] ? memo[name] + time : time
|
136
|
-
memo
|
137
135
|
end
|
138
136
|
end
|
139
137
|
|
@@ -168,16 +166,16 @@ module ChefHandlerLrc
|
|
168
166
|
|
169
167
|
def resource_level(resource)
|
170
168
|
if !resource.exception.nil?
|
171
|
-
|
169
|
+
'err'
|
172
170
|
elsif resource.new_resource.updated
|
173
|
-
|
171
|
+
'notice'
|
174
172
|
else
|
175
|
-
|
173
|
+
'debug'
|
176
174
|
end
|
177
175
|
end
|
178
176
|
|
179
177
|
def chef_log
|
180
|
-
message = 'run'
|
178
|
+
message = 'chef-client run'
|
181
179
|
if @status == 'success' && exception.nil?
|
182
180
|
level = 'notice'
|
183
181
|
else
|
@@ -186,7 +184,7 @@ module ChefHandlerLrc
|
|
186
184
|
end
|
187
185
|
|
188
186
|
{ 'log' => {
|
189
|
-
'sources' => { 'source' =>
|
187
|
+
'sources' => { 'source' => "chef-client #{Chef::VERSION}" },
|
190
188
|
'messages' => { 'message' => message },
|
191
189
|
'level' => level,
|
192
190
|
} }
|
@@ -198,13 +196,7 @@ module ChefHandlerLrc
|
|
198
196
|
# 'error' means only errors
|
199
197
|
|
200
198
|
def filter_logs(logs)
|
201
|
-
|
202
|
-
logs.select { |log| log['log']['level'] == 'err' }
|
203
|
-
elsif log_level == 'notice'
|
204
|
-
logs.select { |log| %w(err,notice).include? log['log']['level'] }
|
205
|
-
else
|
206
|
-
logs
|
207
|
-
end
|
199
|
+
logs.select { |log| ['err','notice'].include? log['log']['level'] }
|
208
200
|
end
|
209
201
|
end
|
210
202
|
end
|
@@ -12,15 +12,15 @@ module ChefHandlerLrc
|
|
12
12
|
def lrc_request(path, body, method = 'post')
|
13
13
|
uri = URI.parse(options[:url])
|
14
14
|
http = Net::HTTP.new(uri.host, uri.port)
|
15
|
-
|
16
|
-
|
15
|
+
http.use_ssl = true
|
16
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
17
17
|
req = Net::HTTP.const_get(method.capitalize).new("#{uri}#{path}")
|
18
|
-
req.add_field('Accept','application/json')
|
19
|
-
req.add_field('Content-Type','application/json')
|
18
|
+
req.add_field('Accept', 'application/json')
|
19
|
+
req.add_field('Content-Type', 'application/json')
|
20
20
|
req.body = body.to_json
|
21
21
|
response = http.request(req)
|
22
22
|
Chef::Log.info("The report API has return: #{response.inspect} from #{uri}#{path}")
|
23
|
-
|
23
|
+
Chef::Log.debug("Report Content: #{body.to_json}")
|
24
24
|
end
|
25
25
|
end
|
26
26
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lrc_handler
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- team-chef
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-09-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|