Class: Chef::DataCollector

Inherits:
Object
  • Object
show all
Defined in:
lib/chef/data_collector.rb,
lib/chef/data_collector/messages.rb,
lib/chef/data_collector/resource_report.rb,
lib/chef/data_collector/messages/helpers.rb

Overview

== Chef::DataCollector Provides methods for determinine whether a reporter should be registered.

Defined Under Namespace

Modules: Messages Classes: Reporter, ResourceReport

Class Method Summary collapse

Class Method Details

.data_collector_url_configured?Boolean


68
69
70
# File 'lib/chef/data_collector.rb', line 68

def self.data_collector_url_configured?
  !!Chef::Config[:data_collector][:server_url]
end

.register_reporter?Boolean

Whether or not to enable data collection:

  • always disabled for why run mode
  • disabled when the user sets Chef::Config[:data_collector][:mode] to a value that excludes the mode (client or solo) that we are running as
  • disabled in solo mode if the user did not configure the auth token
  • disabled if Chef::Config[:data_collector][:server_url] is set to a falsey value

43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/chef/data_collector.rb', line 43

def self.register_reporter?
  if why_run?
    Chef::Log.debug("data collector is disabled for why run mode")
    return false
  end
  unless reporter_enabled_for_current_mode?
    Chef::Log.debug("data collector is configured to only run in " \
                    "#{Chef::Config[:data_collector][:mode].inspect} modes, disabling it")
    return false
  end
  unless data_collector_url_configured?
    Chef::Log.debug("data collector URL is not configured, disabling data collector")
    return false
  end
  if solo? && !token_auth_configured?
    Chef::Log.debug("Data collector token must be configured to use Chef Automate data collector with Chef Solo")
  end
  if !solo? && token_auth_configured?
    Chef::Log.warn("Data collector token authentication is not recommended for client-server mode" \
                   "Please upgrade Chef Server to 12.11.0 and remove the token from your config file " \
                   "to use key based authentication instead")
  end
  true
end

.reporter_enabled_for_current_mode?Boolean


84
85
86
87
88
89
90
91
92
# File 'lib/chef/data_collector.rb', line 84

def self.reporter_enabled_for_current_mode?
  if Chef::Config[:solo] || Chef::Config[:local_mode]
    acceptable_modes = [:solo, :both]
  else
    acceptable_modes = [:client, :both]
  end

  acceptable_modes.include?(Chef::Config[:data_collector][:mode])
end

.solo?Boolean


80
81
82
# File 'lib/chef/data_collector.rb', line 80

def self.solo?
  !!Chef::Config[:solo] || !!Chef::Config[:local_mode]
end

.token_auth_configured?Boolean


76
77
78
# File 'lib/chef/data_collector.rb', line 76

def self.token_auth_configured?
  !!Chef::Config[:data_collector][:token]
end

.why_run?Boolean


72
73
74
# File 'lib/chef/data_collector.rb', line 72

def self.why_run?
  !!Chef::Config[:why_run]
end