Skip to content

Instantly share code, notes, and snippets.

@adamhjk
Created April 18, 2010 22:47
Show Gist options
  • Save adamhjk/370601 to your computer and use it in GitHub Desktop.
Save adamhjk/370601 to your computer and use it in GitHub Desktop.
#
# Author:: Adam Jacob (<[email protected]>)
# Copyright:: Copyright (c) 2010 Opscode, Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
require 'chef/handler'
require 'chef/resource/directory'
class Chef
class Handler
class JsonFile < ::Chef::Handler
def initialize(config={})
super(config)
end
def report(node, runner, start_time, end_time, elapsed_time)
Chef::Log.info("Creating JSON run report")
data = build_report_data(node, runner, start_time, end_time, elapsed_time)
build_report_dir(node)
build_report_file(node)
end
def build_report_file(node)
report = Chef::Resource::File.new(File.join(config[:path], "run_report.json"), nil, node)
report.content(JSON.pretty_generate(data))
report.mode("0644")
report.provider(Chef::Provider::File)
report.backup(config[:number_to_keep])
report.run_action(:create)
end
def exception(node, runner, exception=nil)
Chef::Log.info("Creating JSON run report")
data = build_report_data(node, runner, start_time, end_time, elapsed_time)
data[:exception] = {
:message => e.
}
build_report_dir(node)
build_report_file(node)
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment