Class: Chef::Handler::JsonFile
- Inherits:
-
Chef::Handler
- Object
- Chef::Handler
- Chef::Handler::JsonFile
- Defined in:
- lib/chef/handler/json_file.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Attributes inherited from Chef::Handler
Instance Method Summary collapse
- #build_report_dir ⇒ Object
-
#initialize(config = {}) ⇒ JsonFile
constructor
A new instance of JsonFile.
- #report ⇒ Object
Methods inherited from Chef::Handler
#action_collection, #all_resources, #data, exception_handlers, #failed_resources, handler_for, report_handlers, resolve_handler_instance, run_exception_handlers, run_report_handlers, #run_report_safely, #run_report_unsafe, run_start_handlers, #skipped_resources, start_handlers, #unprocessed_resources, #up_to_date_resources, #updated_resources
Constructor Details
#initialize(config = {}) ⇒ JsonFile
Returns a new instance of JsonFile.
28 29 30 31 |
# File 'lib/chef/handler/json_file.rb', line 28 def initialize(config = {}) @config = config @config[:path] ||= "/var/chef/reports" end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
26 27 28 |
# File 'lib/chef/handler/json_file.rb', line 26 def config @config end |
Instance Method Details
#build_report_dir ⇒ Object
53 54 55 56 57 58 |
# File 'lib/chef/handler/json_file.rb', line 53 def build_report_dir unless File.exist?(config[:path]) FileUtils.mkdir_p(config[:path]) File.chmod(00700, config[:path]) end end |
#report ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/chef/handler/json_file.rb', line 33 def report if exception Chef::Log.error("Creating JSON exception report") else Chef::Log.info("Creating JSON run report") end build_report_dir savetime = Time.now.strftime("%Y%m%d%H%M%S") File.open(File.join(config[:path], "chef-run-report-#{savetime}.json"), "w") do |file| # ensure start time and end time are output in the json properly in the event activesupport happens to be on the system run_data = data run_data[:start_time] = run_data[:start_time].to_s run_data[:end_time] = run_data[:end_time].to_s file.puts Chef::JSONCompat.to_json_pretty(run_data) end end |