bin/check-chef-nodes.rb in sensu-plugins-chef-1.0.0 vs bin/check-chef-nodes.rb in sensu-plugins-chef-2.0.0
- old
+ new
@@ -47,14 +47,17 @@
option :chef_server_url,
description: 'URL of Chef server',
short: '-U CHEF-SERVER-URL',
long: '--url CHEF-SERVER-URL'
+ # defaults to the equivalent of `hostname --fqdn`
option :client_name,
description: 'Client name',
short: '-C CLIENT-NAME',
- long: '--client CLIENT-NAME'
+ long: '--client CLIENT-NAME',
+ required: true,
+ default: Socket.gethostbyname(Socket.gethostname).first
option :key,
description: 'Client\'s key',
short: '-K CLIENT-KEY',
long: '--keys CLIENT-KEY'
@@ -69,11 +72,11 @@
@connection ||= chef_api_connection
end
def nodes_last_seen
nodes = connection.get_rest('/nodes')
- nodes.delete_if { |node_name| node_name =~ /#{exclude_nodes}/ }
+ nodes.delete_if { |node_name| node_name =~ /#{config[:exclude_nodes]}/ }
nodes.keys.map do |node_name|
node = connection.get_rest("/nodes/#{node_name}")
if node['ohai_time']
{ node_name => (Time.now - Time.at(node['ohai_time'])) > config[:critical_timespan].to_i }
else
@@ -98,13 +101,14 @@
signing_key_filename = config[:key]
Chef::REST.new(chef_server_url, client_name, signing_key_filename)
end
def any_node_stuck?
- nodes_last_seen.map(&:values).flatten.all? { |x| x == false }
+ @nodes_last_seen ||= nodes_last_seen
+ @nodes_last_seen.map(&:values).flatten.all? { |x| x == false }
end
def failed_nodes_names
- all_failed_tuples = nodes_last_seen.select { |node_set| node_set.values.first == true }
+ all_failed_tuples = @nodes_last_seen.select { |node_set| node_set.values.first == true }
all_failed_tuples.map(&:keys).flatten.join(', ')
end
end