Class: ForemanMaintain::Report
- Inherits:
-
Executable
- Object
- Executable
- ForemanMaintain::Report
- Defined in:
- lib/foreman_maintain/report.rb
Constant Summary
Constants included from Concerns::Metadata
Concerns::Metadata::MAX_PREPARATION_STEPS_DEPTH
Constants included from Concerns::OsFacts
Concerns::OsFacts::FALLBACK_OS_RELEASE_FILE, Concerns::OsFacts::OS_RELEASE_FILE
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
Attributes inherited from Executable
Instance Method Summary collapse
-
#__run__(execution) ⇒ Object
internal method called by executor.
- #data_field(field_name) ⇒ Object
- #flatten(hash, prefix = '') ⇒ Object
- #flatten_separator ⇒ Object
- #merge_data(prefix) ⇒ Object
- #query(sql) ⇒ Object
- #run ⇒ Object
- #sql_as_count(selection, sql, cte: '') ⇒ Object
- #sql_count(sql, column: '*', cte: '') ⇒ Object
- #sql_setting(name) ⇒ Object
- #table_exists(table) ⇒ Object
Methods included from Concerns::Finders
#check, #detector, #feature, #find_all_scenarios, #find_procedures, #find_scenarios, #procedure
Methods included from Concerns::Metadata
#advanced_run?, #description, included, #label, #label_dashed, #metadata, #params, #preparation_steps, #run_once?, #runtime_message, #tags
Methods included from Concerns::SystemHelpers
#check_max_version, #check_min_version, #command_present?, #directory_empty?, #execute, #execute!, #execute?, #execute_runner, #execute_with_status, #file_exists?, #file_nonzero?, #find_dir_containing_file, #find_package, #find_symlinks, #foreman_plugin_name, #format_shell_args, #hammer_package, #hammer_plugin_name, #hostname, included, #package_manager, #package_version, #packages_action, #parse_csv, #parse_json, #proxy_plugin_name, #repository_manager, #ruby_prefix, #server?, #shellescape, #systemd_installed?, #version
Methods included from Concerns::OsFacts
#centos?, #cpu_cores, #deb_major_version, #debian?, #debian_or_ubuntu?, #el8?, #el?, #el_major_version, #el_short_name, #facts, #memory, #os_id, #os_id_like_list, #os_name, #os_release_file, #os_version, #os_version_codename, #os_version_id, #rhel?, #ubuntu?, #ubuntu_major_version
Methods included from Concerns::Logger
Methods inherited from Executable
#abort!, #after_initialize, #associated_feature, #ensure_instance, ensure_instance, #eql?, #executed?, #execution, #fail!, #hash, #initialize, #inspect, #matches_hash?, #necessary?, #next_steps, #say, #set_abort, #set_fail, #set_info_warn, #set_param_variable, #set_skip, #set_status, #set_warn, #setup_execution_state, #setup_params, #skip, #to_hash, #update_from_hash, #warn!
Constructor Details
This class inherits a constructor from ForemanMaintain::Executable
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
8 9 10 |
# File 'lib/foreman_maintain/report.rb', line 8 def data @data end |
Instance Method Details
#__run__(execution) ⇒ Object
internal method called by executor
67 68 69 70 71 72 73 |
# File 'lib/foreman_maintain/report.rb', line 67 def __run__(execution) super rescue Error::Fail => e set_fail(e.) rescue StandardError => e set_warn(e.) end |
#data_field(field_name) ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/foreman_maintain/report.rb', line 46 def data_field(field_name) self.data ||= {} value = yield self.data[field_name] = value rescue StandardError nil end |
#flatten(hash, prefix = '') ⇒ Object
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/foreman_maintain/report.rb', line 31 def flatten(hash, prefix = '') hash.each_with_object({}) do |(key, value), result| new_key = "#{prefix}#{prefix.empty? ? '' : flatten_separator}#{key}" if value.is_a? Hash result.merge!(flatten(value, new_key)) else result[new_key] = value end end end |
#flatten_separator ⇒ Object
75 76 77 |
# File 'lib/foreman_maintain/report.rb', line 75 def flatten_separator '|' end |
#merge_data(prefix) ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/foreman_maintain/report.rb', line 54 def merge_data(prefix) self.data ||= {} data_hash = yield self.data.merge!(flatten(data_hash, prefix)) rescue StandardError nil end |
#query(sql) ⇒ Object
10 11 12 |
# File 'lib/foreman_maintain/report.rb', line 10 def query(sql) feature(:foreman_database).query(sql) end |
#run ⇒ Object
62 63 64 |
# File 'lib/foreman_maintain/report.rb', line 62 def run raise NoMethodError, 'method not implemented on abstract report classes' end |
#sql_as_count(selection, sql, cte: '') ⇒ Object
18 19 20 21 22 23 |
# File 'lib/foreman_maintain/report.rb', line 18 def sql_as_count(selection, sql, cte: '') query = "#{cte} SELECT #{selection} AS COUNT FROM #{sql}" feature(:foreman_database).query(query).first['count'].to_i rescue StandardError nil end |
#sql_count(sql, column: '*', cte: '') ⇒ Object
14 15 16 |
# File 'lib/foreman_maintain/report.rb', line 14 def sql_count(sql, column: '*', cte: '') sql_as_count("COUNT(#{column})", sql, cte: cte) end |
#sql_setting(name) ⇒ Object
25 26 27 28 29 |
# File 'lib/foreman_maintain/report.rb', line 25 def sql_setting(name) sql = "SELECT value FROM settings WHERE name = '#{name}'" result = feature(:foreman_database).query(sql).first (result || {})['value'] end |
#table_exists(table) ⇒ Object
42 43 44 |
# File 'lib/foreman_maintain/report.rb', line 42 def table_exists(table) sql_count("information_schema.tables WHERE table_name = '#{table}'").positive? end |