Module: ChefHandlerLrc::LrcHooks

Defined in:
lib/lbn_report_chef/lrc_hooks.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#lrc_report_handlerObject (readonly)

Returns the value of attribute lrc_report_handler.



8
9
10
# File 'lib/lbn_report_chef/lrc_hooks.rb', line 8

def lrc_report_handler
  @lrc_report_handler
end

#lrc_reporterObject (readonly)

Returns the value of attribute lrc_reporter.



8
9
10
# File 'lib/lbn_report_chef/lrc_hooks.rb', line 8

def lrc_reporter
  @lrc_reporter
end

#lrc_uploaderObject (readonly)

Returns the value of attribute lrc_uploader.



8
9
10
# File 'lib/lbn_report_chef/lrc_hooks.rb', line 8

def lrc_uploader
  @lrc_uploader
end

Instance Method Details

#lrc_reports_upload(upload, mode = 1) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/lbn_report_chef/lrc_hooks.rb', line 24

def lrc_reports_upload(upload, mode = 1)
  return unless upload
  case mode
  when 1
    @lrc_reporter                   = LrcResourceReporter.new(nil)
    @lrc_reporter.uploader          = @lrc_uploader
    @lrc_reporter.log_level         = @lrc_reports_level
    if Chef::Config[:event_handlers].is_a?(Array)
      Chef::Config[:event_handlers].push @lrc_reporter
    else
      Chef::Config[:event_handlers] = [@lrc_reporter]
    end
  when 2
    @lrc_report_handler          = LrcReporting.new
    @lrc_report_handler.uploader = @lrc_uploader
    report_handlers << @lrc_report_handler
    exception_handlers << @lrc_report_handler
  else
    raise ArgumentError, 'unknown mode: ' + mode.to_s
  end
end

#lrc_server_options(options = {}) ⇒ Object

=> ”, …



16
17
18
19
20
21
22
# File 'lib/lbn_report_chef/lrc_hooks.rb', line 16

def lrc_server_options(options = {})
  options[:client_key] = client_key || '/etc/chef/client.pem' unless options[:client_key]
  raise 'No LRC URL! Please provide a URL' unless options[:url]
  @lrc_uploader                 = LrcUploader.new(options)
  @lrc_report_handler.uploader  = @lrc_uploader if @lrc_report_handler
  @lrc_reporter.uploader        = @lrc_uploader if @lrc_reporter
end

#lrc_server_url(url) ⇒ Object

Provide a chef-client cookbook friendly option



11
12
13
# File 'lib/lbn_report_chef/lrc_hooks.rb', line 11

def lrc_server_url(url)
  lrc_server_options(url: url)
end

#reports_log_level(level) ⇒ Object

level can be string error notice debug

Raises:

  • (ArgumentError)


47
48
49
50
51
52
# File 'lib/lbn_report_chef/lrc_hooks.rb', line 47

def reports_log_level(level)
  raise ArgumentError, 'unknown level: ' + level.to_s unless %w(error notice debug).include?(level)
  @lrc_reports_level = level
  return unless @lrc_reporter
  @lrc_reporter.log_level = level
end