bin/check-chef-nodes.rb in sensu-plugins-chef-2.0.1 vs bin/check-chef-nodes.rb in sensu-plugins-chef-3.0.0

- old
+ new

@@ -30,11 +30,11 @@ # Released under the same terms as Sensu (the MIT license); see LICENSE # for details. # require 'sensu-plugin/check/cli' -require 'chef/rest' +require 'ridley' # # Chef Nodes Status Checker # class ChefNodesStatusChecker < Sensu::Plugin::Check::CLI @@ -66,23 +66,28 @@ description: 'Node to excludes', short: '-e EXCLUDE-NODES', long: '--exclude-nodes EXCLUDE-NODES', default: '^$' + option :ignore_ssl_verification, + description: 'Ignore SSL certificate verification', + short: '-i', + long: '--ignore-ssl' + def connection @connection ||= chef_api_connection end def nodes_last_seen - nodes = connection.get_rest('/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 } + nodes = connection.node.all + nodes.delete_if { |node| node.name =~ /#{config[:exclude_nodes]}/ } + nodes.map do |node| + node.reload + if node['automatic']['ohai_time'] + { node.name => (Time.now - Time.at(node['automatic']['ohai_time'])) > config[:critical_timespan].to_i } else - { node_name => true } + { node.name => true } end end end def run @@ -97,10 +102,14 @@ def chef_api_connection chef_server_url = config[:chef_server_url] client_name = config[:client_name] signing_key_filename = config[:key] - Chef::REST.new(chef_server_url, client_name, signing_key_filename) + ignore_ssl = config[:ignore_ssl_verification] + verify_ssl = ignore_ssl.nil? + + Celluloid.boot + Ridley.new(server_url: chef_server_url, client_name: client_name, client_key: signing_key_filename, ssl: { verify: verify_ssl }) end def any_node_stuck? @nodes_last_seen ||= nodes_last_seen @nodes_last_seen.map(&:values).flatten.all? { |x| x == false }