-
-
Save michaelbiven/6526896 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Nick-Stielaus-MacBook-Pro:chef-repo nstielau$ knife node log nstielau_vagrantup.com | |
Time Recipe Action Resource Type Resource | |
Tue May 10 10:25:20 -0700 2011 nginx::source create template proxy.conf | |
Tue May 10 10:25:20 -0700 2011 nginx::source enable service nginx | |
Tue May 10 09:50:42 -0700 2011 nginx::source create template /etc/init.d/nginx |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
log_level :info | |
log_location STDOUT | |
node_name "nstielau_vagrantup.com" | |
ssl_verify_mode :verify_none | |
..... | |
# Handlers | |
require "/var/chef/handlers/update_handler" | |
report_handlers << UpdateHandler.new() | |
.... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'chef/knife' | |
require 'highline' | |
module Limelight | |
class NodeLog < Chef::Knife | |
deps do | |
require 'chef/search/query' | |
require 'chef/knife/search' | |
end | |
banner "knife node log NODE" | |
def h | |
@highline ||= HighLine.new | |
end | |
def run | |
unless @node_name = name_args[0] | |
ui.error "You need to specify a node" | |
exit 1 | |
end | |
searcher = Chef::Search::Query.new | |
result = searcher.search(:node, "name:#{@node_name}") | |
knife_search = Chef::Knife::Search.new | |
node = result.first.first | |
if node.nil? | |
puts "Could not find a node named #{@node_name}" | |
exit 1 | |
end | |
$stdout.sync = true | |
if node[:log] | |
log_entries = [ h.color('Time', :bold), | |
h.color('Recipe', :bold), | |
h.color('Action', :bold), | |
h.color('Resource Type', :bold), | |
h.color('Resource', :bold) ] | |
node[:log].each do |log_entry| | |
log_entries << log_entry[:time].to_s | |
log_entries << "#{log_entry[:cookbook_name]}::#{log_entry[:recipe_name]}" | |
log_entries << log_entry[:action].to_s | |
log_entries << log_entry[:resource_type].to_s | |
log_entries << log_entry[:resource].to_s | |
end | |
puts h.list(log_entries, :columns_across, 5) | |
puts | |
end | |
end | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'chef/log' | |
class UpdateHandler < Chef::Handler | |
def initialize(options={}) | |
@max_log_entries = (options[:max_log_entries] || 10).to_i | |
end | |
def report | |
run_status.updated_resources.each do |resource| | |
m = "recipe[#{resource.cookbook_name}::#{resource.recipe_name}] ran '#{resource.action}' on #{resource.resource_name} '#{resource.name}'" | |
Chef::Log.debug(m) | |
# Save entries to node | |
node[:log] ||= [] | |
node[:log].insert(0, { | |
:time => Time.now, | |
:cookbook_name => resource.cookbook_name, | |
:recipe_name => resource.recipe_name, | |
:action => resource.action, | |
:resource => resource.name, | |
:resource_type => resource.resource_name | |
}) | |
node[:log] = node[:log].first(@max_log_entries) if node[:log].length > @max_log_entries | |
end | |
node.save | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment