Created
May 23, 2012 20:30
-
-
Save kkenny/2777606 to your computer and use it in GitHub Desktop.
Knife node status plugin
This file contains 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 NodeStatus < Chef::Knife | |
deps do | |
require 'chef/search/query' | |
require 'chef/knife/search' | |
end | |
banner "knife node status 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('Status', :bold), | |
h.color('Start Time', :bold), | |
h.color('End Time', :bold), | |
h.color('Run Time', :bold) ] | |
node[:log].each do |log_entry| | |
log_entries << log_entry[:time].to_s | |
log_entries << log_entry[:status].to_s | |
log_entries << log_entry[:start_time].to_s | |
log_entries << log_entry[:end_time].to_s | |
log_entries << log_entry[:run_time].to_s | |
end | |
puts h.list(log_entries, :columns_across, 5) | |
puts | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Place in ~/.chef/plugins/knife/ for knife to autoload the plugin.
Run:
knife node status NODE