Last active
July 18, 2017 15:28
-
-
Save jeremymv2/e28056a225d680e75744631dc93d8688 to your computer and use it in GitHub Desktop.
ruby `knife status --hide-by-min xxx` replacement
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' | |
Chef::Config.from_file('/path/to/knife.rb') | |
hide_by_mins = 15700 | |
query = "*:*" | |
opts = { filter_result: | |
{ name: ["name"], ipaddress: ["ipaddress"], ohai_time: ["ohai_time"], | |
run_list: ["run_list"], platform: ["platform"], | |
platform_version: ["platform_version"], chef_environment: ["chef_environment"] } } | |
all_nodes = [] | |
q = Chef::Search::Query.new | |
puts "Sending query: #{query}" | |
q.search(:node, query, opts) do |node| | |
all_nodes << node | |
end | |
# optional sorting | |
#all_nodes.sort! do |n1, n2| | |
# (n2["ohai_time"] || 0) <=> (n1["ohai_time"] || 0) | |
#end | |
time = Time.now.to_i | |
puts "Filtering out converges since #{hide_by_mins}" | |
all_nodes.select! { |i| !i['ohai_time'].between?((time - hide_by_mins * 60), time) } | |
require 'pp' | |
pp all_nodes |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment