# class Chef::Handler::JsonFile

### Attributes

config[R]

### Public Class Methods

new(config={}) click to toggle source

    # File lib/chef/handler/json_file.rb, line 28
    def initialize(config={})
      @config = config
      @config[:path] ||= "/var/chef/reports"
      @config
    end

### Public Instance Methods

build_report_dir() click to toggle source

    # File lib/chef/handler/json_file.rb, line 54
    def build_report_dir
      unless File.exists?(config[:path])
        FileUtils.mkdir_p(config[:path])
        File.chmod(00700, config[:path])
      end
    end

report() click to toggle source

    # File lib/chef/handler/json_file.rb, line 34
    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